mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 23:46:26 -06:00
66a14cb3b7
* provider/aws: Re-implement api gateway parameter handling this PR cleans up some left overs from PR #4295, namely the parameter handling. now that GH-2143 is finally closed this PR does away with the ugly `request_parameters_in_json` and `response_parameters_in_json` hack. * Add deprecation message and conflictsWith settings following @radeksimko s advice, keeping the old code around with a deprecation warning. this should be cleaned up in a few releases * provider/aws: fix missing append operation * provider/aws: mark old parameters clearly as deprecated * provider/aws work around #8104 following @radeksimko s lead * provider/aws fix cnp error
238 lines
7.0 KiB
Go
238 lines
7.0 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
"github.com/aws/aws-sdk-go/service/apigateway"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSAPIGatewayIntegration_basic(t *testing.T) {
|
|
var conf apigateway.Integration
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckAWSAPIGatewayIntegrationDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccAWSAPIGatewayIntegrationConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSAPIGatewayIntegrationExists("aws_api_gateway_integration.test", &conf),
|
|
testAccCheckAWSAPIGatewayIntegrationAttributes(&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"),
|
|
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{ }"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_api_gateway_integration.test", "passthrough_behavior", "WHEN_NO_MATCH"),
|
|
),
|
|
},
|
|
|
|
resource.TestStep{
|
|
Config: testAccAWSAPIGatewayIntegrationConfigUpdate,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSAPIGatewayIntegrationExists("aws_api_gateway_integration.test", &conf),
|
|
testAccCheckAWSAPIGatewayMockIntegrationAttributes(&conf),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_api_gateway_integration.test", "type", "MOCK"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_api_gateway_integration.test", "integration_http_method", ""),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_api_gateway_integration.test", "uri", ""),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_api_gateway_integration.test", "passthrough_behavior", "NEVER"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckAWSAPIGatewayMockIntegrationAttributes(conf *apigateway.Integration) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
if *conf.Type != "MOCK" {
|
|
return fmt.Errorf("Wrong Type: %q", *conf.Type)
|
|
}
|
|
if *conf.RequestParameters["integration.request.header.X-Authorization"] != "'updated'" {
|
|
return fmt.Errorf("wrong updated RequestParameters for header.X-Authorization")
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckAWSAPIGatewayIntegrationAttributes(conf *apigateway.Integration) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
if *conf.HttpMethod == "" {
|
|
return fmt.Errorf("empty HttpMethod")
|
|
}
|
|
if *conf.Uri != "https://www.google.de" {
|
|
return fmt.Errorf("wrong Uri")
|
|
}
|
|
if *conf.Type != "HTTP" {
|
|
return fmt.Errorf("wrong Type")
|
|
}
|
|
if conf.RequestTemplates["application/json"] != nil {
|
|
return fmt.Errorf("wrong RequestTemplate for application/json")
|
|
}
|
|
if *conf.RequestTemplates["application/xml"] != "#set($inputRoot = $input.path('$'))\n{ }" {
|
|
return fmt.Errorf("wrong RequestTemplate for application/xml")
|
|
}
|
|
if *conf.RequestParameters["integration.request.header.X-Authorization"] != "'static'" {
|
|
return fmt.Errorf("wrong RequestParameters for header.X-Authorization")
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckAWSAPIGatewayIntegrationExists(n string, res *apigateway.Integration) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No API Gateway Method ID is set")
|
|
}
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).apigateway
|
|
|
|
req := &apigateway.GetIntegrationInput{
|
|
HttpMethod: aws.String("GET"),
|
|
ResourceId: aws.String(s.RootModule().Resources["aws_api_gateway_resource.test"].Primary.ID),
|
|
RestApiId: aws.String(s.RootModule().Resources["aws_api_gateway_rest_api.test"].Primary.ID),
|
|
}
|
|
describe, err := conn.GetIntegration(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*res = *describe
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckAWSAPIGatewayIntegrationDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*AWSClient).apigateway
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_api_gateway_integration" {
|
|
continue
|
|
}
|
|
|
|
req := &apigateway.GetIntegrationInput{
|
|
HttpMethod: aws.String("GET"),
|
|
ResourceId: aws.String(s.RootModule().Resources["aws_api_gateway_resource.test"].Primary.ID),
|
|
RestApiId: aws.String(s.RootModule().Resources["aws_api_gateway_rest_api.test"].Primary.ID),
|
|
}
|
|
_, err := conn.GetIntegration(req)
|
|
|
|
if err == nil {
|
|
return fmt.Errorf("API Gateway Method still exists")
|
|
}
|
|
|
|
aws2err, ok := err.(awserr.Error)
|
|
if !ok {
|
|
return err
|
|
}
|
|
if aws2err.Code() != "NotFoundException" {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
const testAccAWSAPIGatewayIntegrationConfig = `
|
|
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'"
|
|
}
|
|
|
|
type = "HTTP"
|
|
uri = "https://www.google.de"
|
|
integration_http_method = "GET"
|
|
passthrough_behavior = "WHEN_NO_MATCH"
|
|
}
|
|
`
|
|
|
|
const testAccAWSAPIGatewayIntegrationConfigUpdate = `
|
|
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_parameters = {
|
|
"integration.request.header.X-Authorization" = "'updated'"
|
|
}
|
|
|
|
type = "MOCK"
|
|
passthrough_behavior = "NEVER"
|
|
|
|
}
|
|
`
|