radekg / terraform-provisioner-ansible

Ansible with Terraform 0.14.x
Apache License 2.0
572 stars 100 forks source link

aws_volume_attachment not happening. #108

Closed nemonik closed 5 years ago

nemonik commented 5 years ago

Steps to reproduce

For the following terraform file I am never seeing the example_storage attach when also include the ansible provisioner, but it does when I strip out the ansible provisioner.

Expected behavior

Storage should attach.

Actual behavior

Doesn't. ...

Configuration

Terraform version: Terraform v0.11.11 + provider.aws v1.56.0

terraform-provisioner-ansible version/SHA: 2.1.1

Terraform file / provisioner configuration:

provider "aws" {
  region = "${var.region}"
}

resource "aws_volume_attachment" "example_storage_attachment" {
  device_name  = "/dev/xvdb"
  volume_id    = "${aws_ebs_volume.example.id}"
  instance_id  = "${aws_instance.example.id}"
}

resource "aws_instance" "example" {
  count           = "1"
  ami             = "${data.aws_ami.selected.id}"
  instance_type   = "${var.instance_type}"
  key_name        = "${var.key_name}"
  subnet_id       = "${element(data.aws_subnet_ids.selected.ids, count.index)}"
  security_groups = [...stripped out]
  depends_on      = ["aws_ebs_example_storage"]

  root_block_device {
    volume_size = 80
  }
  tags {
    Name = "Example"
  }

  connection {
    user = "ec2-user"
    private_key = "${file("~/${var.key_name}.pem")}"
  }

  provisioner "ansible" {
    plays {
      playbook = {
        file_path = "./ansible/playbook.yml"
        roles_path = ["./ansible/roles"]
      }
      groups = ["examples"]
      extra_vars = {
        ansible_user = "ec2-user"
        ansible_user_id = "ec2-user"
      }
    }

    remote { }
  }
}

# Example storage volume
resource "aws_ebs_volume" "example_storage" {
  size = 20
  type = "gp2"
  availability_zone = "${var.volume_region}"
  encrypted = "true"

  tags {
    Name = "Example Storage"
  }
}
nemonik commented 5 years ago

it looks like this is a common problem

https://grem11n.github.io/blog/2017/03/11/terraform-for-instances-with-ebs/

so, this may be my problem... gonna take the advice from the link above... and come back and maybe close this issue.

radekg commented 5 years ago

Hi @nemonik, is there an update on this? I'm not sure how Ansible provisioner would have such a destructive effect on your setup.

radekg commented 5 years ago

I assume this is not a problem with this provider. Hence closing.