Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Gateway basePath import options for OpenAPI #7374

Merged
merged 9 commits into from
Jan 12, 2021
20 changes: 20 additions & 0 deletions aws/resource_aws_api_gateway_rest_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func resourceAwsApiGatewayRestApi() *schema.Resource {
Optional: true,
},

"body_base_path": {
Type: schema.TypeString,
Default: "ignore",
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"ignore", "prepend", "split"}, true),
},

"minimum_compression_size": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -175,12 +182,20 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{}

d.SetId(aws.StringValue(gateway.Id))

bodyBasePathMode := d.Get("body_base_path").(string)

if body, ok := d.GetOk("body"); ok {
log.Printf("[DEBUG] Initializing API Gateway from OpenAPI spec %s", d.Id())
_, err := conn.PutRestApi(&apigateway.PutRestApiInput{
RestApiId: gateway.Id,
Mode: aws.String(apigateway.PutModeOverwrite),
Body: []byte(body.(string)),
Parameters: map[string]*string{
// See https://docs.aws.amazon.com/cli/latest/reference/apigateway/import-rest-api.html
// At the moment of writing, according to aws support, the docs are incorrect
// and the parameter should be called 'basepath' and not 'basePath'
"basepath": &bodyBasePathMode,
},
})
if err != nil {
return fmt.Errorf("error creating API Gateway specification: %s", err)
Expand Down Expand Up @@ -411,12 +426,17 @@ func resourceAwsApiGatewayRestApiUpdate(d *schema.ResourceData, meta interface{}
}

if d.HasChange("body") {
bodyBasePathMode := d.Get("body_base_path").(string)

if body, ok := d.GetOk("body"); ok {
log.Printf("[DEBUG] Updating API Gateway from OpenAPI spec: %s", d.Id())
_, err := conn.PutRestApi(&apigateway.PutRestApiInput{
RestApiId: aws.String(d.Id()),
Mode: aws.String(apigateway.PutModeOverwrite),
Body: []byte(body.(string)),
Parameters: map[string]*string{
"basepath": &bodyBasePathMode,
},
})
if err != nil {
return fmt.Errorf("error updating API Gateway specification: %s", err)
Expand Down
Loading