It seems that it does not actually invoke the STS GetCallerId endpoint, which can provide the necessary information, in particular, the UserId and Arn of the user executing the command. aws_caller_identity
Instead, it accepts a simpler option and simply uses the accountidrecord that the AWS client has already defined and simply returns it.
, . , aws_caller_identity aws_caller_identity STS GetCallerId, .
, Terraform , Terraform, , - -, , , UserId Arn.
, , , - , EC2:
resource "aws_instance" "instance" {
ami = "ami-123456"
instance_type = "t2.micro"
tags {
Name = "HelloWorld"
}
lifecycle {
ignore_changes = [ "tags.Owner" ]
}
provisioner "local-exec" {
command = <<EOF
owner='aws sts get-caller-identity --output text --query 'Arn' | cut -d"/" -f2'
aws ec2 create-tags --resources ${self.id} --tags Key=Owner,Value=$${owner}
EOF
}
}
Terraform EC2 , "". , / IAM , "" , .