-
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
add new data source aws_api_gateway_rest_api #4172
Conversation
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.
Hi @timborrowdale 👋 Thanks for this contribution. I left some initial comments below. Can you please take a look and let me know if you have any questions?
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"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.
id
does not need to be declared as a schema attribute 👍
matchedApis = append(matchedApis, api) | ||
} | ||
} | ||
return 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.
Should use return !lastPage
here
log.Printf("[DEBUG] Reading API Gateway REST APIs: %s", params) | ||
err := conn.GetRestApisPages(params, func(page *apigateway.GetRestApisOutput, lastPage bool) bool { | ||
for _, api := range page.Items { | ||
if *api.Name == target { |
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.
To prevent a potential crash, we should wrap this with aws.StringValue(api.Name)
in the unlikely scenario that its returned as nil
return true | ||
}) | ||
if err != nil { | ||
return errwrap.Wrapf("error describing API Gateway REST APIs: {{err}}", err) |
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.
We do not need the context of the error when returning a message back to the user here. We can use the simpler fmt.Errorf("error describing API Gateway REST APIs: %s", err)
here 👍
|
||
d.SetId(*match.Id) | ||
|
||
if err = dataSourceAwsApiGatewayRestApiRefreshResources(d, meta); err != nil { |
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.
We do not need the extra function here, its contents can be included in the read function 👍
} | ||
|
||
const testAccDataSourceAwsApiGatewayRestApiConfig = ` | ||
provider "aws" { |
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.
We do not need to declare the provider
block in the testing framework, it defaults to us-west-2
if not provided via AWS_DEFAULT_REGION
} | ||
|
||
resource "aws_api_gateway_rest_api" "tf_test" { | ||
name = "tf_test" |
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.
These should have randomized names to prevent hitting the multiple match error condition after test panics/AWS failures. Usually we achieve this by wrapping the test configuration in fmt.Sprintf()
and passing a randomized name from the test function, e.g. rName := acctest.StringWithPrefix("tf_acc_test_")
@bflad Thanks for the feedback - I've had a go at addressing those issues. |
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.
Awesome job, LGTM! 🚀
1 test passed (all tests)
=== RUN TestAccDataSourceAwsApiGatewayRestApi
--- PASS: TestAccDataSourceAwsApiGatewayRestApi (8.06s)
This has been released in version 1.15.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
#4146
I've had issues trying to get the terraform-website project working to check the docs locally - I think they're ok but would be good if someone could check.