-
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
New Resource: aws_api_gateway_documentation_version #3287
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.
As usual in pretty good shape. 👍 Please let me know if you have any questions! I can approve this once at least the version item is fixed up.
make testacc TEST=./aws TESTARGS='-run=TestAccAWSAPIGatewayDocumentationVersion'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAPIGatewayDocumentationVersion -timeout 120m
=== RUN TestAccAWSAPIGatewayDocumentationVersion_basic
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_basic (15.29s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_allFields
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_allFields (53.44s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_importBasic
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_importBasic (16.14s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 84.923s
|
||
restApiId := d.Get("rest_api_id").(string) | ||
|
||
params := &apigateway.CreateDocumentationVersionInput{ |
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.
Question: the CreateDocumentationVersionInput
type also supports StageName
, do we need to support it as well?
// The stage name to be associated with the new documentation snapshot.
StageName *string `locationName:"stageName" type:"string"`
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 intentionally removed it, although it was in my original implementation. CloudFormation also doesn't have it, probably for the same reason https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-documentationversion.html
It has a very problematic workflow. You need to create the stage 1st (for referencing in APIG Documentation Version), but you cannot delete the APIG Documentation Version before deleting the stage (it errors out otherwise). Basically the dependency chain reverts during destruction.
Either way we shouldn't need it, because https://www.terraform.io/docs/providers/aws/r/api_gateway_stage.html#documentation_version allows users to associate the two.
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.
👍 sounds good
d.Set("version", docVersion) | ||
d.Set("rest_api_id", apiId) | ||
d.Set("description", version.Description) | ||
d.Set("version", version.Version) |
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.
Setting version
twice 😉
}) | ||
} | ||
|
||
func TestAccAWSAPIGatewayDocumentationVersion_importBasic(t *testing.T) { |
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.
Nitpick: Something I've been trying to remember to do is include ImportState
TestStep
s with each of the regular tests. We get the extra benefit of checking the additional attributes associated with each of the test cases and don't need explicit import test cases (which generally get neglected unless there's a 🐛 - too late!).
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 have no objections against adding more import tests with different configurations, but I don't think it's a good idea to add ImportState
to existing tests which aren't called _import
.
If we break import (for any reason) and nothing else I expect _import
tests to fail, but no other tests, and vice versa, ideally. While in reality this is may not be always true I think we should aim for such isolation so it's easier to debug test failures as they appear.
There's benefit to isolation, I think - to keep us sane and focused 😉
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 added a new test - TestAccAWSAPIGatewayDocumentationVersion_importAllFields
which should address this concern, hopefully? 😃
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 don't mean to harp on this resource/test specifically, but here's where I'm coming from, using this resource's testing as an example. I'm not asking you to change this one, but I think its something worth thinking about. 😄
- We now have two of these import tests, duplicating the regular ones except a new
TestStep
. This means the testing is going to take roughly twice as long. Not the biggest deal, but even running parallel these all add up. e.g.
make testacc TEST=./aws TESTARGS='-run=TestAccAWSAPIGatewayDocumentationVersion'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAPIGatewayDocumentationVersion -timeout 120m
=== RUN TestAccAWSAPIGatewayDocumentationVersion_basic
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_basic (14.69s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_allFields
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_allFields (57.37s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_importBasic
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_importBasic (16.63s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_importAllFields
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_importAllFields (43.97s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 132.701s
-
The "regular" part (first
TestStep
) of these_importX
tests can also fail because of other resources. There are plenty of examples of these in the EC2 or KMS daily acceptance testing. So if you're looking at just the test name and not the actual error message (we're looking at the error message right? 😉 ), you can be misled already. -
I think
TestStep.ImportStateVerify
seems to do a pretty good job of calling out that its an import problem by the error message.
// Comment out in resourceAwsApiGatewayDocumentationVersionRead
// d.Set("description", version.Description)
// Add in resourceAwsApiGatewayDocumentationVersionCreate
d.Set("description", d.Get("description").(string))
// Add to TestAccAWSAPIGatewayDocumentationVersion_allFields
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
It returns:
make testacc TEST=./aws TESTARGS='-run=TestAccAWSAPIGatewayDocumentationVersion_allFields'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAPIGatewayDocumentationVersion_allFields -timeout 120m
=== RUN TestAccAWSAPIGatewayDocumentationVersion_allFields
--- FAIL: TestAccAWSAPIGatewayDocumentationVersion_allFields (34.59s)
testing.go:513: Step 2 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
(map[string]string) {
}
(map[string]string) (len=1) {
(string) (len=11) "description": (string) (len=40) "Tf Acc Test description updated xjsh6nsw"
}
FAIL
exit status 1
FAIL github.com/terraform-providers/terraform-provider-aws/aws 34.628s
Combined with maybe a little bit better naming of the tests (e.g. _description
in this case), we'll know from the test name its a description
problem and from the error message its an import problem.
Hope this makes sense! 🍻 I guess mentally I am treating an attribute's import just a "feature" of an attribute, which should be logically tested with the other CRUD actions on it.
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.
mentally I am treating an attribute's import just a "feature" of an attribute, which should be logically tested with the other CRUD actions on it.
That's an interesting POV. I never thought about that like this. We can discuss that on Slack with other folks later. 👌
return err | ||
} | ||
|
||
func decodeApiGatewayDocVersionId(id string) (string, string, error) { |
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.
Worst OCD nitpick maybe of all time 😢 : Can you spell out Documentation
so we can keep everything consistent with DocumentationVersion
depends_on = ["aws_api_gateway_documentation_part.test"] | ||
} | ||
|
||
resource "aws_api_gateway_documentation_part" "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.
Nitpick: Can we reuse something from the aws_api_gateway_documentation_part
test configurations instead of duplicating this whole large configuration? 😄
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 not sure it's a good idea as tests should ideally be as isolated as possible, at least cross resource, IMO.
|
||
# aws_api_gateway_documentation_version | ||
|
||
Provides a settings of an API Gateway Documentation Version. |
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.
Typo 🕶 : Maybe a resource to manage an
here and slightly above?
10ea2fd
to
eef28b1
Compare
|
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.
LGTM! (we can discuss my likely crazy opinions of import testing outside this PR)
make testacc TEST=./aws TESTARGS='-run=TestAccAWSAPIGatewayDocumentationVersion'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAPIGatewayDocumentationVersion -timeout 120m
=== RUN TestAccAWSAPIGatewayDocumentationVersion_basic
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_basic (14.69s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_allFields
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_allFields (57.37s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_importBasic
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_importBasic (16.63s)
=== RUN TestAccAWSAPIGatewayDocumentationVersion_importAllFields
--- PASS: TestAccAWSAPIGatewayDocumentationVersion_importAllFields (43.97s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 132.701s
Those opinions are important and useful for a healthy discussion 😉 But yeah, let's discuss this outside of this PR. |
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. |
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! |
Test results