terraform - local-exec -- when destroy not working as expected

1,171 views
Skip to first unread message

kamalakar vadla

unread,
Jun 27, 2017, 7:12:23 PM6/27/17
to Terraform
Hi All,

  • terraform destroy - running my local-exec provisioner on destroy as expected
  • terraform apply  - Not running defined local-exec provisioner on destroy ( in case of existing resource getting destroyed and creating new resource)

Not sure why it is not calling in case of existing resource getting destroyed and creating new resource ?


Terraform version :  v0.9.6

Your help is appreciated 

Regards
KV

Lowe Schmidt

unread,
Jun 28, 2017, 6:49:53 AM6/28/17
to terrafo...@googlegroups.com
Some code for reference would help a lot.

--
Lowe Schmidt | +46 723 867 157

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/cc8f6151-4506-4969-a3d5-1afa0456069b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kamalakar vadla

unread,
Jun 28, 2017, 10:11:20 AM6/28/17
to Terraform
Sample code :

resource "aws_instance" "hcvault_ec2_instance" {
  count = "${var.servers}"
  ami = "${var.ami}"
  instance_type = "${var.InstanceType}"
  monitoring = "${var.ec2_monitoring}"
  iam_instance_profile = "${var.InstanceProfile}"
  vpc_security_group_ids = ["${var.SecurityGroupIds}"]
  subnet_id = "${element(var.Subnets-AZS, count.index)}"
  tags {
    Name = "${var.InstanceName}-${var.application_environment}${count.index}"
    ASV = "${var.ASV}"
    CMDBEnvironment = "${var.CMDBEnvironment}"
    OwnerContact = "${var.OwnerContact}"
    OwnerEid = "${var.OwnerEid}"
    consulrole = "${var.consulrole}-${var.application_environment}"
  }
  key_name = "${var.KeyFiles}"
  user_data = "${data.template_file.ec2_user_data.rendered}"

  provisioner "local-exec" {
     when = "destroy"
     command = "bash test.sh ${self.private_dns}"
  }

}

output "terra-private-ip" {
    value = ["${aws_instance.hcvault_ec2_instance.*.private_ip}"]
}

output "wait_for_cluster" { value = ["${join(",",aws_instance.hcvault_ec2_instance.*.id)}"] }


Output

module.vault-agent.aws_instance.hcvault_ec2_instance.1 (deposed #0): Still destroying... (ID: i-08812aa0a56bca547, 10s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 10s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.0 (deposed #0): Still destroying... (ID: i-0b7a8b64677b8e605, 10s elapsed)

module.consul-server.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0641c9238daf05acf, 10s elapsed)

module.consul-server.aws_instance.hcvault_ec2_instance.1 (deposed #0): Still destroying... (ID: i-005fbf47d60de7ecc, 10s elapsed)

module.consul-server.aws_instance.hcvault_ec2_instance.0 (deposed #0): Still destroying... (ID: i-0d853a2d067d3ad9e, 10s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.1 (deposed #0): Still destroying... (ID: i-08812aa0a56bca547, 20s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 20s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.0 (deposed #0): Still destroying... (ID: i-0b7a8b64677b8e605, 20s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.1 (deposed #0): Still destroying... (ID: i-08812aa0a56bca547, 30s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 30s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.0 (deposed #0): Still destroying... (ID: i-0b7a8b64677b8e605, 30s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.0 (deposed #0): Destruction complete

module.vault-agent.aws_instance.hcvault_ec2_instance.1 (deposed #0): Still destroying... (ID: i-08812aa0a56bca547, 40s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 40s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.1 (deposed #0): Destruction complete

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 50s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 1m0s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 1m10s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Still destroying... (ID: i-0ad13a5c12a605c91, 1m20s elapsed)

module.vault-agent.aws_instance.hcvault_ec2_instance.2 (deposed #0): Destruction complete


From above output it is not calling local-exec on destroy of existing instance .

Let me know if you need any more data from my end.

Regards
KV


On Wednesday, 28 June 2017 05:49:53 UTC-5, Lowe Schmidt wrote:
Some code for reference would help a lot.

--
Lowe Schmidt | +46 723 867 157

On 28 June 2017 at 01:12, kamalakar vadla <vkcha...@gmail.com> wrote:
Hi All,

  • terraform destroy - running my local-exec provisioner on destroy as expected
  • terraform apply  - Not running defined local-exec provisioner on destroy ( in case of existing resource getting destroyed and creating new resource)

Not sure why it is not calling in case of existing resource getting destroyed and creating new resource ?


Terraform version :  v0.9.6

Your help is appreciated 

Regards
KV

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

kamalakar vadla

unread,
Jul 6, 2017, 11:20:38 AM7/6/17
to Terraform

Any update on this issue ?

Regards
KV
Reply all
Reply to author
Forward
0 new messages