lib/terraforming/resource/ec2.rb in terraforming-0.11.0 vs lib/terraforming/resource/ec2.rb in terraforming-0.12.0
- old
+ new
@@ -24,11 +24,11 @@
in_vpc = in_vpc?(instance)
block_devices = block_devices_of(instance)
attributes = {
"ami" => instance.image_id,
- "associate_public_ip_address" => "true",
+ "associate_public_ip_address" => associate_public_ip?(instance).to_s,
"availability_zone" => instance.placement.availability_zone,
"ebs_block_device.#" => ebs_block_devices_in(block_devices, instance).length.to_s,
"ebs_optimized" => instance.ebs_optimized.to_s,
"ephemeral_block_device.#" => "0", # Terraform 0.6.1 cannot fetch this field from AWS
"id" => instance.instance_id,
@@ -92,9 +92,13 @@
# https://github.com/hashicorp/terraform/blob/281e4d3e67f66daab9cdb1f7c8b6f602d949e5ee/builtin/providers/aws/resource_aws_instance.go#L481-L501
#
def in_vpc?(instance)
!vpc_security_groups_of(instance).empty? ||
(instance.subnet_id && instance.subnet_id != "" && instance.security_groups.empty?)
+ end
+
+ def associate_public_ip?(instance)
+ !instance.public_ip_address.to_s.empty?
end
def monitoring_state(instance)
%w(enabled pending).include?(instance.monitoring.state)
end