Skip to content

Commit d9614d1

Browse files
authored
Merge pull request #2054 from migibert/make_runtime_config_importable
Make runtime configs importable
2 parents 87204bf + 25e1610 commit d9614d1

6 files changed

+75
-0
lines changed

google/resource_runtimeconfig_config.go

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ func resourceRuntimeconfigConfig() *schema.Resource {
1717
Update: resourceRuntimeconfigConfigUpdate,
1818
Delete: resourceRuntimeconfigConfigDelete,
1919

20+
Importer: &schema.ResourceImporter{
21+
State: resourceRuntimeconfigConfigImport,
22+
},
23+
2024
Schema: map[string]*schema.Schema{
2125
"name": {
2226
Type: schema.TypeString,
@@ -131,6 +135,20 @@ func resourceRuntimeconfigConfigDelete(d *schema.ResourceData, meta interface{})
131135
return nil
132136
}
133137

138+
func resourceRuntimeconfigConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
139+
config := meta.(*Config)
140+
parseImportId([]string{"projects/(?P<project>[^/]+)/configs/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
141+
142+
// Replace import id for the resource id
143+
id, err := replaceVars(d, config, "projects/{{project}}/configs/{{name}}")
144+
if err != nil {
145+
return nil, fmt.Errorf("Error constructing id: %s", err)
146+
}
147+
d.SetId(id)
148+
149+
return []*schema.ResourceData{d}, nil
150+
}
151+
134152
// resourceRuntimeconfigFullName turns a given project and a 'short name' for a runtime config into a full name
135153
// (e.g. projects/my-project/configs/my-config).
136154
func resourceRuntimeconfigFullName(project, name string) string {

google/resource_runtimeconfig_config_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ func TestAccRuntimeconfigConfig_basic(t *testing.T) {
3030
testAccCheckRuntimeConfigDescription(&runtimeConfig, description),
3131
),
3232
},
33+
resource.TestStep{
34+
ResourceName: "google_runtimeconfig_config.foobar",
35+
ImportState: true,
36+
ImportStateVerify: true,
37+
},
3338
},
3439
})
3540
}

google/resource_runtimeconfig_variable.go

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func resourceRuntimeconfigVariable() *schema.Resource {
1414
Update: resourceRuntimeconfigVariableUpdate,
1515
Delete: resourceRuntimeconfigVariableDelete,
1616

17+
Importer: &schema.ResourceImporter{
18+
State: resourceRuntimeconfigVariableImport,
19+
},
20+
1721
Schema: map[string]*schema.Schema{
1822
"name": {
1923
Type: schema.TypeString,
@@ -124,6 +128,20 @@ func resourceRuntimeconfigVariableDelete(d *schema.ResourceData, meta interface{
124128
return nil
125129
}
126130

131+
func resourceRuntimeconfigVariableImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
132+
config := meta.(*Config)
133+
parseImportId([]string{"projects/(?P<project>[^/]+)/configs/(?P<parent>[^/]+)/variables/(?P<name>[^/]+)", "(?P<parent>[^/]+)/(?P<name>[^/]+)"}, d, config)
134+
135+
// Replace import id for the resource id
136+
id, err := replaceVars(d, config, "projects/{{project}}/configs/{{parent}}/variables/{{name}}")
137+
if err != nil {
138+
return nil, fmt.Errorf("Error constructing id: %s", err)
139+
}
140+
d.SetId(id)
141+
142+
return []*schema.ResourceData{d}, nil
143+
}
144+
127145
// resourceRuntimeconfigVariableFullName turns a given project, runtime config name, and a 'short name' for a runtime
128146
// config variable into a full name (e.g. projects/my-project/configs/my-config/variables/my-variable).
129147
func resourceRuntimeconfigVariableFullName(project, config, name string) string {

google/resource_runtimeconfig_variable_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func TestAccRuntimeconfigVariable_basic(t *testing.T) {
3434
testAccCheckRuntimeconfigVariableUpdateTime("google_runtimeconfig_variable.foobar"),
3535
),
3636
},
37+
resource.TestStep{
38+
ResourceName: "google_runtimeconfig_variable.foobar",
39+
ImportState: true,
40+
ImportStateVerify: true,
41+
},
3742
},
3843
})
3944
}
@@ -94,6 +99,11 @@ func TestAccRuntimeconfigVariable_basicValue(t *testing.T) {
9499
testAccCheckRuntimeconfigVariableUpdateTime("google_runtimeconfig_variable.foobar"),
95100
),
96101
},
102+
resource.TestStep{
103+
ResourceName: "google_runtimeconfig_variable.foobar",
104+
ImportState: true,
105+
ImportStateVerify: true,
106+
},
97107
},
98108
})
99109
}

website/docs/r/runtimeconfig_config.html.markdown

+12
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ is not provided, the provider project is used.
3737

3838
* `description` - (Optional) The description to associate with the runtime
3939
config.
40+
41+
## Import
42+
43+
Runtime Configs can be imported using the `name` or full config name, e.g.
44+
45+
```
46+
$ terraform import google_runtimeconfig_config.myconfig myconfig
47+
```
48+
```
49+
$ terraform import google_runtimeconfig_config.myconfig projects/my-gcp-project/configs/myconfig
50+
```
51+
When importing using only the name, the provider project must be set.

website/docs/r/runtimeconfig_variable.html.markdown

+12
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,15 @@ exported:
7676
* `update_time` - (Computed) The timestamp in RFC3339 UTC "Zulu" format,
7777
accurate to nanoseconds, representing when the variable was last updated.
7878
Example: "2016-10-09T12:33:37.578138407Z".
79+
80+
## Import
81+
82+
Runtime Config Variables can be imported using the `name` or full variable name, e.g.
83+
84+
```
85+
$ terraform import google_runtimeconfig_variable.myvariable myconfig/myvariable
86+
```
87+
```
88+
$ terraform import google_runtimeconfig_variable.myvariable projects/my-gcp-project/configs/myconfig/variables/myvariable
89+
```
90+
When importing using only the name, the provider project must be set.

0 commit comments

Comments
 (0)