Skip to content

Instantly share code, notes, and snippets.

@phinze
Last active December 3, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phinze/97c728df1b6497877450 to your computer and use it in GitHub Desktop.
Save phinze/97c728df1b6497877450 to your computer and use it in GitHub Desktop.
Example for terraform-tool mailing list of moving a subnet between VPCs
# See https://groups.google.com/d/msgid/terraform-tool/db2ee775-e8b8-4e6b-8b3a-35fb182a1571%40googlegroups.com
# Setting region so AMI always works, configure the rest via env vars
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "from" {
cidr_block = "10.1.0.0/16"
}
resource "aws_vpc" "to" {
cidr_block = "10.1.0.0/16"
}
resource "aws_subnet" "moving" {
# before
vpc_id = "${aws_vpc.from.id}"
# after
# vpc_id = "${aws_vpc.to.id}"
cidr_block = "10.1.1.0/24"
}
resource "aws_launch_configuration" "vanillaubuntu" {
image_id = "ami-534d5d32"
instance_type = "t2.micro"
}
resource "aws_autoscaling_group" "someapp" {
# Does not trigger ASG replacement
name = "someapp - ${aws_launch_configuration.vanillaubuntu.id}"
# Does trigger ASG replacement
# name = "someapp - ${aws_launch_configuration.vanillaubuntu.id} - ${aws_subnet.moving.id}"
max_size = 1
min_size = 1
vpc_zone_identifier = ["${aws_subnet.moving.id}"]
launch_configuration = "${aws_launch_configuration.vanillaubuntu.id}"
}

Without ASG name interpolating the subnet ID:

~ aws_autoscaling_group.someapp
    vpc_zone_identifier.#: "" => "<computed>"

-/+ aws_subnet.moving
    availability_zone:       "us-west-2c" => "<computed>"
    cidr_block:              "10.1.1.0/24" => "10.1.1.0/24"
    map_public_ip_on_launch: "false" => "0"
    vpc_id:                  "vpc-e825108d" => "vpc-e925108c" (forces new resource)


Plan: 1 to add, 1 to change, 1 to destroy.

With name interpolating the subnet ID:

-/+ aws_autoscaling_group.someapp
    default_cooldown:          "300" => "<computed>"
    desired_capacity:          "1" => "<computed>"
    force_delete:              "false" => "0"
    health_check_grace_period: "0" => "<computed>"
    health_check_type:         "EC2" => "<computed>"
    launch_configuration:      "terraform-vsvm7ctixfbgpcqzzai5ipcgb4" => "terraform-vsvm7ctixfbgpcqzzai5ipcgb4"
    max_size:                  "1" => "1"
    min_size:                  "1" => "1"
    name:                      "someapp - terraform-vsvm7ctixfbgpcqzzai5ipcgb4" => "someapp - ${aws_launch_configuration.vanillaubuntu.id} - ${aws_subnet.moving.id}" (forces new resource)
    vpc_zone_identifier.#:     "1" => "<computed>"
    wait_for_capacity_timeout: "10m" => "10m"

-/+ aws_subnet.moving
    availability_zone:       "us-west-2c" => "<computed>"
    cidr_block:              "10.1.1.0/24" => "10.1.1.0/24"
    map_public_ip_on_launch: "false" => "0"
    vpc_id:                  "vpc-e825108d" => "vpc-e925108c" (forces new resource)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment