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

fix api-gateway import tests #3549

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .changelog/5104.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
apigateway: fixed import functionality for all `apigateway` resources
```
10 changes: 3 additions & 7 deletions google-beta/resource_api_gateway_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ func resourceApiGatewayApiCreate(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error waiting to create Api: %s", err)
}

if err := d.Set("name", flattenApiGatewayApiName(opRes["name"], d, config)); err != nil {
return err
}

// This may have caused the ID to update - update it if so.
id, err = replaceVars(d, config, "projects/{{project}}/locations/global/apis/{{api_id}}")
if err != nil {
Expand Down Expand Up @@ -351,9 +347,9 @@ func resourceApiGatewayApiDelete(d *schema.ResourceData, meta interface{}) error
func resourceApiGatewayApiImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"projects/(?P<project>[^/]+)/locations/global/apis/(?P<name>[^/]+)",
"(?P<project>[^/]+)/(?P<name>[^/]+)",
"(?P<name>[^/]+)",
"projects/(?P<project>[^/]+)/locations/global/apis/(?P<api_id>[^/]+)",
"(?P<project>[^/]+)/(?P<api_id>[^/]+)",
"(?P<api_id>[^/]+)",
}, d, config); err != nil {
return nil, err
}
Expand Down
10 changes: 3 additions & 7 deletions google-beta/resource_api_gateway_api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ func resourceApiGatewayApiConfigCreate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error waiting to create ApiConfig: %s", err)
}

if err := d.Set("name", flattenApiGatewayApiConfigName(opRes["name"], d, config)); err != nil {
return err
}

// This may have caused the ID to update - update it if so.
id, err = replaceVars(d, config, "projects/{{project}}/locations/global/apis/{{api}}/configs/{{api_config_id}}")
if err != nil {
Expand Down Expand Up @@ -446,9 +442,9 @@ func resourceApiGatewayApiConfigDelete(d *schema.ResourceData, meta interface{})
func resourceApiGatewayApiConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"projects/(?P<project>[^/]+)/locations/global/apis/(?P<api>[^/]+)/configs/(?P<name>[^/]+)",
"(?P<project>[^/]+)/(?P<api>[^/]+)/(?P<name>[^/]+)",
"(?P<api>[^/]+)/(?P<name>[^/]+)",
"projects/(?P<project>[^/]+)/locations/global/apis/(?P<api>[^/]+)/configs/(?P<api_config_id>[^/]+)",
"(?P<project>[^/]+)/(?P<api>[^/]+)/(?P<api_config_id>[^/]+)",
"(?P<api>[^/]+)/(?P<api_config_id>[^/]+)",
}, d, config); err != nil {
return nil, err
}
Expand Down
12 changes: 4 additions & 8 deletions google-beta/resource_api_gateway_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ func resourceApiGatewayGatewayCreate(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error waiting to create Gateway: %s", err)
}

if err := d.Set("name", flattenApiGatewayGatewayName(opRes["name"], d, config)); err != nil {
return err
}

// This may have caused the ID to update - update it if so.
id, err = replaceVars(d, config, "projects/{{project}}/locations/{{region}}/gateways/{{gateway_id}}")
if err != nil {
Expand Down Expand Up @@ -367,10 +363,10 @@ func resourceApiGatewayGatewayDelete(d *schema.ResourceData, meta interface{}) e
func resourceApiGatewayGatewayImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/gateways/(?P<name>[^/]+)",
"(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)",
"(?P<region>[^/]+)/(?P<name>[^/]+)",
"(?P<name>[^/]+)",
"projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/gateways/(?P<gateway_id>[^/]+)",
"(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<gateway_id>[^/]+)",
"(?P<region>[^/]+)/(?P<gateway_id>[^/]+)",
"(?P<gateway_id>[^/]+)",
}, d, config); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_gke_hub_feature_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/api_gateway_api.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ This resource provides the following
Api can be imported using any of these accepted formats:

```
$ terraform import google_api_gateway_api.default projects/{{project}}/locations/global/apis/{{name}}
$ terraform import google_api_gateway_api.default {{project}}/{{name}}
$ terraform import google_api_gateway_api.default {{name}}
$ terraform import google_api_gateway_api.default projects/{{project}}/locations/global/apis/{{api_id}}
$ terraform import google_api_gateway_api.default {{project}}/{{api_id}}
$ terraform import google_api_gateway_api.default {{api_id}}
```

## User Project Overrides
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/api_gateway_api_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ This resource provides the following
ApiConfig can be imported using any of these accepted formats:

```
$ terraform import google_api_gateway_api_config.default projects/{{project}}/locations/global/apis/{{api}}/configs/{{name}}
$ terraform import google_api_gateway_api_config.default {{project}}/{{api}}/{{name}}
$ terraform import google_api_gateway_api_config.default {{api}}/{{name}}
$ terraform import google_api_gateway_api_config.default projects/{{project}}/locations/global/apis/{{api}}/configs/{{api_config_id}}
$ terraform import google_api_gateway_api_config.default {{project}}/{{api}}/{{api_config_id}}
$ terraform import google_api_gateway_api_config.default {{api}}/{{api_config_id}}
```

## User Project Overrides
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/api_gateway_api_iam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ exported:

For all import syntaxes, the "resource in question" can take any of the following forms:

* projects/{{project}}/locations/global/apis/{{name}}
* {{project}}/{{name}}
* {{name}}
* projects/{{project}}/locations/global/apis/{{api}}
* {{project}}/{{api}}
* {{api}}

Any variables not passed in the import command will be taken from the provider configuration.

Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/api_gateway_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ This resource provides the following
Gateway can be imported using any of these accepted formats:

```
$ terraform import google_api_gateway_gateway.default projects/{{project}}/locations/{{region}}/gateways/{{name}}
$ terraform import google_api_gateway_gateway.default {{project}}/{{region}}/{{name}}
$ terraform import google_api_gateway_gateway.default {{region}}/{{name}}
$ terraform import google_api_gateway_gateway.default {{name}}
$ terraform import google_api_gateway_gateway.default projects/{{project}}/locations/{{region}}/gateways/{{gateway_id}}
$ terraform import google_api_gateway_gateway.default {{project}}/{{region}}/{{gateway_id}}
$ terraform import google_api_gateway_gateway.default {{region}}/{{gateway_id}}
$ terraform import google_api_gateway_gateway.default {{gateway_id}}
```

## User Project Overrides
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/api_gateway_gateway_iam.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ exported:

For all import syntaxes, the "resource in question" can take any of the following forms:

* projects/{{project}}/locations/{{region}}/gateways/{{name}}
* {{project}}/{{region}}/{{name}}
* {{region}}/{{name}}
* {{name}}
* projects/{{project}}/locations/{{region}}/gateways/{{gateway}}
* {{project}}/{{region}}/{{gateway}}
* {{region}}/{{gateway}}
* {{gateway}}

Any variables not passed in the import command will be taken from the provider configuration.

Expand Down