Merge pull request #11443 from kenkku/aws_api_gateway_resource_path_fix

Fix: path not updated when modifying AWS API Gateway Resource
This commit is contained in:
Clint 2017-01-26 14:44:44 -06:00 committed by GitHub
commit 46f7265747
2 changed files with 53 additions and 3 deletions

View File

@ -84,6 +84,7 @@ func resourceAwsApiGatewayResourceRead(d *schema.ResourceData, meta interface{})
d.Set("parent_id", resource.ParentId) d.Set("parent_id", resource.ParentId)
d.Set("path_part", resource.PathPart) d.Set("path_part", resource.PathPart)
d.Set("path", resource.Path)
return nil return nil
} }

View File

@ -23,18 +23,55 @@ func TestAccAWSAPIGatewayResource_basic(t *testing.T) {
Config: testAccAWSAPIGatewayResourceConfig, Config: testAccAWSAPIGatewayResourceConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayResourceExists("aws_api_gateway_resource.test", &conf), testAccCheckAWSAPIGatewayResourceExists("aws_api_gateway_resource.test", &conf),
testAccCheckAWSAPIGatewayResourceAttributes(&conf), testAccCheckAWSAPIGatewayResourceAttributes(&conf, "/test"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_api_gateway_resource.test", "path_part", "test"), "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 { return func(s *terraform.State) error {
if *conf.Path != "/test" { if *conf.Path != path {
return fmt.Errorf("Wrong Path: %q", conf.Path) return fmt.Errorf("Wrong Path: %q", conf.Path)
} }
@ -119,3 +156,15 @@ resource "aws_api_gateway_resource" "test" {
path_part = "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"
}
`