diff --git a/cmd/create.go b/cmd/create.go index 2482e42c6..054f47331 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "log" + "os" "os/exec" "syscall" "time" @@ -54,6 +55,19 @@ to quickly create a Cobra application.`, log.Panic(err) } + // set profile + profile, err := cmd.Flags().GetString("profile") + if err != nil { + log.Panicf("unable to get region values from viper") + } + viper.Set("aws.profile", profile) + // propagate it to local environment + err = os.Setenv("AWS_PROFILE", profile) + if err != nil { + log.Panicf("unable to set environment variable AWS_PROFILE, error is: %v", err) + } + log.Println("profile:", profile) + infoCmd.Run(cmd, args) progressPrinter.IncrementTracker("step-0", 1) @@ -395,6 +409,12 @@ func init() { createCmd.Flags().Bool("skip-gitlab", false, "Skip GitLab lab install and vault setup") createCmd.Flags().Bool("skip-vault", false, "Skip post-gitClient lab install and vault setup") + initCmd.Flags().String("profile", "", "the profile to provision the cloud resources in. The profile data is collected from ~/.aws/config") + err := initCmd.MarkFlagRequired("profile") + if err != nil { + log.Panic(err) + } + progressPrinter.GetInstance() progressPrinter.SetupProgress(4) } diff --git a/cmd/destroy.go b/cmd/destroy.go index 581423f26..b1fb615de 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -9,7 +9,9 @@ import ( "github.com/kubefirst/kubefirst/internal/k8s" "github.com/kubefirst/kubefirst/internal/terraform" "github.com/spf13/cobra" + "github.com/spf13/viper" "log" + "os" "os/exec" "syscall" ) @@ -44,6 +46,19 @@ if the registry has already been deleted.`, log.Panic(err) } + // set profile + profile, err := cmd.Flags().GetString("profile") + if err != nil { + log.Panicf("unable to get region values from viper") + } + viper.Set("aws.profile", profile) + // propagate it to local environment + err = os.Setenv("AWS_PROFILE", profile) + if err != nil { + log.Panicf("unable to set environment variable AWS_PROFILE, error is: %v", err) + } + log.Println("profile:", profile) + arnRole, err := cmd.Flags().GetString("aws-assume-role") if err != nil { log.Println("unable to use the provided AWS IAM role for AssumeRole feature") @@ -131,6 +146,12 @@ func init() { destroyCmd.Flags().Bool("skip-base-terraform", false, "whether to skip the terraform destroy against base install - note: if you already deleted registry it doesnt exist") destroyCmd.Flags().Bool("destroy-buckets", false, "remove created aws buckets, not empty buckets are not cleaned") + initCmd.Flags().String("profile", "", "the profile to provision the cloud resources in. The profile data is collected from ~/.aws/config") + err := initCmd.MarkFlagRequired("profile") + if err != nil { + log.Panic(err) + } + // AWS assume role destroyCmd.Flags().String("aws-assume-role", "", "instead of using AWS IAM user credentials, AWS AssumeRole feature generate role based credentials, more at https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html") } diff --git a/cmd/init.go b/cmd/init.go index f539f2d5a..6f46d5fb2 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -242,7 +242,7 @@ func init() { log.Panic(err) } - initCmd.Flags().String("profile", "", "the profile to provision the cloud resources in. The profile data is collected from ~/aws/config") + initCmd.Flags().String("profile", "", "the profile to provision the cloud resources in. The profile data is collected from ~/.aws/config") err = initCmd.MarkFlagRequired("profile") if err != nil { log.Panic(err)