-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add state filter to aws_availability_zones data source. #7965
Add state filter to aws_availability_zones data source. #7965
Conversation
This commit adds an ability to filter Availability Zones based on state, where by default it would only list available zones. Be advised that this does not always works reliably for an older accounts which have been created in the pre-VPC era of EC2. These accounts tends to retrieve availability zones that are not VPC-enabled, thus creation of a custom subnet within such Availability Zone would result in a failure. Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Resolves #7959. |
Test is passing:
|
The debug output confirms that state is set:
|
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
@stack72 over to you 🚀 |
"state": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "available", |
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 think setting this default would make it impossible to retrieve an unfiltered list, and is a backward-compatibility break.
Could we instead default to no filter, and have the user explicitly set state = "available"
to get the filtered list? This does make the user do a little more work, but has the advantage of being consistent with how some of our other data sources are working (each new attribute acts as an additional filter constraint) and makes things a little more explicit.
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.
@apparentlymart makes sense! I will push an update shortly.
This commit makes the state filter applicable only when set. Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Test is passing:
|
@stack72 @apparentlymart over to you 🚀 |
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `names` - A list of the availability zone names available to the account. | ||
* `names` - A list of the Availability Zone names available to the account. |
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.
It's a little weird to capitalize non-proper nouns in English... what was the motivation for this change here?
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.
Just to reflect what AWS does in their documentation, which might not be correct convention (since I am not an English language native speaker, etc., I have assumed that their style is somewhat acceptable). For example, as per: Regions and Availability Zones.
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.
Hmm interesting... I'd not noticed that before. I think we've generally treated "availability zones" as a general noun rather than a proper noun elsewhere in our docs, so it might be a bit late for us to switch to the AWS docs style now without a lot of updates on other doc pages. Not a big deal though, certainly.
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.
Sorry for causing troubles!
In terms of consistency in documentation we have, it does vary:
(not a very scientific comparison, though)
krzysztof@apple ~/Development/Projects/Go/src/github.com/hashicorp/terraform (master %)$ ack --no-smart-case availability website/source/ -l | wc -l
45
krzysztof@apple ~/Development/Projects/Go/src/github.com/hashicorp/terraform (master %)$ ack --no-smart-case Availability website/source/ -l | wc -l
11
Would you like me to revert this back?
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.
@apparentlymart we can merge this one for now and then follow up on the docs later :)
|
With 0.7.5, I tried using the following, hoping to use the second AZ in the us-west-1 region in a subnet:
It tried to insert "us-west-1b" (index 1), which isn't available. Did I do this incorrectly or is this fix not available in the version I'm using? |
@cmusser hi there! I am sorry that you are having issues! Let me have a look what is going on here. |
@cmusser hi there again! I have had a look, and for example, for my account Terraform returns the right set of results:
Which is consistent with the AWSCLI output for the given (same) set of credentials. Basically, this is all my IAM user sees in terms of what my account has an access to. Also, Is there something I am missing? I am not sure if I got the gist of the problem right. |
There is something funny going on, perhaps with AWS itself. I see the same thing you did with AWS CLI: 1b appears available. So it's reasonable that Terraform places it in the list. The specific error when creating the subnet with the list of available AZs is:
Maybe its somehow possible for them to return a zone as available, when it really isn't for subnets. |
@cmusser the Availability Zones are very elusive. From the AWS documentation (excerpt):
See: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html I have to accounts and both have different availability zones reported. The issue with subnets is quite a common one. Sadly, there is no reliable way to detect this (or at least I am not familiar with a possible solution and/or workaround), especially as there is no API from Amazon which would provide such details e.g. which Availability Zones are VPC-enabled and allow subnets creation, etc. Related reading material:
I am sorry that I have no better solution for you yet. We could, in theory, have a "VPC subnet probe" which would make an attempt to create a VPC then create a subnet in each of the Availability Zones, and catch failure/success in turn assembling a list of ones which support subnets creation. But this would be rather slow. |
Hitting the same thing, and I am afraid the VPC subnet probe is the only way to actually determine if an AZ is available. Is there a Github issue for this? |
@pmoust hi there! I agree. And it is rather annoying to stumble into. I proposed the VPC probe, but was seen as not necessarily the right thing to do (albeit, there isn't any other that works 100% successfully), and I can see why as it would require to attempt to provision a VPC with a subnet which might not necessarily be the best thing to do e.g. can be affected by account limits, etc. What do you think, @stack72 and @radeksimko? |
@kwilczynski I have contacted AWS via our TAMs, and can confirm there is no other sane way at the moment. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This commit adds an ability to filter Availability Zones based on state.
Be advised that this does not always works reliably for an older accounts which
have been created in the pre-VPC era of EC2. These accounts tends to retrieve
availability zones that are not VPC-enabled, thus creation of a custom subnet
within such Availability Zone would result in a failure.
Signed-off-by: Krzysztof Wilczynski krzysztof.wilczynski@linux.com