_This issue was originally opened by @iwat as hashicorp/terraform#8746. It was migrated here as part of the provider split. The original body of the issue is below._
Terraform v0.7.3
This affects all AWS related command.
resource "aws_security_group_rule" "demo_pri_ingress_vpn_service" {
security_group_id = "${aws_security_group.demo_pri.id}"
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["${data.terraform_remote_state.infra.vpn-cidr_block}"]
}
https://gist.github.com/iwat/df0b0ebfe2f8db62adfd5953bfd6b92c
None
It should work by using IAM Role for ECS Task.
awscli works
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
None
@stack72 This is still an issue on 0.9.10. Any hope of fixing this in the near future? terraform should try getting the ECS credentials before the instance-profile credentials.
http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html
I hope Terraform will be able to get these credentials for use in CodeBuild. For now I am doing the following:
export AWS_ACCESS_KEY_ID=`curl --silent http://169.254.170.2:80$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | jq -r '.AccessKeyId'`
export AWS_SECRET_ACCESS_KEY=`curl --silent http://169.254.170.2:80$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | jq -r '.SecretAccessKey'`
export AWS_SESSION_TOKEN=`curl --silent http://169.254.170.2:80$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | jq -r '.Token'`
Cheers!
This was implemented in #1425 which was just merged.
Here's a similar workaround to the one above for CodeBuild which may be useful in a python container with minimal bash utilities. Placed in the buildspec file.
- export AWS_ACCESS_KEY_ID=$(python -c 'import json,sys,urllib2;i=json.load(urllib2.urlopen(urllib2.Request(sys.argv[1])));print(i["AccessKeyId"]);' "http://169.254.170.2:80$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI")
- export AWS_SECRET_ACCESS_KEY=$(python -c 'import json,sys,urllib2;i=json.load(urllib2.urlopen(urllib2.Request(sys.argv[1])));print(i["SecretAccessKey"]);' "http://169.254.170.2:80$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI")
- export AWS_SESSION_TOKEN=$(python -c 'import json,sys,urllib2;i=json.load(urllib2.urlopen(urllib2.Request(sys.argv[1])));print(i["Token"]);' "http://169.254.170.2:80$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI")
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
This was implemented in #1425 which was just merged.