$ terraform apply --var-file=terraform.tfvars
aws_iam_policy.policy_allow_rw_access_s3_bucket: Refreshing state... [id=arn:aws:iam::111111111111:policy/s3-policy-example]
aws_iam_role.s3-role-for-ec2: Refreshing state... [id=s3-role-example]
aws_iam_instance_profile.instance-profile_s3-role-for-ec2: Refreshing state... [id=s3-role-example]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach1 will be created
+ resource "aws_iam_policy_attachment" "policy-attachment_s3-role-for-ec2-attach1" {
+ id = (known after apply)
+ name = "policy-attachment_s3-role-for-ec2-attachment1"
+ policy_arn = "arn:aws:iam::111111111111:policy/s3-policy-example"
+ roles = [
+ "s3-role-example",
]
}
# aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach2 will be created
+ resource "aws_iam_policy_attachment" "policy-attachment_s3-role-for-ec2-attach2" {
+ id = (known after apply)
+ name = "policy-attachment_s3-role-for-ec2-attachment2"
+ policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
+ roles = [
+ "s3-role-example",
]
}
Plan: 2 to add, 0 to change, 0 to destroy.
Warning: Argument is deprecated
Use shared_credentials_files instead.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach1: Creating...
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach2: Creating...
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach1: Creation complete after 1s [id=policy-attachment_s3-role-for-ec2-attachment1]
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach2: Creation complete after 1s [id=policy-attachment_s3-role-for-ec2-attachment2]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: ./terraform.tfstate
次に、Terraform のコードは一切変更せず、再度terraform apply を実行します。出力結果に「No changes. Infrastructure is up-to-date.」と表示されることを期待しましたが、「1 to change」と表示されました。今回は、yes と入力して変更を適用します。 ※実際には、出力結果が期待と異なる場合にyes を入力してはいけません。
$ terraform apply --var-file=terraform.tfvars
aws_iam_policy.policy_allow_rw_access_s3_bucket: Refreshing state... [id=arn:aws:iam::111111111111:policy/s3-policy-example]
aws_iam_role.s3-role-for-ec2: Refreshing state... [id=s3-role-example]
aws_iam_instance_profile.instance-profile_s3-role-for-ec2: Refreshing state... [id=s3-role-example]
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach2: Refreshing state... [id=policy-attachment_s3-role-for-ec2-attachment2]
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach1: Refreshing state... [id=policy-attachment_s3-role-for-ec2-attachment1]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach2 will be updated in-place
~ resource "aws_iam_policy_attachment" "policy-attachment_s3-role-for-ec2-attach2" {
groups = []
id = "policy-attachment_s3-role-for-ec2-attachment2"
name = "policy-attachment_s3-role-for-ec2-attachment2"
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
~ roles = [
- "niikawa-test-role-ec2",
"s3-role-example",
]
~ users = [
- "test-niikawa",
]
}
Plan: 0 to add, 1 to change, 0 to destroy.
Warning: Argument is deprecated
Use shared_credentials_files instead.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach2: Modifying... [id=policy-attachment_s3-role-for-ec2-attachment2]
aws_iam_policy_attachment.policy-attachment_s3-role-for-ec2-attach2: Modifications complete after 2s [id=policy-attachment_s3-role-for-ec2-attachment2]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.
State path: ./terraform.tfstate