From cc5dbd1fdd9f57aa131ec5d549f0f1fffed645a4 Mon Sep 17 00:00:00 2001 From: "xiaowei.wang" Date: Sat, 17 Feb 2018 13:51:17 +0100 Subject: [PATCH] resource/api_gateway_integration: add acceptance test for vpc link --- ...source_aws_api_gateway_integration_test.go | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/aws/resource_aws_api_gateway_integration_test.go b/aws/resource_aws_api_gateway_integration_test.go index 37b55313801c..f476a8eb10fb 100644 --- a/aws/resource_aws_api_gateway_integration_test.go +++ b/aws/resource_aws_api_gateway_integration_test.go @@ -7,6 +7,7 @@ import ( "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/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -214,6 +215,29 @@ func TestAccAWSAPIGatewayIntegration_cache_key_parameters(t *testing.T) { }) } +func TestAccAWSAPIGatewayIntegration_vpcLink(t *testing.T) { + var conf apigateway.Integration + + rName := fmt.Sprintf("tf-acctest-apigw-int-%s", acctest.RandString(7)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayIntegrationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayIntegrationConfigVpcLink(rName), + 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", "connection_type", "VPC_LINK"), + resource.TestCheckResourceAttrSet("aws_api_gateway_integration.test", "connection_id"), + ), + }, + }, + }) +} + func testAccCheckAWSAPIGatewayIntegrationExists(n string, res *apigateway.Integration) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -587,3 +611,84 @@ resource "aws_api_gateway_integration" "test" { content_handling = "CONVERT_TO_TEXT" } ` + +func testAccAWSAPIGatewayIntegrationConfigVpcLink(rName string) string { + return fmt.Sprintf(` +variable "name" { + default = "%s" +} + +resource "aws_api_gateway_rest_api" "test" { + name = "${var.name}" +} + +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" + integration_http_method = "GET" + passthrough_behavior = "WHEN_NO_MATCH" + content_handling = "CONVERT_TO_TEXT" + + connection_type = "VPC_LINK" + connection_id = "${aws_api_gateway_vpc_link.test.id}" +} + +resource "aws_lb" "test" { + name = "${var.name}" + internal = true + load_balancer_type = "network" + subnets = ["${aws_subnet.test.id}"] +} + +resource "aws_vpc" "test" { + cidr_block = "10.10.0.0/16" + tags { + Name = "${var.name}" + } +} + +data "aws_availability_zones" "test" {} + +resource "aws_subnet" "test" { + vpc_id = "${aws_vpc.test.id}" + cidr_block = "10.10.0.0/24" + availability_zone = "${data.aws_availability_zones.test.names[0]}" +} + +resource "aws_api_gateway_vpc_link" "test" { + name = "${var.name}" + target_arns = ["${aws_lb.test.arn}"] +} +`, rName) +}