New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform does not use IAM Role for ECS Task as credential provider #8746
Comments
A little context to help the enhancement along. I ran into this while trying to run a terraform command from the new AWS CodeBuild service (which is running on an AWS hosted ECS cluster farm it seems). In the newer versions of the AWS SDK, they've added one more "location" to scan for IAM keys to support IAM roles on docker containers. The launched docker containers, if they have an IAM role, get passed an extra environment variable like this:
Since all the SDK's have been updated to scan this location as well as the usual paths, it just seems to work like magic when you run AWS commands. This sample, and all the gory details are from here Hopefully this is enough to get somebody going on the terraform enhancement. Any takers? UPDATE: Of course, now that I just typed all that, it seems that if you are using the aws-sdk-go package, you just need to update the dependency version. These seem to be the minimums |
Faced the problem from within AWS CodeBuild with v0.8.6 as well. |
Facing the same problem. It seems that the Terraform AWS credential logic is custom and does not use the default terraform/builtin/providers/aws/auth_helpers.go Lines 94 to 204 in 351c6be
|
I blogged about using Terraform within CodeBuild, which includes a workaround for this problem: https://www.ruempler.eu/2017/02/26/continuous-infrastructure-delivery-pipeline-aws-codepipeline-codebuild-terraform/ |
This may be a little off-topic, but here's my workaround for use with Jenkins Pipelines (Groovy)
|
Thanks for this feature request @iwat, and thanks to everyone else for the great info that followed. Terraform is using the official Go SDK for AWS but is customizing the set of valid credential sources. To implement this I expect we would need to upgrade the SDK (assuming we didn't already do that for some other reason) and add one more credential provider to the list in the Terraform AWS provider. Since this one is gated on the presence of an environment variable it should be safe to add without any unintended consequences for those not using ECS. The Terraform team doesn't have any immediate plans to work on this but if someone else had the time or motivation we would love to review a PR! |
I submitted PR #14199 for this. A couple questions in the PR, but hopefully this will help get terraform working with CodeBuild/ECS slaves. |
I can confirm this is now working in CodeBuild WITHOUT the pre_build phase I posted above. Terraform 0.11.7 and Terraform AWS provider 1.14.1. Brilliant work 👍 |
I can confirm that terraform trying to assume the role of EC2's instead of ECS's Below are some logs terraform version: 0.12.21 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform v0.7.3
Affected Resource(s)
This affects all AWS related command.
Terraform Configuration Files
Debug Output
https://gist.github.com/iwat/df0b0ebfe2f8db62adfd5953bfd6b92c
Panic Output
None
Expected Behavior
It should work by using IAM Role for ECS Task.
awscli works
Actual Behavior
It was using EC2 Instance Role which does not allow this action.
Error retrieving Target Group: AccessDenied: User: arn:aws:sts::872767853649:assumed-role/myrole/i-0223aeb98c19f2d0d
Steps to Reproduce
Important Factoids
None
References
The text was updated successfully, but these errors were encountered: