feat: add vault terraform user
This commit is contained in:
59
shuttletask/plan.go
Normal file
59
shuttletask/plan.go
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user