Skip to content

Commit 919073e

Browse files
committed
Avoid ambiguity when using the AWS_REGION environment var
If using the AWS_REGION environment variable and a manifest where the region property of one or more resources doesn't match you can see unspecified behaviour. See puppetlabs-toy-chest#117 for discussions. This PR extracted from the above simply stops that from happening. If the env is present and doesn't match All of the region properties then we fail. This maintains the utility of the env var as an optimisation but stops us shooting ourselves in the foot.
1 parent fa0982b commit 919073e

17 files changed

+63
-88
lines changed

lib/puppet/type/cloudwatch_alarm.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative '../../puppet_x/puppetlabs/property/region'
2+
13
Puppet::Type.newtype(:cloudwatch_alarm) do
24
@doc = 'Type representing an AWS CloudWatch Alarm.'
35

@@ -73,13 +75,8 @@
7375
end
7476
end
7577

76-
newproperty(:region) do
78+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
7779
desc 'The region in which to launch the instances.'
78-
validate do |value|
79-
fail 'region should not contain spaces' if value =~ /\s/
80-
fail 'region should not be blank' if value == ''
81-
fail 'region should be a String' unless value.is_a?(String)
82-
end
8380
end
8481

8582
newproperty(:dimensions, :array_matching => :all) do

lib/puppet/type/ec2_autoscalinggroup.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative '../../puppet_x/puppetlabs/property/region'
2+
13
Puppet::Type.newtype(:ec2_autoscalinggroup) do
24
@doc = 'Type representing an EC2 auto scaling group.'
35

@@ -31,13 +33,8 @@
3133
end
3234
end
3335

34-
newproperty(:region) do
36+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
3537
desc 'The region in which to launch the instances.'
36-
validate do |value|
37-
fail 'region should not contain spaces' if value =~ /\s/
38-
fail 'region should not be blank' if value == ''
39-
fail 'region should be a String' unless value.is_a?(String)
40-
end
4138
end
4239

4340
newproperty(:launch_configuration) do

lib/puppet/type/ec2_elastic_ip.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative '../../puppet_x/puppetlabs/property/region'
2+
13
Puppet::Type.newtype(:ec2_elastic_ip) do
24
@doc = "Type representing an Elastic IP and it's association."
35

@@ -19,12 +21,8 @@
1921
end
2022
end
2123

22-
newproperty(:region) do
24+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
2325
desc 'The name of the region in which the Elastic IP is found.'
24-
validate do |value|
25-
fail 'region should be a String' unless value.is_a?(String)
26-
fail 'You must provide a region for Elastic IPs.' if value.nil? || value.empty?
27-
end
2826
end
2927

3028
newproperty(:instance) do

lib/puppet/type/ec2_launchconfiguration.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative '../../puppet_x/puppetlabs/property/region'
2+
13
Puppet::Type.newtype(:ec2_launchconfiguration) do
24
@doc = 'Type representing an EC2 launch configuration.'
35

@@ -33,13 +35,8 @@ def insync?(is)
3335
end
3436
end
3537

36-
newproperty(:region) do
38+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
3739
desc 'The region in which to launch the instances.'
38-
validate do |value|
39-
fail 'region should not contain spaces' if value =~ /\s/
40-
fail 'region should not be blank' if value == ''
41-
fail 'region should be a String' unless value.is_a?(String)
42-
end
4340
end
4441

4542
newproperty(:instance_type) do

lib/puppet/type/ec2_scalingpolicy.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative '../../puppet_x/puppetlabs/property/region'
2+
13
Puppet::Type.newtype(:ec2_scalingpolicy) do
24
@doc = 'Type representing an EC2 scaling policy.'
35

@@ -21,13 +23,8 @@
2123
end
2224
end
2325

24-
newproperty(:region) do
26+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
2527
desc 'The region in which to launch the policy.'
26-
validate do |value|
27-
fail 'region should not contain spaces' if value =~ /\s/
28-
fail 'region should not be blank' if value == ''
29-
fail 'region should be a String' unless value.is_a?(String)
30-
end
3128
end
3229

