Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new aws opsworks instances forces all the other instances to be re-created #6787

Closed
iroller opened this issue May 20, 2016 · 5 comments

Comments

@iroller
Copy link
Contributor

iroller commented May 20, 2016

Hi there,

I'm trying to have aws_opsworks_instance, aws_subnet and aws_route_table_association to be created depending on a number set in variables, but once I add one more I'm always getting all the instances re-created all over again:

    subnet_id:                    "subnet-ed8bacd0" => "${element(aws_subnet.private.*.id, count.index)}" (forces new resource)

Here's my config:

# Create private associations
resource "aws_route_table_association" "private" {
  count = "${var.instance_count}"
  subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
  route_table_id = "${aws_route_table.nat-private.id}"
  lifecycle {
    create_before_destroy = true
  }
}

# Create private subnets for app instances
resource "aws_subnet" "private" {
  count = "${var.instance_count}"
  vpc_id = "${aws_vpc.my-vpc.id}"
  availability_zone = "${lookup(var.instances, count.index)}"
  cidr_block = "${concat(var.vpc_cidr_block_base, ".", count.index + 1 ,".0/24")}"
  map_public_ip_on_launch = false
  tags {
    Name = "private.${lookup(var.instances, count.index)}"
    Environment = "${var.environment}"
  }
  lifecycle {
    create_before_destroy = true
  }
}


# Instances
resource "aws_opsworks_instance" "app" {
  stack_id = "${aws_opsworks_stack.my-stack.id}"
  layer_ids = [
    "${aws_opsworks_rails_app_layer.app.id}",
  ]
  availability_zone = "${lookup(var.instances, count.index)}"
  subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
  instance_type    = "t2.small"
  os               = "Ubuntu 14.04 LTS"
  state            = "running"
  root_device_type = "ebs"
  count = "${var.instance_count}"
}

And variables:

variable "instances" {
  description = "OpsWorks App instances"
  default     = {
    "0" = "us-east-1e"
    "1" = "us-east-1a"
    "2" = "us-east-1c"
    "3" = "us-east-1c" # re-creates all the instances once I'm adding that
  }
}
# Still need to provide that until we can figure out how to count instanced in the map above
variable "instance_count" {
  description = "Count"
  default     = "4"
}

When I'm running terraform plan with v. 0.6.16 it's showing that each opsworks instance is going to be re-created and the new one will be added.

How to prevent it from re-creating all the existing instances?

@iroller iroller changed the title Adding a new aws ec2 instances forces all the other instances to be recreated Adding a new aws opsworks instances forces all the other instances to be recreated May 20, 2016
@iroller iroller changed the title Adding a new aws opsworks instances forces all the other instances to be recreated Adding a new aws opsworks instances forces all the other instances to be re-created May 20, 2016
@iroller
Copy link
Contributor Author

iroller commented May 20, 2016

Latest master is failing with the following:

  * concat: arguments to concat() must be a string or list in:
${concat(var.vpc_cidr_block_base, ".", count.index + 1, ".0/24")}

EDIT: can be worked around by using format() instead of concat() but the initial issue with re-creating instances is still there.

@iroller
Copy link
Contributor Author

iroller commented May 20, 2016

Also this is not happening on every terraform plan, only when adding a new instance into var.instances and bumping var.instance_count.

@iroller
Copy link
Contributor Author

iroller commented May 20, 2016

I figured this problem was mentioned in many issues before. The workaround suggested by @apparentlymart works fine. In this case it looks like this:

terraform apply -target="aws_opsworks_instance.app[3]" -target="aws_subnet.private[3]" -target="aws_route_table_association.private[3]"

@catsby
Copy link
Contributor

catsby commented May 25, 2016

Hey @iroller thanks for the detailed report here. It looks like the core issue is here:

This may be fixed in the master branch and released with v0.7.0, though I believe you need to use the newly introduced (in v0.7.0) list type (added here #6322)

For now though the workaround is your best bet. Since this is tracked elsewhere, I'm going to go ahead and close this. Thanks again!

@ghost
Copy link

ghost commented Apr 25, 2020

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants