From e31a66a59d9f85d1f407f90298c2add49d3469f0 Mon Sep 17 00:00:00 2001 From: schulze Date: Mon, 20 Mar 2023 15:43:14 +0100 Subject: [PATCH] add manual credentials --- config.yaml | 2 +- main.go | 2 +- mtd_aws/sdk.go | 4 ++-- state/config.go | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index b2fc771..db71ee2 100644 --- a/config.yaml +++ b/config.yaml @@ -3,4 +3,4 @@ aws: - us-east-1 - us-east-2 - us-west-1 - + credentials_path: ./mtd_aws/.credentials \ No newline at end of file diff --git a/main.go b/main.go index c128074..3194e7c 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ func main() { for _, region := range config.AWS.Regions { fmt.Println("Listing instances in region:", region) - aws_config := mtd_aws.New_config(region) + aws_config := mtd_aws.New_config(region, config.AWS.Credentials_path) instances, err := mtd_aws.Instances(aws_config) if err != nil { fmt.Println("Error listing instances:", err) diff --git a/mtd_aws/sdk.go b/mtd_aws/sdk.go index 8ceb276..f52774a 100644 --- a/mtd_aws/sdk.go +++ b/mtd_aws/sdk.go @@ -10,9 +10,9 @@ import ( "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go-v2/service/ec2/types" ) -func New_config(region string) aws.Config { +func New_config(region string, credentials string) aws.Config { // Create a new AWS config - cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region)) + cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithSharedConfigFiles([]string{credentials}), config.WithRegion(region)) if err != nil { fmt.Println("Error creating config:", err) fmt.Println("Configure Credentials in line with the documentation found here: https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials") diff --git a/state/config.go b/state/config.go index f3b2b48..a470103 100644 --- a/state/config.go +++ b/state/config.go @@ -9,7 +9,8 @@ import ( type Config struct { AWS struct { - Regions []string `yaml:"regions"` + Regions []string `yaml:"regions"` + Credentials_path string `yaml:"credentials_path"` } `yaml:"aws"` }