Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
(CLOUD-184, CLOUD-205) Avoid ambiguity when using the AWS_REGION envi…
Browse files Browse the repository at this point in the history
…ronment var
  • Loading branch information
Andy Henroid committed Jan 24, 2017
1 parent eb0d5a1 commit 4cc3c39
Show file tree
Hide file tree
Showing 36 changed files with 70 additions and 90 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/type/cloudwatch_alarm.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:cloudwatch_alarm) do
@doc = 'Type representing an AWS CloudWatch Alarm.'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/ec2_autoscalinggroup.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/region.rb'
require 'puppet/property/boolean'

Puppet::Type.newtype(:ec2_autoscalinggroup) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/ec2_elastic_ip.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_elastic_ip) do
@doc = "Type representing an Elastic IP and it's association."
Expand Down
7 changes: 2 additions & 5 deletions lib/puppet/type/ec2_instance.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_instance) do
@doc = 'Type representing an EC2 instance.'
Expand Down Expand Up @@ -93,12 +94,8 @@ def insync?(is)
end
end

newproperty(:region) do
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
desc 'The region in which to launch the instance.'
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should be a String' unless value.is_a?(String)
end
end

newproperty(:image_id) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/ec2_launchconfiguration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_launchconfiguration) do
@doc = 'Type representing an EC2 launch configuration.'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/ec2_scalingpolicy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_scalingpolicy) do
@doc = 'Type representing an EC2 scaling policy.'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_securitygroup.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'
require_relative '../../puppet_x/puppetlabs/aws_ingress_rules_parser'

Puppet::Type.newtype(:ec2_securitygroup) do
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_vpc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc) do
@doc = 'A type representing an AWS VPC.'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_vpc_customer_gateway.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc_customer_gateway) do
@doc = 'Type representing an AWS VPC customer gateways.'
Expand Down
8 changes: 2 additions & 6 deletions lib/puppet/type/ec2_vpc_dhcp_options.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc_dhcp_options) do
@doc = 'Type representing a DHCP option set for AWS VPC.'
Expand All @@ -20,10 +20,6 @@

newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
desc 'The region in which to assign the DHCP option set.'
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should be a String' unless value.is_a?(String)
end
end

newproperty(:domain_name, :array_matching => :all) do
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_vpc_internet_gateway.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc_internet_gateway) do
@doc = 'Type representing an EC2 VPC Internet Gateway.'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_vpc_routetable.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc_routetable) do
@doc = 'Type representing a VPC route table.'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_vpc_subnet.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc_subnet) do
@doc = 'Type representing a VPC Subnet.'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_vpc_vpn.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc_vpn) do
@doc = 'Type representing an AWS Virtual Private Networks.'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/ec2_vpc_vpn_gateway.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:ec2_vpc_vpn_gateway) do
@doc = 'A type representing a VPN gateway.'
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/elb_loadbalancer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/tag'
require_relative '../../puppet_x/puppetlabs/property/region'
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:elb_loadbalancer) do
@doc = 'Type representing an ELB load balancer.'
Expand Down
8 changes: 3 additions & 5 deletions lib/puppet/type/rds_db_parameter_group.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:rds_db_parameter_group) do
@doc = 'Type representing an RDS DB Parameter group.'

Expand All @@ -22,12 +24,8 @@
end
end

newproperty(:region) do
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
desc 'The region in which to create the db_parameter_group.'
validate do |value|
fail 'region should be a String' unless value.is_a?(String)
fail 'region should not contain spaces' if value =~ /\s/
end
end

end
8 changes: 3 additions & 5 deletions lib/puppet/type/rds_db_securitygroup.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:rds_db_securitygroup) do
@doc = 'Type representing an RDS instance.'

Expand Down Expand Up @@ -32,12 +34,8 @@
end
end

newproperty(:region) do
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
desc 'The region in which to create the db_securitygroup.'
validate do |value|
fail 'region should be a String' unless value.is_a?(String)
fail 'region should not contain spaces' if value =~ /\s/
end
end

newproperty(:ip_ranges, :array_matching => :all) do
Expand Down
8 changes: 3 additions & 5 deletions lib/puppet/type/rds_instance.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:rds_instance) do
@doc = 'Type representing an RDS instance.'

