Skip to content

Commit

Permalink
resource/api_gateway_integration: add acceptance test for vpc link
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei.wang committed Mar 15, 2018
1 parent 128e1e6 commit cc5dbd1
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions aws/resource_aws_api_gateway_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}

0 comments on commit cc5dbd1

Please sign in to comment.