mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
Merge pull request #2054 from migibert/make_runtime_config_importable
Make runtime configs importable
This commit is contained in:
commit
d9614d1664
@ -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,
|
||||
@ -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 {
|
||||
|
@ -30,6 +30,11 @@ func TestAccRuntimeconfigConfig_basic(t *testing.T) {
|
||||
testAccCheckRuntimeConfigDescription(&runtimeConfig, description),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
ResourceName: "google_runtimeconfig_config.foobar",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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 {
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user