Skip to content

Commit

Permalink
Make module idempotent by requiring subnet_id and ignore changes in s…
Browse files Browse the repository at this point in the history
…everal arguments (fixes terraform-aws-modules#10)
  • Loading branch information
antonbabenko committed Dec 8, 2017
1 parent 463116f commit 2cc71d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module "ec2" {
name = "example"
ami = "${data.aws_ami.amazon_linux.id}"
instance_type = "t2.micro"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
associate_public_ip_address = true
}
7 changes: 6 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ resource "aws_instance" "this" {
source_dest_check = "${var.source_dest_check}"
disable_api_termination = "${var.disable_api_termination}"
instance_initiated_shutdown_behavior = "${var.instance_initiated_shutdown_behavior}"
availability_zone = "${var.availability_zone}"
placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}"

# Note: network_interface can't be specified together with associate_public_ip_address
# network_interface = "${var.network_interface}"

tags = "${merge(var.tags, map("Name", format("%s-%d", var.name, count.index+1)))}"
lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments
ignore_changes = ["private_ip", "vpc_security_group_ids", "root_block_device"]
}
}
6 changes: 0 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ variable "ami" {
description = "ID of AMI to use for the instance"
}

variable "availability_zone" {
description = "The AZ to start the instance in"
default = ""
}

variable "placement_group" {
description = "The Placement Group to start the instance in"
default = ""
Expand Down Expand Up @@ -62,7 +57,6 @@ variable "vpc_security_group_ids" {

variable "subnet_id" {
description = "The VPC Subnet ID to launch in"
default = ""
}

variable "associate_public_ip_address" {
Expand Down

0 comments on commit 2cc71d6

Please sign in to comment.