diff --git a/README.md b/README.md index dd4d4f69a..f103f1ad2 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,6 @@ GitOps integration, secrets management, production and development Kubernetes en - [Destroy](#destroy) - [Available Commands]() -## Setup - -The setup is extremely simple, create a `.env` file in the root folder, and add the following variables: - -| Variable | example | -|--------------------|------------------| -| AWS_PROFILE | default | -| CLOUD_PROVIDER=aws | aws | -| HOSTED_ZONE_NAME | example.com | -| ADMIN_EMAIL | john@example.com | - ## Start the container We run everything on isolation with Docker, for that, start the container with: diff --git a/cmd/info.go b/cmd/info.go index 443954e6c..5702531fb 100755 --- a/cmd/info.go +++ b/cmd/info.go @@ -44,10 +44,6 @@ var infoCmd = &cobra.Command{ if err != nil { log.Panic(err) } - err = configs.CheckEnvironment() - if err != nil { - log.Panic(err) - } fmt.Printf("----------- \n") fmt.Println(reports.StyleMessage(infoSummary.String())) diff --git a/cmd/init.go b/cmd/init.go index b46a6eda0..07810d806 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -211,6 +211,13 @@ func init() { if err != nil { log.Panic(err) } + + initCmd.Flags().String("profile", "", "the profile to provision the cloud resources in") + err = initCmd.MarkFlagRequired("profile") + if err != nil { + log.Panic(err) + } + initCmd.Flags().Bool("clean", false, "delete any local kubefirst content ~/.kubefirst, ~/.k1") log.SetPrefix("LOG: ") diff --git a/configs/config.go b/configs/config.go index 471d0a6b4..69f9b9b82 100644 --- a/configs/config.go +++ b/configs/config.go @@ -75,5 +75,13 @@ func ReadConfig() *Config { config.InstallerEmail = "kubefirst-bot@kubefirst.com" + // If the AWS_SDK_LOAD_CONFIG environment variable is set to a truthy value the shared config file (~/.aws/config) + // will also be loaded in addition to the shared credentials file (~/.aws/credentials). + // AWS SDK client will take it in advance + err = os.Setenv("AWS_SDK_LOAD_CONFIG", "1") + if err != nil { + log.Panicf("unable to set AWS_SDK_LOAD_CONFIG enviroment value, error is: %v", err) + } + return &config } diff --git a/configs/envvars.go b/configs/envvars.go deleted file mode 100755 index f486b7603..000000000 --- a/configs/envvars.go +++ /dev/null @@ -1,27 +0,0 @@ -package configs - -import ( - "fmt" - "log" - "os" -) - -// CheckEnvironment validate if the required environment variable values are set. -func CheckEnvironment() error { - - requiredEnvValues := map[string]string{ - "AWS_PROFILE": os.Getenv("AWS_PROFILE"), - } - - for k, v := range requiredEnvValues { - if v == "" { - errorMsg := fmt.Sprintf("%s is not set", k) - log.Printf(errorMsg) - return fmt.Errorf(errorMsg) - } - } - - log.Println("all environment variables are set") - - return nil -} diff --git a/docker-compose.yaml b/docker-compose.yaml index 55ea902e3..befbca0f0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,6 +15,4 @@ services: - "8200:8200" # Vault volumes: - ./:/home/developer/kubefirst - env_file: - - .env command: sh -c "./scripts/kubefirst-dev.sh" diff --git a/internal/aws/aws.go b/internal/aws/aws.go index a8b4b8f46..580866067 100644 --- a/internal/aws/aws.go +++ b/internal/aws/aws.go @@ -16,6 +16,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/sts" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/aws/credentials/stscreds" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/cip8/autoname" @@ -311,12 +312,20 @@ func DestroyBucket(bucketName string) { } func GetAWSSession() *session.Session { - sess, err := session.NewSession(&aws.Config{ - Region: aws.String(viper.GetString("aws.region"))}, - ) - if err != nil { - log.Panicf("failed to get session ", err.Error()) - } + //sess, err := session.NewSession(&aws.Config{ + // Region: aws.String(viper.GetString("aws.region"))}, + //) + sess := session.Must(session.NewSessionWithOptions(session.Options{ + Config: aws.Config{ + Region: aws.String(viper.GetString("aws.region")), + }, + Profile: viper.GetString("aws.profile"), + + AssumeRoleTokenProvider: stscreds.StdinTokenProvider, + })) + //if err != nil { + // log.Panicf("failed to get session ", err.Error()) + //} return sess }