From eb70c538a85b6d8235e7a03106f34a06ee07604c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tero=20Kein=C3=A4nen?= Date: Thu, 26 Jan 2017 21:39:27 +0200 Subject: [PATCH] Fix: path not updated when modifying AWS API Gateway Resource Fixes #11442 --- .../aws/resource_aws_api_gateway_resource.go | 1 + .../resource_aws_api_gateway_resource_test.go | 55 ++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_api_gateway_resource.go b/builtin/providers/aws/resource_aws_api_gateway_resource.go index 77df10c31..04f136174 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_resource.go +++ b/builtin/providers/aws/resource_aws_api_gateway_resource.go @@ -84,6 +84,7 @@ func resourceAwsApiGatewayResourceRead(d *schema.ResourceData, meta interface{}) d.Set("parent_id", resource.ParentId) d.Set("path_part", resource.PathPart) + d.Set("path", resource.Path) return nil } diff --git a/builtin/providers/aws/resource_aws_api_gateway_resource_test.go b/builtin/providers/aws/resource_aws_api_gateway_resource_test.go index d398d7fa5..d0b3d8568 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_resource_test.go +++ b/builtin/providers/aws/resource_aws_api_gateway_resource_test.go @@ -23,18 +23,55 @@ func TestAccAWSAPIGatewayResource_basic(t *testing.T) { Config: testAccAWSAPIGatewayResourceConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayResourceExists("aws_api_gateway_resource.test", &conf), - testAccCheckAWSAPIGatewayResourceAttributes(&conf), + testAccCheckAWSAPIGatewayResourceAttributes(&conf, "/test"), resource.TestCheckResourceAttr( "aws_api_gateway_resource.test", "path_part", "test"), + resource.TestCheckResourceAttr( + "aws_api_gateway_resource.test", "path", "/test"), ), }, }, }) } -func testAccCheckAWSAPIGatewayResourceAttributes(conf *apigateway.Resource) resource.TestCheckFunc { +func TestAccAWSAPIGatewayResource_update(t *testing.T) { + var conf apigateway.Resource + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayResourceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSAPIGatewayResourceConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayResourceExists("aws_api_gateway_resource.test", &conf), + testAccCheckAWSAPIGatewayResourceAttributes(&conf, "/test"), + resource.TestCheckResourceAttr( + "aws_api_gateway_resource.test", "path_part", "test"), + resource.TestCheckResourceAttr( + "aws_api_gateway_resource.test", "path", "/test"), + ), + }, + + resource.TestStep{ + Config: testAccAWSAPIGatewayResourceConfig_updatePathPart, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayResourceExists("aws_api_gateway_resource.test", &conf), + testAccCheckAWSAPIGatewayResourceAttributes(&conf, "/test_changed"), + resource.TestCheckResourceAttr( + "aws_api_gateway_resource.test", "path_part", "test_changed"), + resource.TestCheckResourceAttr( + "aws_api_gateway_resource.test", "path", "/test_changed"), + ), + }, + }, + }) +} + +func testAccCheckAWSAPIGatewayResourceAttributes(conf *apigateway.Resource, path string) resource.TestCheckFunc { return func(s *terraform.State) error { - if *conf.Path != "/test" { + if *conf.Path != path { return fmt.Errorf("Wrong Path: %q", conf.Path) } @@ -119,3 +156,15 @@ resource "aws_api_gateway_resource" "test" { path_part = "test" } ` + +const testAccAWSAPIGatewayResourceConfig_updatePathPart = ` +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_changed" +} +`