Skip to content

Commit

Permalink
resource/aws_api_gateway_integration: Allow update of URI attributes (#…
Browse files Browse the repository at this point in the history
…2834)

* Allow updating API Gateway integration URI attributes instead of forcing new resources

* Add testcase for updating API Gateway integration URI attributes
  • Loading branch information
mdlavin authored and Ninir committed Jan 10, 2018
1 parent 507d6ae commit 6838bdc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
12 changes: 11 additions & 1 deletion aws/resource_aws_api_gateway_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func resourceAwsApiGatewayIntegration() *schema.Resource {
"uri": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"credentials": {
Expand Down Expand Up @@ -370,6 +369,17 @@ func resourceAwsApiGatewayIntegrationUpdate(d *schema.ResourceData, meta interfa
})
}

// The documentation https://docs.aws.amazon.com/apigateway/api-reference/link-relation/integration-update/ says
// that uri changes are only supported for non-mock types. Because the uri value is not used in mock
// resources, it means that the uri can always be updated
if d.HasChange("uri") {
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/uri"),
Value: aws.String(d.Get("uri").(string)),
})
}

params := &apigateway.UpdateIntegrationInput{
HttpMethod: aws.String(d.Get("http_method").(string)),
ResourceId: aws.String(d.Get("resource_id").(string)),
Expand Down
64 changes: 64 additions & 0 deletions aws/resource_aws_api_gateway_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ func TestAccAWSAPIGatewayIntegration_basic(t *testing.T) {
),
},

{
Config: testAccAWSAPIGatewayIntegrationConfigUpdateURI,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayIntegrationExists("aws_api_gateway_integration.test", &conf),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "type", "HTTP"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "integration_http_method", "GET"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "uri", "https://www.google.de/updated"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "passthrough_behavior", "WHEN_NO_MATCH"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "content_handling", "CONVERT_TO_TEXT"),
resource.TestCheckNoResourceAttr("aws_api_gateway_integration.test", "credentials"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_parameters.%", "2"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_parameters.integration.request.header.X-Authorization", "'static'"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_parameters.integration.request.header.X-Foo", "'Bar'"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_templates.%", "2"),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_templates.application/json", ""),
resource.TestCheckResourceAttr("aws_api_gateway_integration.test", "request_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"),
),
},

{
Config: testAccAWSAPIGatewayIntegrationConfigUpdateNoTemplates,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -279,6 +298,51 @@ resource "aws_api_gateway_integration" "test" {
}
`

const testAccAWSAPIGatewayIntegrationConfigUpdateURI = `
resource "aws_api_gateway_rest_api" "test" {
name = "test"
}
resource "aws_api_gateway_resource" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
parent_id = "${aws_api_gateway_rest_api.test.root_resource_id}"
path_part = "test"
}
resource "aws_api_gateway_method" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
resource_id = "${aws_api_gateway_resource.test.id}"
http_method = "GET"
authorization = "NONE"
request_models = {
"application/json" = "Error"
}
}
resource "aws_api_gateway_integration" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
resource_id = "${aws_api_gateway_resource.test.id}"
http_method = "${aws_api_gateway_method.test.http_method}"
request_templates = {
"application/json" = ""
"application/xml" = "#set($inputRoot = $input.path('$'))\n{ }"
}
request_parameters = {
"integration.request.header.X-Authorization" = "'static'"
"integration.request.header.X-Foo" = "'Bar'"
}
type = "HTTP"
uri = "https://www.google.de/updated"
integration_http_method = "GET"
passthrough_behavior = "WHEN_NO_MATCH"
content_handling = "CONVERT_TO_TEXT"
}
`

const testAccAWSAPIGatewayIntegrationConfigUpdateNoTemplates = `
resource "aws_api_gateway_rest_api" "test" {
name = "test"
Expand Down

0 comments on commit 6838bdc

Please sign in to comment.