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 additional instances that have volume attachments #235

Closed
hashibot opened this issue Jun 13, 2017 · 3 comments
Closed

Adding additional instances that have volume attachments #235

hashibot opened this issue Jun 13, 2017 · 3 comments
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. upstream-terraform Addresses functionality related to the Terraform core binary.

Comments

@hashibot
Copy link

This issue was originally opened by @micahlmartin as hashicorp/terraform#8395. It was migrated here as part of the provider split. The original body of the issue is below.


I have a module that creates an instance or mysql and attaches an ebs volume. I'm trying to increase the number of instances from 1 to 3. Here is the configuration:

resource "aws_instance" "mysql_galera" {
  count = "${var.instances}"
  ami = "${var.ami_id}"
  instance_type = "${var.instance_type}"
  vpc_security_group_ids = ["${var.security_groups}"]
  subnet_id = "${element(var.subnets, count.index)}"
  user_data = "${data.template_cloudinit_config.config.rendered}"
  iam_instance_profile = "${var.iam_instance_profile}"
  ebs_optimized = true
  ....
}

resource "aws_ebs_volume" "mysql_galera_ebs_volume" {
  depends_on = ["aws_instance.mysql_galera"]
  count = "${var.instances}"
  availability_zone = "${element(aws_instance.mysql_galera.*.availability_zone, count.index)}"
  encrypted = "${var.ebs_encrypted}"
  size = "${var.ebs_size}"
  type = "${var.ebs_type}"
}

resource "aws_volume_attachment" "mysql_galera_ebs_attachment" {
  count = "${var.instances}"
  device_name = "/dev/sdh"
  volume_id = "${element(aws_ebs_volume.mysql_galera_ebs_volume.*.id, count.index)}"
  instance_id = "${element(aws_instance.mysql_galera.*.id, count.index)}"
}

Here's the relevant part of the plan:

-/+ module.base.mysql_galera.aws_volume_attachment.mysql_galera_ebs_attachment.0
    device_name:  "/dev/sdh" => "/dev/sdh"
    force_detach: "" => "<computed>"
    instance_id:  "i-xxx" => "${element(aws_instance.mysql_galera.*.id, count.index)}" (forces new resource)
    volume_id:    "vol-xxx" => "${element(aws_ebs_volume.mysql_galera_ebs_volume.*.id, count.index)}" (forces new resource)

If I've already created the first resource and then increase the count to 3 this is what I get. Any ideas on how to handle this?

@hashibot hashibot added the bug Addresses a defect in current functionality. label Jun 13, 2017
@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 25, 2018
@bflad
Copy link
Contributor

bflad commented Nov 8, 2018

I'm able to reproduce this issue on Terraform 0.11.10 with the below configuration - we can check Terraform 0.12 to see if it helps.

terraform {
  required_version = "0.11.10"
}

provider "aws" {
  region  = "us-east-1"
  version = "1.43.0"
}

variable "count" {
  # bug encountered when updated to 3
  default = 1
}

data "aws_ami" "test" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn-ami-hvm-*-x86_64-gp2"]
  }
}

data "aws_availability_zones" "available" {}

data "aws_subnet" "test" {
  availability_zone = "${data.aws_availability_zones.available.names[0]}"
  default_for_az    = true
}

resource "aws_instance" "test" {
  count = "${var.count}"

  ami           = "${data.aws_ami.test.id}"
  instance_type = "t2.medium"
  subnet_id     = "${data.aws_subnet.test.id}"
}

resource "aws_ebs_volume" "test" {
  count = "${var.count}"

  availability_zone = "${element(aws_instance.test.*.availability_zone, count.index)}"
  size              = "10"
  type              = "gp2"
}

resource "aws_volume_attachment" "test" {
  count = "${var.count}"

  device_name = "/dev/xvdg"
  instance_id = "${element(aws_instance.test.*.id, count.index)}"
  volume_id   = "${element(aws_ebs_volume.test.*.id, count.index)}"
}

@bflad bflad added the upstream-terraform Addresses functionality related to the Terraform core binary. label Nov 8, 2018
@bflad
Copy link
Contributor

bflad commented Nov 8, 2018

This appears to be a duplicate of #83 -- closing to consolidate discussions there.

@bflad bflad closed this as completed Nov 8, 2018
@ghost
Copy link

ghost commented Apr 2, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. upstream-terraform Addresses functionality related to the Terraform core binary.
Projects
None yet
Development

No branches or pull requests

3 participants