Skip to content
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

provider/aws: Add aws_availability_zones source #6805

Merged
merged 1 commit into from
May 24, 2016
Merged

Conversation

jen20
Copy link
Contributor

@jen20 jen20 commented May 20, 2016

This pull request adds a data source with a single list, available, in the schema. The list is populated with the availability zones to which an account has access within the region for which the AWS provider is configured. The list is sorted alphabetically so should remain in a predictable order.

conn := meta.(*AWSClient).ec2conn

log.Printf("[DEBUG] Reading availability zones")
d.SetId(time.Now().UTC().String())
Copy link
Contributor

Choose a reason for hiding this comment

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

why use the time as the Id? Is it just to set something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just the convention set by @apparentlymart. It's as good as anything else :-)

@stack72
Copy link
Contributor

stack72 commented May 20, 2016

Looks awesome! Cannot wait to use it :) I currently use this: https://github.com/terraform-community-modules/tf_aws_availability_zones

@stack72
Copy link
Contributor

stack72 commented May 23, 2016

@jen20 so, I'm REALLY impatient and I put this through some tests :)

data "aws_availability_zones" "zones" {}

output "azs" {
  value = "${data.aws_availability_zones.zones.available}"
}

I got the following:

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

azs = [
  us-west-2a
  us-west-2b
  us-west-2c
]

The only issue I currently see on this is on the destroy

data.aws_availability_zones.zones: Refreshing state...
data.aws_availability_zones.zones: Destroying...
Error applying plan:

1 error(s) occurred:

* data.aws_availability_zones.zones: unknown resource type: aws_availability_zones

@apparentlymart
Copy link
Contributor

In a moment of brief forgetfulness I re-implemented this as part of #6819... so if this gets merged first I'll go back and tear that out of there.

@stack72 that issue you're seeing with "unknown resource type" is one that @jen20 saw first and I saw over the weekend too, on many different data sources. It seems like a bug in the core handling of data sources during destroy, but I didn't track it down yet.

@jen20
Copy link
Contributor Author

jen20 commented May 24, 2016

I think we've decided on a "convention" of naming the list on singleton resources such as this instance. So it should read ${data.aws_availability_zones.instance}. I'll update the PR and merge this. I can't reproduce the core bug with all of @apparentlymart's patches applied, although I could reliably reproduce it previously, so I think we can consider this fixed unless we come up with a new repro (on a new issue!). I'll update this PR now to line up with the new convention.

This commit adds a data source with a single list, `instance` for the
schema which gets populated with the availability zones to which an
account has access.
@jen20 jen20 force-pushed the ds-availability-zone branch from e33812c to 1ea727e Compare May 24, 2016 20:43
@phinze
Copy link
Contributor

phinze commented May 24, 2016

Tested and it Just Works ™️ with multi-provider support:

provider "aws" {
  alias  = "east1"
  region = "us-east-1"
}

provider "aws" {
  alias  = "west2"
  region = "us-west-2"
}

data "aws_availability_zones" "east" {
  provider = "aws.east1"
}

data "aws_availability_zones" "west" {
  provider = "aws.west2"
}

output "east" {
  value = "${data.aws_availability_zones.east.instance}"
}

output "west" {
  value = "${data.aws_availability_zones.west.instance}"
}

zsh

COOL! 😍

LGTM

@jen20 jen20 merged commit e0d13f8 into master May 24, 2016
@jen20 jen20 deleted the ds-availability-zone branch May 24, 2016 21:12
@ghost
Copy link

ghost commented Apr 25, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants