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

Make runtime configs importable #2054

Merged
merged 2 commits into from
Sep 20, 2018
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
18 changes: 18 additions & 0 deletions google/resource_runtimeconfig_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func resourceRuntimeconfigConfig() *schema.Resource {
Update: resourceRuntimeconfigConfigUpdate,
Delete: resourceRuntimeconfigConfigDelete,

Importer: &schema.ResourceImporter{
State: resourceRuntimeconfigConfigImport,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -131,6 +135,20 @@ func resourceRuntimeconfigConfigDelete(d *schema.ResourceData, meta interface{})
return nil
}

func resourceRuntimeconfigConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{"projects/(?P<project>[^/]+)/configs/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)

// Replace import id for the resource id
id, err := replaceVars(d, config, "projects/{{project}}/configs/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
}

// resourceRuntimeconfigFullName turns a given project and a 'short name' for a runtime config into a full name
// (e.g. projects/my-project/configs/my-config).
func resourceRuntimeconfigFullName(project, name string) string {
Expand Down
5 changes: 5 additions & 0 deletions google/resource_runtimeconfig_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func TestAccRuntimeconfigConfig_basic(t *testing.T) {
testAccCheckRuntimeConfigDescription(&runtimeConfig, description),
),
},
resource.TestStep{
ResourceName: "google_runtimeconfig_config.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
18 changes: 18 additions & 0 deletions google/resource_runtimeconfig_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func resourceRuntimeconfigVariable() *schema.Resource {
Update: resourceRuntimeconfigVariableUpdate,
Delete: resourceRuntimeconfigVariableDelete,

Importer: &schema.ResourceImporter{
State: resourceRuntimeconfigVariableImport,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -124,6 +128,20 @@ func resourceRuntimeconfigVariableDelete(d *schema.ResourceData, meta interface{
return nil
}

func resourceRuntimeconfigVariableImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{"projects/(?P<project>[^/]+)/configs/(?P<parent>[^/]+)/variables/(?P<name>[^/]+)", "(?P<parent>[^/]+)/(?P<name>[^/]+)"}, d, config)

// Replace import id for the resource id
id, err := replaceVars(d, config, "projects/{{project}}/configs/{{parent}}/variables/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
}

// resourceRuntimeconfigVariableFullName turns a given project, runtime config name, and a 'short name' for a runtime
// config variable into a full name (e.g. projects/my-project/configs/my-config/variables/my-variable).
func resourceRuntimeconfigVariableFullName(project, config, name string) string {
Expand Down
10 changes: 10 additions & 0 deletions google/resource_runtimeconfig_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func TestAccRuntimeconfigVariable_basic(t *testing.T) {
testAccCheckRuntimeconfigVariableUpdateTime("google_runtimeconfig_variable.foobar"),
),
},
resource.TestStep{
ResourceName: "google_runtimeconfig_variable.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -94,6 +99,11 @@ func TestAccRuntimeconfigVariable_basicValue(t *testing.T) {
testAccCheckRuntimeconfigVariableUpdateTime("google_runtimeconfig_variable.foobar"),
),
},
resource.TestStep{
ResourceName: "google_runtimeconfig_variable.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/runtimeconfig_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ is not provided, the provider project is used.

* `description` - (Optional) The description to associate with the runtime
config.

## Import

Runtime Configs can be imported using the `name` or full config name, e.g.

```
$ terraform import google_runtimeconfig_config.myconfig myconfig
```
```
$ terraform import google_runtimeconfig_config.myconfig projects/my-gcp-project/configs/myconfig
```
When importing using only the name, the provider project must be set.
12 changes: 12 additions & 0 deletions website/docs/r/runtimeconfig_variable.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ exported:
* `update_time` - (Computed) The timestamp in RFC3339 UTC "Zulu" format,
accurate to nanoseconds, representing when the variable was last updated.
Example: "2016-10-09T12:33:37.578138407Z".

## Import

Runtime Config Variables can be imported using the `name` or full variable name, e.g.

```
$ terraform import google_runtimeconfig_variable.myvariable myconfig/myvariable
```
```
$ terraform import google_runtimeconfig_variable.myvariable projects/my-gcp-project/configs/myconfig/variables/myvariable
```
When importing using only the name, the provider project must be set.