-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
data-source/aws_region: Remove EC2 API call, default to current if no endpoint or name specified #3157
Conversation
… endpoint or name
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 a few nitpicky questions. I appreciate this is a first step of the refactoring and already very helpful (getting rid of extra API call), but generally I'd be probably even a bit more aggressive and deprecated current
.
It's no big deal though. We can do it in a separate PR.
website/docs/d/region.html.markdown
Outdated
@@ -35,12 +33,9 @@ exported as attributes. | |||
* `name` - (Optional) The full name of the region to select. | |||
|
|||
* `current` - (Optional) Set to `true` to match only the region configured | |||
in the provider. (It is not meaningful to set this to `false`.) | |||
in the provider. Defaults to `true` if `endpoint` or `name` is not given. |
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'm curious what is the value of current = true
still. 🤔 Can't we just assume it's always true in such conditions and deprecate the field?
@@ -51,4 +46,4 @@ The following attributes are exported: | |||
* `current` - `true` if the selected region is the one configured on the | |||
provider, or `false` otherwise. | |||
|
|||
* `endpoint` - The endpoint for the selected region. | |||
* `endpoint` - The EC2 endpoint for the selected region. |
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.
Thank you! 👍
aws/data_source_aws_region.go
Outdated
break | ||
} | ||
if current && (*matchingRegion).ID() != currentRegion { | ||
return fmt.Errorf("multiple regions matched; use additional constraints to reduce matches to a single region") |
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.
Is there any reason we can't just error out here regardless of current
?
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.
Ha, I think I was trying to make it so it could support current being false or something. I'm on board with deprecating the current
attribute completely (making it have no effect in the interim period) so this extra logic is moot and I'll remove it now.
aws/data_source_aws_region.go
Outdated
} | ||
if matchingRegion == nil { | ||
return fmt.Errorf("region not found for endpoint: %s", endpoint) | ||
} |
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 took me a while to understand what this block of code does. 😅 Would you mind extracting it into something like matchingRegion, err := findRegionByEndpoint(endpoint)
?
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.
That's a great idea! Let me implement that.
aws/data_source_aws_region.go
Outdated
} | ||
if matchingRegion == nil { | ||
return fmt.Errorf("region not found for name: %s", name) | ||
} |
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.
Likewise - how do you feel about extracting this into matchingRegion, err := findRegionByName(name)
?
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.
👍 👍
} | ||
|
||
region := resp.Regions[0] | ||
d.Set("endpoint", strings.TrimPrefix(regionEndpointEc2.URL, "https://")) |
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 out of curiosity: What is the reason for the trimming 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.
Previously, the EC2 API response was returning just the hostname (see example here: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRegions.html), however the SDK ResolvedEndpoint.URL
prepends https://
to the front. We weren't previously testing the old behavior, but the acceptance testing shows it doing the required trimming (I think).
…nd findRegionByName functions
@radeksimko refactored those two functions out, much cleaner. 😄
|
This has been released in terraform-provider-aws version 1.9.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
* commit '5293a0e3b1366ee16d8742b9b2354781a79bfbd9': (224 commits) v1.9.0 Update CHANGELOG for hashicorp#1101 and hashicorp#3283 docs/resource/aws_sns_platform_application: Add note about platform_credential and platform_principal hashing resource/aws_sns_platform_application: Refactor ID parsing to its own function, use testing.T in testAccAwsSnsPlatformApplicationPlatformFromEnv Add lambda example (hashicorp#3168) Update CHANGELOG for hashicorp#3157 docs/data-source/aws_region: Remove now deprecated current argument data-source/aws_region: Refactor logic into findRegionByEc2Endpoint and findRegionByName functions Update CHANGELOG for hashicorp#3301 Update CHANGELOG for hashicorp#2559 and hashicorp#3240 Update CHANGELOG.md resource/aws_kinesis_stream: Retry deletion on LimitExceededException (hashicorp#3108) Update CHANGELOG.md resource/aws_dynamodb_table_item: Cleanup + add missing bits Added dynamodb_table_item resource hashicorp#517 Update CHANGELOG.md New Resource: aws_cloud9_environment_ec2 Update CHANGELOG.md Fixed markdown typo in docs resource/aws_kinesis_firehose_delivery_stream: Prevent crashes on empty CloudWatchLoggingOptions and fix extended_s3_configuration kms_key_arn ... # Conflicts: # aws/validators.go
…parameters-features * commit '5293a0e3b1366ee16d8742b9b2354781a79bfbd9': (752 commits) v1.9.0 Update CHANGELOG for hashicorp#1101 and hashicorp#3283 docs/resource/aws_sns_platform_application: Add note about platform_credential and platform_principal hashing resource/aws_sns_platform_application: Refactor ID parsing to its own function, use testing.T in testAccAwsSnsPlatformApplicationPlatformFromEnv Add lambda example (hashicorp#3168) Update CHANGELOG for hashicorp#3157 docs/data-source/aws_region: Remove now deprecated current argument data-source/aws_region: Refactor logic into findRegionByEc2Endpoint and findRegionByName functions Update CHANGELOG for hashicorp#3301 Update CHANGELOG for hashicorp#2559 and hashicorp#3240 Update CHANGELOG.md resource/aws_kinesis_stream: Retry deletion on LimitExceededException (hashicorp#3108) Update CHANGELOG.md resource/aws_dynamodb_table_item: Cleanup + add missing bits Added dynamodb_table_item resource hashicorp#517 Update CHANGELOG.md New Resource: aws_cloud9_environment_ec2 Update CHANGELOG.md Fixed markdown typo in docs resource/aws_kinesis_firehose_delivery_stream: Prevent crashes on empty CloudWatchLoggingOptions and fix extended_s3_configuration kms_key_arn ... # Conflicts: # aws/resource_aws_ssm_parameter_test.go
removing current will fix the messages. Warning: module.platform.module.ecs.data.aws_region.current: "current": [DEPRECATED] Defaults to current provider region if no other filtering is enabled You can find more info at hashicorp/terraform-provider-aws#3157
removing current will fix the messages. Warning: module.platform.module.ecs.data.aws_region.current: "current": [DEPRECATED] Defaults to current provider region if no other filtering is enabled You can find more info at hashicorp/terraform-provider-aws#3157
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
This PR accomplishes a few things here:
ec2.DescribeRegions
API call. The SDK provides all regions and EC2 endpoint information already and this resource will automatically update when we update the SDK. The provider will not work in a new region without an updated release anyways.current
to match the documentation that listed it as optional, socurrent = true
is no longer necessary ifendpoint
andname
are omitted.