Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
Signed-off-by: João Vanzuita <joao@kubeshop.io>
  • Loading branch information
João Vanzuita committed Jul 20, 2022
1 parent efc8dd9 commit 7b8044a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"syscall"
"time"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
21 changes: 21 additions & 0 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7b8044a

Please sign in to comment.