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

Feature/add api gateway stage data source #8890

Conversation

FreekingDean
Copy link

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Release note for CHANGELOG:

adds new data source "aws_api_gateway_stage"

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'
 ==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccDataSourceAwsApiGatewayStage -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccDataSourceAwsApiGatewayStage
=== PAUSE TestAccDataSourceAwsApiGatewayStage
=== CONT  TestAccDataSourceAwsApiGatewayStage
--- PASS: TestAccDataSourceAwsApiGatewayStage (30.49s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	(cached)g
...

@ghost ghost added size/M Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. service/apigateway Issues and PRs that pertain to the apigateway service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Jun 6, 2019
@FreekingDean
Copy link
Author

FreekingDean commented Jun 6, 2019

One issue I ran into that I did not expect was when using depends_on for the stage instead of using the basename funkyness that is in there now I ran into this error testing:

data "aws_api_gateway_stage" "example" {
  depends_on  = ["aws_api_gateway_stage.example"]
  rest_api_id = "${aws_api_gateway_rest_api.test.id}"
  stage_name 	= "prod"
}
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccDataSourceAwsApiGatewayStage -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccDataSourceAwsApiGatewayStage
=== PAUSE TestAccDataSourceAwsApiGatewayStage
=== CONT  TestAccDataSourceAwsApiGatewayStage
--- FAIL: TestAccDataSourceAwsApiGatewayStage (31.83s)
    testing.go:568: Step 0 error: After applying this step and refreshing, the plan was not empty:
        
        DIFF:
        
        UPDATE: data.aws_api_gateway_stage.example
          current_deployment_id: "" => "<computed>"
          id:                    "" => "<computed>"
          rest_api_id:           "" => "ibu4ynzcr3"
          stage_name:            "" => "prod"
        

@FreekingDean FreekingDean force-pushed the feature/add-api-gateway-stage-data-source branch from 1a07282 to 6ee79d8 Compare June 6, 2019 13:06
@bflad bflad added the new-data-source Introduces a new data source. label Jun 6, 2019
Copy link
Member

@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.

Hi @FreekingDean 👋 Thanks so much for your contribution here. I left some initial feedback items below -- please reach out if you have any questions or do not have time to implement them.

Regarding your earlier comment about depends_on: the usage of depends_on with data sources can be problematic with perpetual read updates and its usage is discouraged in general for data sources. We do have some documentation about this here, if you are interested in reading more: https://www.terraform.io/docs/configuration/data-sources.html#data-resource-dependencies

Type: schema.TypeString,
Required: true,
},
"current_deployment_id": {
Copy link
Member

Choose a reason for hiding this comment

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

Since the API refers to this as deployment ID, should we remove current_ from the naming?

}

d.SetId(fmt.Sprintf("ags-%s-%s", restApiID, stageName))
d.Set("current_deployment_id", *stage.DeploymentId)
Copy link
Member

Choose a reason for hiding this comment

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

Dereferencing the string pointer via * can introduce potential panics without a nil check and is extraneous here as d.Set() automatically will handle nil 👍

Suggested change
d.Set("current_deployment_id", *stage.DeploymentId)
d.Set("deployment_id", stage.DeploymentId)


data "aws_api_gateway_stage" "example" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
stage_name = "${basename(aws_api_gateway_stage.example.invoke_url)}"
Copy link
Member

Choose a reason for hiding this comment

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

Can we use stage_name = "${aws_api_gateway_stage.example.stage_name}" instead?

Copy link
Author

Choose a reason for hiding this comment

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

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccDataSourceAwsApiGatewayStage -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccDataSourceAwsApiGatewayStage
=== PAUSE TestAccDataSourceAwsApiGatewayStage
=== CONT  TestAccDataSourceAwsApiGatewayStage
--- PASS: TestAccDataSourceAwsApiGatewayStage (27.37s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	27.411s

Just to note that Acceptance tests still pass :)

aws/provider.go Outdated Show resolved Hide resolved
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 6, 2019
@ghost ghost added size/L Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. and removed size/M Managed by automation to categorize the size of a PR. labels Jun 6, 2019
@FreekingDean
Copy link
Author

I believe I resolved all outstanding comments @bflad! Let me know if theres anything else you see that sticks out!

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 6, 2019
Copy link
Member

@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.

Small little things then should be good to go!

stage_name = "production"
}

resource "aws_api_gateway_stage" "production" {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be named prod to match the stage_name below or vice versa? Maybe blue/green? Admittedly this example feels a little confusing to me for a use case since it doesn't show overwriting any stage settings. 😅

Copy link
Author

Choose a reason for hiding this comment

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

Hopefully this is a bit better, our use case was:
We had a system that updated & deployed an api gateway stage, but wanted to configure settings (specifically the logging settings via terraform). This would cause issues every time we applied since a deployment is required as an attribute, this change will allow us to just use the latest deployment as input to the stage resource so we dont revery the api gateway on each trerraform apply!

website/docs/d/api_gateway_stage.html.markdown Outdated Show resolved Hide resolved
website/docs/d/api_gateway_stage.html.markdown Outdated Show resolved Hide resolved
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 6, 2019
@FreekingDean FreekingDean force-pushed the feature/add-api-gateway-stage-data-source branch from 3bd3b01 to 6a4a6b2 Compare June 6, 2019 21:33
@FreekingDean
Copy link
Author

Hopefully they are addressed!

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 6, 2019
@FreekingDean
Copy link
Author

Anything needed for this?

@FreekingDean
Copy link
Author

Just wanted to see if there were changes requested! :D

@FreekingDean
Copy link
Author

Hey! Just wanted to do a last checkin to see if theres something I can do to help this through :)

@FreekingDean
Copy link
Author

Just want to bump this again to see what I can do to help!

@aeschright aeschright requested a review from a team June 28, 2019 18:14
@FreekingDean
Copy link
Author

Any updates to this?

@jlambert121
Copy link

Is there anything blocking this? This is something that is impacting us!

@FreekingDean
Copy link
Author

Fixed the merge conflict!

@FreekingDean FreekingDean requested review from bflad and removed request for a team September 25, 2019 16:08
@FreekingDean
Copy link
Author

Closing this to clean up my open PRs

@FreekingDean FreekingDean deleted the feature/add-api-gateway-stage-data-source branch April 13, 2020 17:38
@ghost
Copy link

ghost commented May 14, 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!

@hashicorp hashicorp locked and limited conversation to collaborators May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-data-source Introduces a new data source. provider Pertains to the provider itself, rather than any interaction with AWS. service/apigateway Issues and PRs that pertain to the apigateway service. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants