-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
d/aws_dx_connection: Adding new data source for Direct Connect connection #9705
Conversation
aws/data_source_aws_dx_connection.go
Outdated
Read: dataSourceAwsDxConnectionRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"id": { |
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.
No need to define an explicit id
attribute here.
aws/data_source_aws_dx_connection.go
Outdated
Computed: true, | ||
}, | ||
"jumbo_frame_capable": { | ||
Type: schema.TypeString, |
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.
schema.TypeBool
to match aws_dx_connection
resource?
aws/data_source_aws_dx_connection.go
Outdated
connection := connections[0] | ||
|
||
d.SetId(aws.StringValue(connection.ConnectionId)) | ||
d.Set("state", aws.StringValue(connection.ConnectionState)) |
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.
No need to use aws.StringValue()
for attributes set with d.Set
. Pointer dereferencing is dome automatically.
e.g. d.Set("state", connection.ConnectionState)
.
aws/data_source_aws_dx_connection.go
Outdated
d.Set("state", aws.StringValue(connection.ConnectionState)) | ||
d.Set("location", aws.StringValue(connection.Location)) | ||
d.Set("bandwidth", aws.StringValue(connection.Bandwidth)) | ||
d.Set("jumbo_frame_capable", strconv.FormatBool(aws.BoolValue(connection.JumboFrameCapable))) |
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.
If jumbo_frame_capable
is schema.TypeBool
then we can just do
d.Set("jumbo_frame_capable", connection.JumboFrameCapable)
) | ||
|
||
func TestAccDataSourceAwsDxConnection_Basic(t *testing.T) { | ||
key := "DX_LOCATION" |
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. The acceptance tests for the corresponding hard-code the location to EqSe2
, assuming that the AWS region is us-west-2
. It's good to challenge that assumption.
Maybe call DescribeLocations
for the current test region and pick one at random rather than requiring an environment variable be set?
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.
Added #9708 to track adding new data sources to make this easier.
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, |
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.
Please add "tags": tagsSchemaComputed()
(and query for tags) as DX Connection now support resource tags.
Maybe set an "arn"
attribute as well?
Hi @ewbankkit thanks for the feedback. I've updated the PR with your suggestions. #9705 (comment) I've added tags as an optional attribute & included a test too. Passing test output below. === CONT TestAccDataSourceAwsDxConnection_Basic |
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccDataSourceAwsDxConnection_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -parallel 20 -run=TestAccDataSourceAwsDxConnection_ -timeout 120m
=== RUN TestAccDataSourceAwsDxConnection_Basic
2019/08/12 09:48:11 [INFO] Building AWS auth structure
2019/08/12 09:48:11 [INFO] Setting AWS metadata API timeout to 100ms
2019/08/12 09:48:16 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2019/08/12 09:48:16 [INFO] AWS Auth provider used: "EnvProvider"
2019/08/12 09:48:16 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2019/08/12 09:48:16 [DEBUG] Trying to get account information via sts:GetCallerIdentity
Testing Connections in DX Location: SNAP=== PAUSE TestAccDataSourceAwsDxConnection_Basic
=== RUN TestAccDataSourceAwsDxConnection_tags
2019/08/12 09:48:17 [INFO] Building AWS auth structure
2019/08/12 09:48:17 [INFO] Setting AWS metadata API timeout to 100ms
2019/08/12 09:48:23 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2019/08/12 09:48:23 [INFO] AWS Auth provider used: "EnvProvider"
2019/08/12 09:48:23 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2019/08/12 09:48:23 [DEBUG] Trying to get account information via sts:GetCallerIdentity
Testing Connections in DX Location: ECPO1=== PAUSE TestAccDataSourceAwsDxConnection_tags
=== CONT TestAccDataSourceAwsDxConnection_Basic
=== CONT TestAccDataSourceAwsDxConnection_tags
--- PASS: TestAccDataSourceAwsDxConnection_tags (43.91s)
--- PASS: TestAccDataSourceAwsDxConnection_Basic (45.00s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 51.398s |
func testAccAwsDxConnectionLocation() (*string, error) { | ||
var region string | ||
|
||
if _, ok := os.LookupEnv("AWS_DEFAULT_REGION"); ok { |
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.
You could use testAccGetRegion()
here (which is the same logic).
I'll try and get #9708 done today but that shouldn't hold up a review of this PR - I can refactor the acceptance tests for this data source and the corresponding resource depending on the merge order. |
I'm getting a dependency error with this as-is:
With a merge from master a different error:
|
I've rebased this against an up-to-date master and made a few fixes in https://github.com/beezly/terraform-provider-aws/tree/rh007_against_master. It passed the acceptance test when I ran it:
|
Having had a try at using this data source, I think it needs a little bit of tweaking. At the moment the only way to identify a dx_connection is using the |
OK - I've done some more work on this and reworked it to use the connection ID to find the dx connection resource. As my code is now diverging from the original quite significantly, I've created a new branch at https://github.com/beezly/terraform-provider-aws/tree/use_connection_id_for_dx_connection with this work in. Acceptance tests currently pass:
At the moment, my code doesn't support filtering by Tags or by Name, which the original code does attempt to do. However, AWS don't provide an API for filtering on Connections at all as My gut feeling is that the simple basic functionality of searching by Id should be working first and then more extended functionality (filtering on Name/Tags) could be added on top. @ewbankkit do you have any opinions? |
@beezly Agree with keeping things simple to start with, maybe just |
@ewbankkit thanks - I've got that working on the use_connection_id_for_dx_connection I mentioned above. I've also added some attributes that the In my particular use-case, the reason I need the |
Hi @beezly I based the original code from the aws_dx_gateway implementation to use a name which I felt was easier to use rather than an ID. We don't have hosted DX connections so the workflow worked fine because we named the original connections. This was also my first data source I wrote I think & it's been a while since the original commit. Let me know if you want me to do anything. |
@robh007 thanks for getting in touch! Your code has been a great place for me to get going with what we needed on my current project. I'm really grateful I didn't have to start from scratch! I've been doing a bit more work on my branch and added support for searching by You do raise a really good point. I think the @ewbankkit / @bflad - what do you think? Should there be a single |
@beezly @ewbankkit is there anything outstanding on this PR that I could help out with? I could really do with this data source to help look up connections by name |
Notification of Recent and Upcoming Changes to ContributionsThank you for this contribution! There have been a few recent development changes that affect this pull request. We apologize for the inconvenience, especially if there have been long review delays up until now. Please note that this is automated message from an unmonitored account. See the FAQ for additional information on the maintainer team and review prioritization. If you are unable to complete these updates, please leave a comment for the community and maintainers so someone can potentially continue the work. The maintainers will encourage other contributors to use the existing contribution as the base for additional changes as appropriate. Otherwise, contributions that do not receive updated code or comments from the original contributor may be closed in the future so the maintainers can focus on active items. For the most up to date information about Terraform AWS Provider development, see the Contributing Guide. Additional technical debt changes can be tracked with the As part of updating a pull request with these changes, the most current unit testing and linting will run. These may report issues that were not previously reported. Action Required: Terraform 0.12 SyntaxReference: #8950 Version 3 and later of the Terraform AWS Provider, which all existing contributions would potentially be added, only supports Terraform 0.12 and later. Certain syntax elements of Terraform 0.11 and earlier show deprecation warnings during runs with Terraform 0.12. Documentation and test configurations, such as those including deprecated string interpolations ( Action Required: Terraform Plugin SDK Version 2Reference: #14551 The Terraform AWS Provider has been upgraded to the latest version of the Terraform Plugin SDK. Generally, most changes to contributions should only involve updating Go import paths in source code files. Please see the referenced issue for additional information. Action Required: Removal of website/aws.erb FileReference: #14712 Any changes to the Upcoming Change of Git Branch NamingReference: #14292 Development environments will need their upstream Git branch updated from Upcoming Change of GitHub OrganizationReference: #14715 This repository will be migrating from https://github.com/terraform-providers/terraform-provider-aws to https://github.com/hashicorp/terraform-provider-aws. No practitioner or developer action is anticipated and most GitHub functionality will automatically redirect to the new location. Go import paths including |
@ewbankkit - yeah whatever's easier. I'd just like to see the additional attributes added to that PR as you've mentioned. |
Closing in favor of #17852. |
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! |
Community Note
Changes proposed in this pull request:
Adds a new data resource for DX connections:
aws_dx_connection
Lookup DX connections from a name.
example
Output from acceptance testing: