clank-vault/shuttletask/plan.go

60 lines
1.3 KiB
Go
Raw Normal View History

2023-04-09 23:24:34 +02:00
package main
import (
"context"
"os"
"dagger.io/dagger"
"github.com/joho/godotenv"
)
func Plan(ctx context.Context) error {
terraform, err := bootstrap(ctx)
if err != nil {
return err
}
_, err = terraform.WithExec([]string{
"plan",
}).
ExitCode(ctx)
if err != nil {
return err
}
return nil
}
func bootstrap(ctx context.Context) (*dagger.Container, error) {
_ = godotenv.Load()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
return nil, err
}
username := client.SetSecret("MINIO_USERNAME", os.Getenv("MINIO_USERNAME"))
password := client.SetSecret("MINIO_PASSWORD", os.Getenv("MINIO_PASSWORD"))
terraformDir := client.Host().Directory("infrastructure", dagger.HostDirectoryOpts{Exclude: []string{
".terraform/",
}})
terraform := client.
Container().
From("hashicorp/terraform").
WithSecretVariable("AWS_ACCESS_KEY_ID", username).
WithSecretVariable("AWS_SECRET_ACCESS_KEY", password).
WithSecretVariable("TF_VAR_minio_user", username).
WithSecretVariable("TF_VAR_minio_password", password).
WithEnvVariable("MINIO_ENABLE_HTTPS", "true").
WithMountedDirectory("/mnt/terraform", terraformDir).
WithWorkdir("/mnt/terraform").
WithExec([]string{
"init",
})
return terraform, nil
}