digitickets / terraform-aws-cli

Run the AWS CLI, with the ability to run under an assumed role, to access resources and properties missing from the Terraform AWS Provider.
26 stars 11 forks source link

Error when using profile + assume role #8

Closed gregory-lecomte closed 7 months ago

gregory-lecomte commented 9 months ago

Hello,

I can't use the module when I want to use a profile + an assume role. The console return the following error :

╷
│ Error: External Program Execution Failed
│ 
│   with module.proxy_protocol_v2_https.data.external.awscli_program,
│   on .terraform/modules/proxy_protocol_v2_https/main.tf line 22, in data "external" "awscli_program":
│   22:   program = [format("%s/scripts/awsWithAssumeRole.sh", path.module)]
│ 
│ The data source received an unexpected error while attempting to execute the program.
│ 
│ Program: .terraform/modules/proxy_protocol_v2_https/scripts/awsWithAssumeRole.sh
│ Error Message: .terraform/modules/proxy_protocol_v2_https/scripts/awsWithAssumeRole.sh: 27: [-n: not found
│ 
│ Unable to locate credentials. You can configure credentials by running "aws configure".
│ 
│ Unable to locate credentials. You can configure credentials by running "aws configure".
│ 
│ State: exit status 1

Additionally, as you can see in the return message, there is an error line 27, some spaces are missing around brackets.

To fix temporary my issue, I had to add in the bash script the option "--profile" in sts assume command line to fix my issue with a variable "profile" in the variable.tf file.

But I think you can do better to take in consideration the option --profile when it's set or not.

Regards,

rquadling commented 7 months ago

You can add --profile to the list of arguments you want to run. Slightly messy maybe, but as profile is part of the command line call, adding it makes sense.

e.g.

aws_cli_commands   = ["s3api", "list-objects", "--profile", "your-profile-name-here", "--bucket", "ryft-public-sample-data", "--no-sign-request"]

I can certainly add the option of using a profile argument.

And I'll also fix the lack of white space (VERY sorry about that!!!).

rquadling commented 7 months ago

I've also added support for --region. Final testing and releasing shortly.