Skip to content

Commit 38078fb

Browse files
committed
Merge pull request hashicorp#5470 from TimeIncOSS/f-api-gateway-cleanup
provider/aws: Cleanup nitpicks in new API Gateway resources
2 parents caaf9ba + 61d0d19 commit 38078fb

17 files changed

Lines changed: 526 additions & 430 deletions

Godeps/Godeps.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builtin/providers/aws/provider.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ func Provider() terraform.ResourceProvider {
114114
"aws_ami": resourceAwsAmi(),
115115
"aws_ami_copy": resourceAwsAmiCopy(),
116116
"aws_ami_from_instance": resourceAwsAmiFromInstance(),
117-
"aws_api_gateway_rest_api": resourceAwsApiGatewayRestApi(),
118117
"aws_api_gateway_api_key": resourceAwsApiGatewayApiKey(),
119-
"aws_api_gateway_model": resourceAwsApiGatewayModel(),
120-
"aws_api_gateway_resource": resourceAwsApiGatewayResource(),
121-
"aws_api_gateway_method": resourceAwsApiGatewayMethod(),
122-
"aws_api_gateway_method_response": resourceAwsApiGatewayMethodResponse(),
118+
"aws_api_gateway_deployment": resourceAwsApiGatewayDeployment(),
123119
"aws_api_gateway_integration": resourceAwsApiGatewayIntegration(),
124120
"aws_api_gateway_integration_response": resourceAwsApiGatewayIntegrationResponse(),
125-
"aws_api_gateway_deployment": resourceAwsApiGatewayDeployment(),
121+
"aws_api_gateway_method": resourceAwsApiGatewayMethod(),
122+
"aws_api_gateway_method_response": resourceAwsApiGatewayMethodResponse(),
123+
"aws_api_gateway_model": resourceAwsApiGatewayModel(),
124+
"aws_api_gateway_resource": resourceAwsApiGatewayResource(),
125+
"aws_api_gateway_rest_api": resourceAwsApiGatewayRestApi(),
126126
"aws_app_cookie_stickiness_policy": resourceAwsAppCookieStickinessPolicy(),
127127
"aws_autoscaling_group": resourceAwsAutoscalingGroup(),
128128
"aws_autoscaling_notification": resourceAwsAutoscalingNotification(),

builtin/providers/aws/resource_aws_api_gateway_integration.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,11 @@ func resourceAwsApiGatewayIntegrationDelete(d *schema.ResourceData, meta interfa
161161
conn := meta.(*AWSClient).apigateway
162162
log.Printf("[DEBUG] Deleting API Gateway Integration: %s", d.Id())
163163

164-
resourceId := d.Get("resource_id").(string)
165-
if o, n := d.GetChange("resource_id"); o.(string) != n.(string) {
166-
resourceId = o.(string)
167-
}
168-
httpMethod := d.Get("http_method").(string)
169-
if o, n := d.GetChange("http_method"); o.(string) != n.(string) {
170-
httpMethod = o.(string)
171-
}
172-
restApiID := d.Get("rest_api_id").(string)
173-
if o, n := d.GetChange("rest_api_id"); o.(string) != n.(string) {
174-
restApiID = o.(string)
175-
}
176-
177164
return resource.Retry(5*time.Minute, func() error {
178-
log.Printf("[DEBUG] schema is %#v", d)
179165
_, err := conn.DeleteIntegration(&apigateway.DeleteIntegrationInput{
180-
HttpMethod: aws.String(httpMethod),
181-
ResourceId: aws.String(resourceId),
182-
RestApiId: aws.String(restApiID),
166+
HttpMethod: aws.String(d.Get("http_method").(string)),
167+
ResourceId: aws.String(d.Get("resource_id").(string)),
168+
RestApiId: aws.String(d.Get("rest_api_id").(string)),
183169
})
184170
if err == nil {
185171
return nil

builtin/providers/aws/resource_aws_api_gateway_integration_response.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,12 @@ func resourceAwsApiGatewayIntegrationResponseDelete(d *schema.ResourceData, meta
116116
conn := meta.(*AWSClient).apigateway
117117
log.Printf("[DEBUG] Deleting API Gateway Integration Response: %s", d.Id())
118118

119-
resourceId := d.Get("resource_id").(string)
120-
if o, n := d.GetChange("resource_id"); o.(string) != n.(string) {
121-
resourceId = o.(string)
122-
}
123-
httpMethod := d.Get("http_method").(string)
124-
if o, n := d.GetChange("http_method"); o.(string) != n.(string) {
125-
httpMethod = o.(string)
126-
}
127-
restApiID := d.Get("rest_api_id").(string)
128-
if o, n := d.GetChange("rest_api_id"); o.(string) != n.(string) {
129-
restApiID = o.(string)
130-
}
131-
statusCode := d.Get("status_code").(string)
132-
if o, n := d.GetChange("status_code"); o.(string) != n.(string) {
133-
statusCode = o.(string)
134-
}
135-
136119
return resource.Retry(5*time.Minute, func() error {
137-
log.Printf("[DEBUG] schema is %#v", d)
138120
_, err := conn.DeleteIntegrationResponse(&apigateway.DeleteIntegrationResponseInput{
139-
HttpMethod: aws.String(httpMethod),
140-
ResourceId: aws.String(resourceId),
141-
RestApiId: aws.String(restApiID),
142-
StatusCode: aws.String(statusCode),
121+
HttpMethod: aws.String(d.Get("http_method").(string)),
122+
ResourceId: aws.String(d.Get("resource_id").(string)),
123+
RestApiId: aws.String(d.Get("rest_api_id").(string)),
124+
StatusCode: aws.String(d.Get("status_code").(string)),
143125
})
144126
if err == nil {
145127
return nil

builtin/providers/aws/resource_aws_api_gateway_method.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,25 +154,11 @@ func resourceAwsApiGatewayMethodDelete(d *schema.ResourceData, meta interface{})
154154
conn := meta.(*AWSClient).apigateway
155155
log.Printf("[DEBUG] Deleting API Gateway Method: %s", d.Id())
156156

157-
resourceId := d.Get("resource_id").(string)
158-
if o, n := d.GetChange("resource_id"); o.(string) != n.(string) {
159-
resourceId = o.(string)
160-
}
161-
httpMethod := d.Get("http_method").(string)
162-
if o, n := d.GetChange("http_method"); o.(string) != n.(string) {
163-
httpMethod = o.(string)
164-
}
165-
restApiID := d.Get("rest_api_id").(string)
166-
if o, n := d.GetChange("rest_api_id"); o.(string) != n.(string) {
167-
restApiID = o.(string)
168-
}
169-
170157
return resource.Retry(5*time.Minute, func() error {
171-
log.Printf("[DEBUG] schema is %#v", d)
172158
_, err := conn.DeleteMethod(&apigateway.DeleteMethodInput{
173-
HttpMethod: aws.String(httpMethod),
174-
ResourceId: aws.String(resourceId),
175-
RestApiId: aws.String(restApiID),
159+
HttpMethod: aws.String(d.Get("http_method").(string)),
160+
ResourceId: aws.String(d.Get("resource_id").(string)),
161+
RestApiId: aws.String(d.Get("rest_api_id").(string)),
176162
})
177163
if err == nil {
178164
return nil

builtin/providers/aws/resource_aws_api_gateway_method_response.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,12 @@ func resourceAwsApiGatewayMethodResponseDelete(d *schema.ResourceData, meta inte
136136
conn := meta.(*AWSClient).apigateway
137137
log.Printf("[DEBUG] Deleting API Gateway Method Response: %s", d.Id())
138138

139-
resourceId := d.Get("resource_id").(string)
140-
if o, n := d.GetChange("resource_id"); o.(string) != n.(string) {
141-
resourceId = o.(string)
142-
}
143-
httpMethod := d.Get("http_method").(string)
144-
if o, n := d.GetChange("http_method"); o.(string) != n.(string) {
145-
httpMethod = o.(string)
146-
}
147-
restApiID := d.Get("rest_api_id").(string)
148-
if o, n := d.GetChange("rest_api_id"); o.(string) != n.(string) {
149-
restApiID = o.(string)
150-
}
151-
statusCode := d.Get("status_code").(string)
152-
if o, n := d.GetChange("status_code"); o.(string) != n.(string) {
153-
statusCode = o.(string)
154-
}
155-
156139
return resource.Retry(5*time.Minute, func() error {
157-
log.Printf("[DEBUG] schema is %#v", d)
158140
_, err := conn.DeleteMethodResponse(&apigateway.DeleteMethodResponseInput{
159-
HttpMethod: aws.String(httpMethod),
160-
ResourceId: aws.String(resourceId),
161-
RestApiId: aws.String(restApiID),
162-
StatusCode: aws.String(statusCode),
141+
HttpMethod: aws.String(d.Get("http_method").(string)),
142+
ResourceId: aws.String(d.Get("resource_id").(string)),
143+
RestApiId: aws.String(d.Get("rest_api_id").(string)),
144+
StatusCode: aws.String(d.Get("status_code").(string)),
163145
})
164146
if err == nil {
165147
return nil

builtin/providers/aws/resource_aws_api_gateway_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func resourceAwsApiGatewayResourceRead(d *schema.ResourceData, meta interface{})
7575
})
7676

7777
if err != nil {
78+
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NotFoundException" {
79+
d.SetId("")
80+
return nil
81+
}
7882
return err
7983
}
8084

builtin/providers/aws/resource_aws_api_gateway_rest_api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ func resourceAwsApiGatewayRestApiRead(d *schema.ResourceData, meta interface{})
8787
RestApiId: aws.String(d.Id()),
8888
})
8989
if err != nil {
90+
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NotFoundException" {
91+
d.SetId("")
92+
return nil
93+
}
9094
return err
9195
}
9296

0 commit comments

Comments
 (0)