mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-04 17:51:11 +00:00
Make runtime configs importable
This commit is contained in:
parent
35e6885c75
commit
1acfc5484a
@ -17,6 +17,10 @@ func resourceRuntimeconfigConfig() *schema.Resource {
|
|||||||
Update: resourceRuntimeconfigConfigUpdate,
|
Update: resourceRuntimeconfigConfigUpdate,
|
||||||
Delete: resourceRuntimeconfigConfigDelete,
|
Delete: resourceRuntimeconfigConfigDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: resourceRuntimeconfigConfigImport,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": {
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@ -131,6 +135,20 @@ func resourceRuntimeconfigConfigDelete(d *schema.ResourceData, meta interface{})
|
|||||||
return nil
|
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
|
// 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).
|
// (e.g. projects/my-project/configs/my-config).
|
||||||
func resourceRuntimeconfigFullName(project, name string) string {
|
func resourceRuntimeconfigFullName(project, name string) string {
|
||||||
|
@ -30,6 +30,11 @@ func TestAccRuntimeconfigConfig_basic(t *testing.T) {
|
|||||||
testAccCheckRuntimeConfigDescription(&runtimeConfig, description),
|
testAccCheckRuntimeConfigDescription(&runtimeConfig, description),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: "google_runtimeconfig_config.foobar",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ func resourceRuntimeconfigVariable() *schema.Resource {
|
|||||||
Update: resourceRuntimeconfigVariableUpdate,
|
Update: resourceRuntimeconfigVariableUpdate,
|
||||||
Delete: resourceRuntimeconfigVariableDelete,
|
Delete: resourceRuntimeconfigVariableDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: resourceRuntimeconfigVariableImport,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": {
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@ -124,6 +128,20 @@ func resourceRuntimeconfigVariableDelete(d *schema.ResourceData, meta interface{
|
|||||||
return nil
|
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
|
// 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).
|
// config variable into a full name (e.g. projects/my-project/configs/my-config/variables/my-variable).
|
||||||
func resourceRuntimeconfigVariableFullName(project, config, name string) string {
|
func resourceRuntimeconfigVariableFullName(project, config, name string) string {
|
||||||
|
@ -34,6 +34,11 @@ func TestAccRuntimeconfigVariable_basic(t *testing.T) {
|
|||||||
testAccCheckRuntimeconfigVariableUpdateTime("google_runtimeconfig_variable.foobar"),
|
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"),
|
testAccCheckRuntimeconfigVariableUpdateTime("google_runtimeconfig_variable.foobar"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: "google_runtimeconfig_variable.foobar",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user