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

Added import support for API Gateway Deployment #28030

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions internal/service/apigateway/deployment.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package apigateway

import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -22,6 +24,10 @@ func ResourceDeployment() *schema.Resource {
Update: resourceDeploymentUpdate,
Delete: resourceDeploymentDelete,

Importer: &schema.ResourceImporter{
StateContext: resourceDeploymentImport,
},

Schema: map[string]*schema.Schema{
"rest_api_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -221,3 +227,18 @@ func resourceDeploymentDelete(d *schema.ResourceData, meta interface{}) error {

return nil
}

func resourceDeploymentImport(_ context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
idParts := strings.Split(d.Id(), "/")
if len(idParts) != 2 {
return nil, fmt.Errorf("Unexpected format of ID (%s), use: 'REST-API-ID/DEPLOYMENT-ID'", d.Id())
}

restApiID := idParts[0]
deploymentID := idParts[1]

d.SetId(deploymentID)
d.Set("rest_api_id", restApiID)

return []*schema.ResourceData{d}, nil
}
12 changes: 12 additions & 0 deletions website/docs/r/api_gateway_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,15 @@ In addition to all arguments above, the following attributes are exported:
when allowing API Gateway to invoke a Lambda function,
e.g., `arn:aws:execute-api:eu-west-2:123456789012:z4675bid1j/prod`
* `created_date` - Creation date of the deployment

## Import

`aws_api_gateway_deployment` can be imported using `REST-API-ID/DEPLOYMENT-ID`, e.g.,

```
$ terraform import aws_api_gateway_deployment.example aabbccddee/1122334
```

The `stage_name` and `stage_description` arguments cannot be imported. Use the [`aws_api_gateway_stage` resource](api_gateway_stage.html) to import and manage stages.

The `triggers` argument cannot be imported.