3330
newproperty(:adjustment_type) do

lib/puppet/type/ec2_securitygroup.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
1+
require_relative '../../puppet_x/puppetlabs/property/tag'
2+
require_relative '../../puppet_x/puppetlabs/property/region'
23
require_relative '../../puppet_x/puppetlabs/aws_ingress_rules_parser'
34

45
Puppet::Type.newtype(:ec2_securitygroup) do
@@ -14,12 +15,8 @@
1415
end
1516
end
1617

17-
newproperty(:region) do
18+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
1819
desc 'the region in which to launch the security group'
19-
validate do |value|
20-
fail 'region should not contain spaces' if value =~ /\s/
21-
fail 'region should be a String' unless value.is_a?(String)
22-
end
2320
end
2421

2522
newproperty(:ingress, :array_matching => :all) do

lib/puppet/type/ec2_vpc.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
1+
require_relative '../../puppet_x/puppetlabs/property/tag'
2+
require_relative '../../puppet_x/puppetlabs/property/region'
23

34
Puppet::Type.newtype(:ec2_vpc) do
45
@doc = 'A type representing an AWS VPC.'
@@ -13,12 +14,8 @@
1314
end
1415
end
1516

16-
newproperty(:region) do
17+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
1718
desc 'The region in which to launch the VPC.'
18-
validate do |value|
19-
fail 'region should not contain spaces' if value =~ /\s/
20-
fail 'region should be a String' unless value.is_a?(String)
21-
end
2219
end
2320

2421
newproperty(:cidr_block) do

lib/puppet/type/ec2_vpc_customer_gateway.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
1+
require_relative '../../puppet_x/puppetlabs/property/tag'
2+
require_relative '../../puppet_x/puppetlabs/property/region'
23

34
Puppet::Type.newtype(:ec2_vpc_customer_gateway) do
45
@doc = 'Type representing an AWS VPC customer gateways.'
@@ -31,12 +32,8 @@
3132
desc 'The tags for the customer gateway.'
3233
end
3334

34-
newproperty(:region) do
35+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
3536
desc 'The region in which to launch the customer gateway.'
36-
validate do |value|
37-
fail 'region should not contain spaces' if value =~ /\s/
38-
fail 'region should be a String' unless value.is_a?(String)
39-
end
4037
end
4138

4239
newproperty(:type) do

lib/puppet/type/ec2_vpc_dhcp_options.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
1+
require_relative '../../puppet_x/puppetlabs/property/tag'
2+
require_relative '../../puppet_x/puppetlabs/property/region'
23

34
Puppet::Type.newtype(:ec2_vpc_dhcp_options) do
45
@doc = 'Type representing a DHCP option set for AWS VPC.'
@@ -17,7 +18,7 @@
1718
desc 'Tags for the DHCP option set.'
1819
end
1920

20-
newproperty(:region) do
21+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
2122
desc 'The region in which to assign the DHCP option set.'
2223
validate do |value|
2324
fail 'region should not contain spaces' if value =~ /\s/

lib/puppet/type/ec2_vpc_internet_gateway.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require_relative '../../puppet_x/puppetlabs/property/tag.rb'
1+
require_relative '../../puppet_x/puppetlabs/property/tag'
2+
require_relative '../../puppet_x/puppetlabs/property/region'
23

34
Puppet::Type.newtype(:ec2_vpc_internet_gateway) do
45
@doc = 'Type representing an EC2 VPC Internet Gateway.'
@@ -17,12 +18,8 @@
1718
desc 'Tags to assign to the internet gateway.'
1819
end
1920

20-
newproperty(:region) do
21+
newproperty(:region, :parent => PuppetX::Property::AwsRegion) do
2122
desc 'The region in which to launch the internet gateway.'
22-
validate do |value|
23-
fail 'region should not contain spaces' if value =~ /\s/
24-
fail 'region should be a String' unless value.is_a?(String)
25-
end
2623
end
2724

2825
newproperty(:vpc) do

0 commit comments

Comments
 (0)