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

New Resource: aws_api_gateway_documentation_part #2893

Merged
merged 2 commits into from
Jan 11, 2018

Conversation

radeksimko
Copy link
Member

Test results

$ make testacc TESTARGS='-run=TestAccAWSAPIGatewayDocumentationPart_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccAWSAPIGatewayDocumentationPart_ -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSAPIGatewayDocumentationPart_basic
--- PASS: TestAccAWSAPIGatewayDocumentationPart_basic (107.73s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_method
--- PASS: TestAccAWSAPIGatewayDocumentationPart_method (60.31s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_responseHeader
--- PASS: TestAccAWSAPIGatewayDocumentationPart_responseHeader (61.64s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	229.724s

@radeksimko radeksimko added the new-resource Introduces a new resource. label Jan 8, 2018
@bflad bflad self-assigned this Jan 10, 2018
RestApiId: aws.String(d.Get("rest_api_id").(string)),
})
if err != nil {
if isAWSErr(err, "NotFoundException", "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Constant is available for this exception: apigateway.ErrCodeNotFoundException

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

This is getting there! Only must fix items are related to adding an import test and fixing the documentation for that functionality (which may or may not require adjustment of the resource ID).

Passes acceptance testing in its current form for me:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSAPIGatewayDocumentationPart'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAPIGatewayDocumentationPart -timeout 120m
=== RUN   TestAccAWSAPIGatewayDocumentationPart_basic
--- PASS: TestAccAWSAPIGatewayDocumentationPart_basic (25.19s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_method
--- PASS: TestAccAWSAPIGatewayDocumentationPart_method (41.56s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_responseHeader
--- PASS: TestAccAWSAPIGatewayDocumentationPart_responseHeader (24.67s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	91.477s

resource.TestStep{
Config: testAccAWSAPIGatewayDocumentationPartConfig(apiName, properties),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayDocumentationPartExists("aws_api_gateway_documentation_part.test", &conf),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick (personal): I've been finding it helpful to declare the resource names as a top level variable in the function so its easier to duplicate code across functions/resources. e.g. resourceName := "aws_api_gateway_documentation_part.test" - personal opinion though!

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm ok with that, sounds reasonable, the only thing is that the majority of the tests we have in the codebase now doesn't follow this, so we might want to revisit the existing code, so other folks copy-pasting code know what's "preferred".

var conf apigateway.DocumentationPart

rString := acctest.RandString(8)
apiName := fmt.Sprintf("tf_acc_api_%s", rString)
Copy link
Contributor

Choose a reason for hiding this comment

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

Generic question: should we try to include the test name (e.g. t.Name()) instead of the fairly diverse naming we have across resources for acceptance tests? I'm guessing it really depends on naming restrictions for some resources (max length, no underscores, etc).

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree we should make it test-specific, but t.Name() is a bit tricky for the reasons you mentioned, so I'll come up with custom, static name.

Delete: resourceAwsApiGatewayDocumentationPartDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Copy link
Contributor

Choose a reason for hiding this comment

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

Must fix: missing acceptance test for import functionality

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Will add.

if err != nil {
return err
}
d.SetId(*out.Id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the documentation part ID need to be combined with the REST API ID to support import? e.g. fmt.Sprintf("%s:%s", d.Get("rest_api_id").(string), *.out.Id) and requisite idParts := strings.Split(d.Id(), ":")

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, good catch, I'll pick / as the divider though. It seems safer, given that both IDs are then used in a URL, divided by that character.


#### `location`

* `method` - (Optional) The HTTP verb of a method. It is a valid field for the API entity types of `METHOD`, `PATH_PARAMETER`, `QUERY_PARAMETER`, `REQUEST_HEADER`, `REQUEST_BODY`, `RESPONSE`, `RESPONSE_HEADER`, and `RESPONSE_BODY`. The default value is `*` for any method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we refer to the API Gateway documentation for this attribute and the ones below instead of listing these out?


## Import

API Gateway documentation_parts can be imported using the word `api-gateway-documentation_part`, e.g.
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be updated for (REST API ID and )documentation part ID depending on outcome of ID value

return err
}

return fmt.Errorf("API Gateway Documentation Part %s/%s still exists.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be updated based on ID discussion (or at least made a little clear what the second ID is). 😄

}
_, err := conn.GetDocumentationPart(req)
if err != nil {
if isAWSErr(err, "NotFoundException", "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note about apigateway.ErrCodeNotFoundException constant

testAccCheckAWSAPIGatewayDocumentationPartExists("aws_api_gateway_documentation_part.test", &conf),
resource.TestCheckResourceAttr("aws_api_gateway_documentation_part.test", "location.#", "1"),
resource.TestCheckResourceAttr("aws_api_gateway_documentation_part.test", "location.0.type", "API"),
resource.TestCheckResourceAttr("aws_api_gateway_documentation_part.test", "properties", `{"description":"Terraform Acceptance Test"}`),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this use strconv.Unquote(properties) instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point in principle, I will use strconv.Quote().

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jan 10, 2018
@radeksimko
Copy link
Member Author

@bflad I just addressed all of your comments. PTAL.

=== RUN   TestAccAWSAPIGatewayDocumentationPart_basic
--- PASS: TestAccAWSAPIGatewayDocumentationPart_basic (107.81s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_method
--- PASS: TestAccAWSAPIGatewayDocumentationPart_method (113.47s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_responseHeader
--- PASS: TestAccAWSAPIGatewayDocumentationPart_responseHeader (116.51s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_importBasic
--- PASS: TestAccAWSAPIGatewayDocumentationPart_importBasic (70.33s)

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Jan 10, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes.

make testacc TEST=./aws TESTARGS='-run=TestAccAWSAPIGatewayDocumentationPart'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAPIGatewayDocumentationPart -timeout 120m
=== RUN   TestAccAWSAPIGatewayDocumentationPart_basic
--- PASS: TestAccAWSAPIGatewayDocumentationPart_basic (25.01s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_method
--- PASS: TestAccAWSAPIGatewayDocumentationPart_method (35.23s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_responseHeader
--- PASS: TestAccAWSAPIGatewayDocumentationPart_responseHeader (27.14s)
=== RUN   TestAccAWSAPIGatewayDocumentationPart_importBasic
--- PASS: TestAccAWSAPIGatewayDocumentationPart_importBasic (23.45s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	110.870s

@bflad bflad added the service/apigateway Issues and PRs that pertain to the apigateway service. label Jan 11, 2018
@radeksimko radeksimko merged commit 0434a5b into master Jan 11, 2018
@radeksimko radeksimko deleted the f-apig-documentation-part branch January 11, 2018 07:36
@bflad
Copy link
Contributor

bflad commented Jan 12, 2018

This has been released in terraform-provider-aws version 1.7.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@bflad bflad added this to the v1.7.0 milestone Jan 12, 2018
@ghost
Copy link

ghost commented Apr 8, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/apigateway Issues and PRs that pertain to the apigateway service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants