This repository has been archived by the owner on Jun 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
(WIP)(CLOUD-184, CLOUD-205) Make the region param and ENV var interchangable #117
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,12 @@ def self.tags_for(item) | |
tags | ||
end | ||
|
||
def target_region | ||
target = resource ? resource[:region] || region : region | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. region in this context is the value of the region property. This basically says:
|
||
target = nil if target == :absent | ||
target || ENV['AWS_REGION'] | ||
end | ||
|
||
def tags=(value) | ||
Puppet.info("Updating tags for #{name} in region #{region}") | ||
ec2 = ec2_client(resource[:region]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module PuppetX | ||
module Property | ||
class AwsRegion < Puppet::Property | ||
validate do |value| | ||
name = resource[:name] | ||
fail "region for #{name} should not contains spaces" if value =~ /\s/ | ||
if !ENV['AWS_REGION'].nil? && ENV['AWS_REGION'] != value | ||
fail "if using AWS_REGION environment variable it must match the specified region value for #{name}" | ||
end | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually fairly tricky, and I'm not sure that this is the right approach.
Assume that:
foo
inus-east-1
andus-west-1
.foo
sg resource with:region => 'us-west-1'
AWS_REGION=us-east-1
It's now possible that even though the manifest wants to modify the resource in
us-west-1
, that Puppet will attach to and modify the resource inus-east-1
based on the order in which the regions were queried.This may seem like an unlikely / synthesized problem, but it makes me really wary of doing something like this. I'm not sure there's a reasonable way around this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of having two mechanisms that perform the same action. Seems like it would get dirty very fast. Which one would take president?
Here is a real world example of modifying multiple resources with the same name in different regions. @mrzarquon mentioned that he wants to create identical VPCs in three different regions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the two methods of passing region, this mirrors most of the AWS tools which will use the explicitly passed region OR fall back to the value of the Environment variable. It allows for some interesting reuse and in practice is less confusing that in theory in my experience. We should decide on whether we want to follow that convention, and if so agree we should better specify this behaviour and provide examples.
The linked example will only work if you have one puppet run per region, due to the requirement for unique resources in the graph. In the future we should definitely investigate other approaches here, including composite namevars ala #124. A current pattern is to use the region var to make unique composite names. ie. {region}-{name}.