Last active
March 28, 2017 20:45
-
-
Save billmoritz/b843faf1e413ba74e231e1eab9d5df85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
region = "us-west-2" | |
} | |
variable "server_count" { | |
default = 4 | |
} | |
resource "aws_eip" "ip" { | |
count = "${var.server_count}" | |
instance = "${element(aws_instance.example.*.id, count.index)}" | |
vpc = true | |
} | |
resource "aws_instance" "example" { | |
count = "${var.server_count}" | |
ami = "ami-dfc39aef" | |
instance_type = "t2.nano" | |
associate_public_ip_address = true | |
subnet_id = "${aws_subnet.us-west-2b-public.id}" | |
availability_zone = "${aws_subnet.us-west-2b-public.availability_zone}" | |
tags { | |
Name = "tf-issue-3429-repro" | |
} | |
lifecycle { | |
create_before_destroy = true | |
} | |
} | |
resource "aws_route53_record" "ec2_instance_fqdn" { | |
count = "${var.server_count}" | |
zone_id = "${var.hosted_zone_id}" | |
name = "${format("%v-%02d.%v", var.role, count.index+1, var.domain)}" | |
type = "CNAME" | |
ttl = "60" | |
records = ["${element(aws_instance.example.*.private_dns, count.index)}"] | |
} | |
variable "role" { | |
default = "example" | |
} | |
variable "domain" { | |
default = "exmaple.com" | |
} | |
variable "hosted_zone_id" { | |
default = "XXXXXXXXXXXXX" | |
} | |
resource "aws_vpc" "example" { | |
cidr_block = "10.0.0.0/16" | |
} | |
resource "aws_internet_gateway" "example" { | |
vpc_id = "${aws_vpc.example.id}" | |
} | |
resource "aws_subnet" "us-west-2b-public" { | |
vpc_id = "${aws_vpc.example.id}" | |
cidr_block = "10.0.0.0/24" | |
availability_zone = "us-west-2b" | |
} | |
resource "aws_route_table" "us-west-2-public" { | |
vpc_id = "${aws_vpc.example.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.example.id}" | |
} | |
} | |
resource "aws_route_table_association" "us-west-2b-public" { | |
subnet_id = "${aws_subnet.us-west-2b-public.id}" | |
route_table_id = "${aws_route_table.us-west-2-public.id}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> awsu exec terraform taint aws_instance.example.0 | |
The resource aws_instance.example.0 in the module root has been marked as tainted! | |
> awsu exec terraform apply | |
aws_vpc.example: Refreshing state... (ID: vpc-4ed29a29) | |
aws_internet_gateway.example: Refreshing state... (ID: igw-fbcadf9f) | |
aws_subnet.us-west-2b-public: Refreshing state... (ID: subnet-8dc0a6ea) | |
aws_route_table.us-west-2-public: Refreshing state... (ID: rtb-46b14220) | |
aws_instance.example.0: Refreshing state... (ID: i-0f26591f4be67e722) | |
aws_instance.example.2: Refreshing state... (ID: i-00cf35593dd0980e6) | |
aws_instance.example.1: Refreshing state... (ID: i-053728ba715cc1e69) | |
aws_instance.example.3: Refreshing state... (ID: i-0e98782b96477aca5) | |
aws_route_table_association.us-west-2b-public: Refreshing state... (ID: rtbassoc-6f9c8709) | |
aws_eip.ip.1: Refreshing state... (ID: eipalloc-e6e21080) | |
aws_route53_record.ec2_instance_fqdn.3: Refreshing state... (ID: XXXXXXXXXXXXX_example-04.example.com_CNAME) | |
aws_eip.ip.3: Refreshing state... (ID: eipalloc-6be0120d) | |
aws_eip.ip.0: Refreshing state... (ID: eipalloc-3dff0d5b) | |
aws_eip.ip.2: Refreshing state... (ID: eipalloc-57e61431) | |
aws_route53_record.ec2_instance_fqdn.2: Refreshing state... (ID: XXXXXXXXXXXXX_example-03.example.com_CNAME) | |
aws_route53_record.ec2_instance_fqdn.1: Refreshing state... (ID: XXXXXXXXXXXXX_example-02.example.com_CNAME) | |
aws_route53_record.ec2_instance_fqdn.0: Refreshing state... (ID: XXXXXXXXXXXXX_example-01.example.com_CNAME) | |
aws_instance.example.0: Creating... | |
ami: "" => "ami-dfc39aef" | |
associate_public_ip_address: "" => "true" | |
availability_zone: "" => "us-west-2b" | |
ebs_block_device.#: "" => "<computed>" | |
ephemeral_block_device.#: "" => "<computed>" | |
instance_state: "" => "<computed>" | |
instance_type: "" => "t2.nano" | |
key_name: "" => "<computed>" | |
network_interface_id: "" => "<computed>" | |
placement_group: "" => "<computed>" | |
private_dns: "" => "<computed>" | |
private_ip: "" => "<computed>" | |
public_dns: "" => "<computed>" | |
public_ip: "" => "<computed>" | |
root_block_device.#: "" => "<computed>" | |
security_groups.#: "" => "<computed>" | |
source_dest_check: "" => "true" | |
subnet_id: "" => "subnet-8dc0a6ea" | |
tags.%: "" => "1" | |
tags.Name: "" => "tf-issue-3429-repro" | |
tenancy: "" => "<computed>" | |
vpc_security_group_ids.#: "" => "<computed>" | |
aws_instance.example.0: Still creating... (10s elapsed) | |
aws_instance.example.0: Creation complete | |
aws_eip.ip.0: Modifying... | |
instance: "i-0f26591f4be67e722" => "i-020a1925c3e7e60d9" | |
aws_route53_record.ec2_instance_fqdn.0: Modifying... | |
records.2781236304: "" => "ip-10-0-0-90.us-west-2.compute.internal" | |
records.320270958: "ip-10-0-0-205.us-west-2.compute.internal" => "" | |
aws_route53_record.ec2_instance_fqdn.0: Still modifying... (10s elapsed) | |
aws_route53_record.ec2_instance_fqdn.0: Still modifying... (20s elapsed) | |
aws_route53_record.ec2_instance_fqdn.0: Still modifying... (30s elapsed) | |
aws_route53_record.ec2_instance_fqdn.0: Still modifying... (40s elapsed) | |
aws_route53_record.ec2_instance_fqdn.0: Modifications complete | |
Error applying plan: | |
1 error(s) occurred: | |
* aws_eip.ip.0: Failure associating EIP: Resource.AlreadyAssociated: resource eipalloc-3dff0d5b is already associated with associate-id eipassoc-dfb259a2 | |
status code: 400, request id: a2762deb-18a5-4dea-ace5-94045976dc64 | |
Terraform does not automatically rollback in the face of errors. | |
Instead, your Terraform state file has been partially updated with | |
any resources that successfully completed. Please address the error | |
above and apply again to incrementally change your infrastructure. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment