Skip to content
This repository was archived by the owner on Jun 5, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ Specifies that basic state of the resource. Valid values are 'attached', 'detach
#####`vpc`
*Optional* A hint to specify the VPC. This is useful when detecting ambiguously named security groups that might exist in different VPCs, such as 'default'. This parameter is set at creation only; it is not affected by updates.

#####`associate_public_ip_address`
*Optional* One or more mappings that specify how block devices are exposed to the instance. For more information, see [Block Device Mapping](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html) in the Amazon Elastic Compute Cloud User Guide. This parameter is set at creation only; it is not affected by updates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs describe block devices; is that copy/paste?


#### Type: ec2_scalingpolicy

#####`name`
Expand Down
5 changes: 4 additions & 1 deletion lib/puppet/provider/ec2_launchconfiguration/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def self.prefetch(resources)
def self.config_to_hash(region, config)
# It appears possible to get launch configurations manually to a state where
# they return the identifier of an invalid or a non-existent security groups
# puts "config_to_hash(#{config})"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd indentation.

security_group_names = begin
group_response = ec2_client(region).describe_security_groups(group_ids: config.security_groups)
group_response.data.security_groups.collect(&:group_name)
Expand All @@ -49,7 +50,8 @@ def self.config_to_hash(region, config)
image_id: config.image_id,
key_name: config.key_name,
ensure: :present,
region: region
region: region,
associate_public_ip_address: config.associate_public_ip_address,
}
end

Expand Down Expand Up @@ -89,6 +91,7 @@ def create
security_groups: group_ids,
instance_type: resource[:instance_type],
user_data: data,
associate_public_ip_address: resource[:associate_public_ip_address],
}

key = resource[:key_name] ? resource[:key_name] : false
Expand Down
21 changes: 21 additions & 0 deletions lib/puppet/type/ec2_launchconfiguration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'puppet/property/boolean'

Puppet::Type.newtype(:ec2_launchconfiguration) do
@doc = 'Type representing an EC2 launch configuration.'

Expand Down Expand Up @@ -67,6 +69,19 @@ def insync?(is)
end
end

newproperty(:associate_public_ip_address, :boolean => true, :parent => Puppet::Property::Boolean) do
desc 'Specifies whether to assign a public IP address to each instance launched in a Amazon VPC. If the instance is launched into a default subnet, the default is true.'
defaultto :true
newvalues(:true, :false)
def insync?(is)
is.to_s == should.to_s
end

def set(value)
read_only_warning(value, self, should)
end
end

autorequire(:ec2_securitygroup) do
groups = self[:security_groups]
groups.is_a?(Array) ? groups : [groups]
Expand All @@ -77,3 +92,9 @@ def insync?(is)
end

end
def read_only_warning(value, property, should)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module already has the ability for marking properties read-only; why this addition?

msg = "#{property.name} is read-only. Cannot set to: #{should}"
Puppet.warning msg
#raise Puppet::Error, msg
false
end
1 change: 1 addition & 0 deletions spec/unit/provider/ec2_launchconfig/v2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
instance_type: 't1.micro',
region: 'sa-east-1',
security_groups: ['test-sg'],
associate_public_ip_address: false,
)
}

Expand Down
11 changes: 11 additions & 0 deletions spec/unit/type/ec2_launchconfiguration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def launchconfig_config
instance_type: 't1.micro',
region: 'sa-east-1',
security_groups: ['test-sg'],
associate_public_ip_address: false,
}
end

Expand All @@ -30,6 +31,7 @@ def launchconfig_config
:instance_type,
:image_id,
:key_name,
:associate_public_ip_address,
]
end

Expand Down Expand Up @@ -81,4 +83,13 @@ def launchconfig_config
end
end

context 'with a full set of properties' do
before :all do
@instance = type_class.new(launchconfig_config)
end

it "should convert associate_public_ip_address to a boolean" do
expect(@instance[:associate_public_ip_address].kind_of?(TrueClass) || @instance[:associate_public_ip_address].kind_of?(FalseClass)).to be true
end
end
end