Expand Down Expand Up @@ -49,12 +51,8 @@
Not applicable. Must be null.'
end

newproperty(:region) do
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
desc 'The region in which to launch the instance.'
validate do |value|
fail 'region should be a String' unless value.is_a?(String)
fail 'region should not contain spaces' if value =~ /\s/
end
end

newproperty(:db_instance_class) do
Expand Down
9 changes: 3 additions & 6 deletions lib/puppet/type/sqs_queue.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative '../../puppet_x/puppetlabs/property/region.rb'

Puppet::Type.newtype(:sqs_queue) do
@doc = "Type representing a SQS Queue"
ensurable
Expand Down Expand Up @@ -43,13 +45,8 @@
munge(&:to_s)
end

newproperty(:region) do
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
desc 'The name of the region in which the SQS queue is located'
validate do |value|
fail 'region should be a String' unless value.is_a?(String)
fail 'You must provide a non-blank region name for SQS Queues' if value.nil? || value.empty?
fail 'The name of a region should contain only alphanumeric characters or dashes' unless value =~ /^([a-zA-Z]+-+)+\d$/
end
end

newproperty(:visibility_timeout) do
Expand Down
5 changes: 2 additions & 3 deletions lib/puppet_x/puppetlabs/property/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ module Property
class AwsRegion < Puppet::Property
validate do |value|
name = resource[:name]
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should not be blank' if value == ''
fail 'region should be a String' unless value.is_a?(String)
if !ENV['AWS_REGION'].nil? && ENV['AWS_REGION'] != value
fail 'region should be a valid AWS region' unless value =~ /^([a-z]{2}-[a-z]{4,}-\d)$/
if ENV['AWS_REGION'] && ENV['AWS_REGION'] != value
fail "if using AWS_REGION environment variable it must match the specified region value for #{name}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/provider/rds_instance/v2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Puppet::Type.type(:rds_instance).new(
ensure: 'present',
name: 'awesome-db-5',
region: 'us-west-1',
region: 'sa-east-1',
db_name: 'mysqldbname3',
engine: 'mysql',
engine_version: '5.6.19a',
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_elastic_ip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
it 'should require a region to be specified' do
expect {
type_class.new({ name: '10.0.0.1', region: '' })
}.to raise_error(Puppet::Error, /region should not be blank/)
}.to raise_error(Puppet::Error, /region should be a valid AWS region/)
end

it 'should require an instance to be specified' do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_securitygroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
it 'should require region to not contain spaces' do
expect {
type_class.new({name: 'name', region: 'invalid region'})
}.to raise_error(Puppet::Error, /region should not contain spaces/)
}.to raise_error(Puppet::Error, /region should be a valid AWS region/)
end

[
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_customer_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

it 'the ASN should be a number' do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_dhcp_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

['8.8.8.8','2.2.2.2'].each do |value|
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_internet_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

[
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_routetable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

it 'routes should contain a cidr' do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

it 'should order tags on output' do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_subnet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

[
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_vpn_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

it 'should default type to ipsec.1' do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/ec2_vpc_vpn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

[
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/rds_db_parameter_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
it 'should require a valid looking region' do
expect {
type_class.new({:name => 'sample', :region => 'definitely invalid'})
}.to raise_error(Puppet::Error, /region should not contain spaces/)
}.to raise_error(Puppet::Error, /region should be a valid AWS region/)
end

[
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/rds_db_securitygroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
it 'should require a valid looking region' do
expect {
type_class.new({:name => 'sample', :region => 'definitely invalid'})
}.to raise_error(Puppet::Error, /region should not contain spaces/)
}.to raise_error(Puppet::Error, /region should be a valid AWS region/)
end

[
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/rds_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
it 'region should not contain spaces' do
expect {
type_class.new(:name => 'sample', :region => 'sa east 1')
}.to raise_error(Puppet::ResourceError, /region should not contain spaces/)
}.to raise_error(Puppet::ResourceError, /region should be a valid AWS region/)
end

it 'IOPS must be an integer' do
Expand Down
Loading

0 comments on commit 4cc3c39

Please sign in to comment.