-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for parameter manager regional parameter version resource…
… `google_parameter_manager_regional_parameter_version` (#12642)
- Loading branch information
1 parent
91e9e24
commit d04d713
Showing
10 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
mmv1/products/parametermanagerregional/RegionalParameterVersion.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Copyright 2024 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- | ||
name: 'RegionalParameterVersion' | ||
api_resource_type_kind: ParameterVersion | ||
description: | | ||
A Regional Parameter Version resource that stores the actual value of the regional parameter. | ||
min_version: 'beta' | ||
references: | ||
guides: | ||
api: 'https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions' | ||
docs: | ||
base_url: '{{parameter}}/versions' | ||
self_link: '{{parameter}}/versions/{{parameter_version_id}}' | ||
create_url: '{{parameter}}/versions?parameter_version_id={{parameter_version_id}}' | ||
update_verb: 'PATCH' | ||
update_mask: true | ||
import_format: | ||
- 'projects/{{%project}}/locations/{{%location}}/parameters/{{%parameter_id}}/versions/{{%parameter_version_id}}' | ||
timeouts: | ||
insert_minutes: 20 | ||
update_minutes: 20 | ||
delete_minutes: 20 | ||
examples: | ||
- name: 'regional_parameter_version_basic' | ||
primary_resource_id: 'regional-parameter-version-basic' | ||
min_version: 'beta' | ||
vars: | ||
parameter_id: 'regional_parameter' | ||
parameter_version_id: 'regional_parameter_version' | ||
- name: 'regional_parameter_version_with_json_format' | ||
primary_resource_id: 'regional-parameter-version-with-json-format' | ||
min_version: 'beta' | ||
vars: | ||
parameter_id: 'regional_parameter' | ||
parameter_version_id: 'regional_parameter_version' | ||
data: 'parameter_data_json_format.yaml' | ||
test_vars_overrides: | ||
'data': '"./test-fixtures/parameter_data_json_format.json"' | ||
- name: 'regional_parameter_version_with_yaml_format' | ||
primary_resource_id: 'regional-parameter-version-with-yaml-format' | ||
min_version: 'beta' | ||
vars: | ||
parameter_id: 'regional_parameter' | ||
parameter_version_id: 'regional_parameter_version' | ||
data: 'parameter_data_yaml_format.yaml' | ||
test_vars_overrides: | ||
'data': '"./test-fixtures/parameter_data_yaml_format.yaml"' | ||
custom_code: | ||
pre_create: 'templates/terraform/pre_create/parameter_manager_regional_parameter_version.go.tmpl' | ||
custom_import: 'templates/terraform/custom_import/parameter_manager_regional_parameter_version.go.tmpl' | ||
parameters: | ||
- name: 'parameter' | ||
type: ResourceRef | ||
description: | | ||
Parameter Manager Regional Parameter resource. | ||
url_param_only: true | ||
required: true | ||
immutable: true | ||
resource: 'RegionalParameter' | ||
imports: 'name' | ||
- name: 'parameter_version_id' | ||
type: String | ||
description: | | ||
Version ID of the Regional Parameter Version Resource. This must be unique within the Regional Parameter. | ||
url_param_only: true | ||
required: true | ||
immutable: true | ||
- name: 'location' | ||
type: String | ||
description: | | ||
Location of Parameter Manager Regional parameter resource. | ||
url_param_only: true | ||
output: true | ||
properties: | ||
- name: 'name' | ||
type: String | ||
description: | | ||
The resource name of the Regional Parameter Version. Format: | ||
`projects/{{project}}/locations/{{location}}/parameters/{{parameter_id}}/versions/{{parameter_version_id}}` | ||
output: true | ||
- name: 'createTime' | ||
type: String | ||
description: | | ||
The time at which the Regional Parameter Version was created. | ||
output: true | ||
- name: 'updateTime' | ||
type: String | ||
description: | | ||
The time at which the Regional Parameter Version was updated. | ||
output: true | ||
- name: 'disabled' | ||
type: Boolean | ||
description: | | ||
The current state of Regional Parameter Version. This field is only applicable for updating Regional Parameter Version. | ||
- name: 'payload' | ||
type: NestedObject | ||
description: | | ||
The parameter payload of the RegionalParameterVersion. | ||
flatten_object: true | ||
required: true | ||
immutable: true | ||
custom_flatten: 'templates/terraform/custom_flatten/parameter_version_parameter_data.go.tmpl' | ||
properties: | ||
- name: 'parameter_data' | ||
type: String | ||
description: | | ||
The Regional Parameter data. | ||
api_name: data | ||
required: true | ||
immutable: true | ||
sensitive: true | ||
custom_expand: 'templates/terraform/custom_expand/base64.go.tmpl' |
28 changes: 28 additions & 0 deletions
28
mmv1/templates/terraform/custom_flatten/parameter_version_parameter_data.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{/* | ||
The license inside this block applies to this file | ||
Copyright 2024 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ -}} | ||
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if v == nil { | ||
return nil | ||
} | ||
original := v.(map[string]interface{}) | ||
if len(original) == 0 { | ||
return nil | ||
} | ||
transformed := make(map[string]interface{}) | ||
data, err := base64.StdEncoding.DecodeString(original["data"].(string)) | ||
if err != nil { | ||
return err | ||
} | ||
transformed["parameter_data"] = string(data) | ||
return []interface{}{transformed} | ||
} |
42 changes: 42 additions & 0 deletions
42
mmv1/templates/terraform/custom_import/parameter_manager_regional_parameter_version.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{/* | ||
The license inside this block applies to this file | ||
Copyright 2024 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ -}} | ||
config := meta.(*transport_tpg.Config) | ||
|
||
// current import_formats can't import fields with forward slashes in their value | ||
if err := tpgresource.ParseImportId([]string{"(?P<name>.+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
name := d.Get("name").(string) | ||
parameterRegex := regexp.MustCompile("(projects/.+/locations/.+/parameters/.+)/versions/.+$") | ||
versionRegex := regexp.MustCompile("projects/(.+)/locations/(.+)/parameters/(.+)/versions/(.+)$") | ||
|
||
parts := parameterRegex.FindStringSubmatch(name) | ||
if len(parts) != 2 { | ||
return nil, fmt.Errorf("Version name does not fit the format `projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/parameters/{{"{{"}}parameter_id{{"}}"}}/versions/{{"{{"}}parameter_version_id{{"}}"}}`") | ||
} | ||
if err := d.Set("parameter", parts[1]); err != nil { | ||
return nil, fmt.Errorf("Error setting parameter: %s", err) | ||
} | ||
|
||
parts = versionRegex.FindStringSubmatch(name) | ||
|
||
if err := d.Set("parameter_version_id", parts[4]); err != nil { | ||
return nil, fmt.Errorf("Error setting parameter_version_id: %s", err) | ||
} | ||
|
||
if err := d.Set("location", parts[2]); err != nil { | ||
return nil, fmt.Errorf("Error setting location: %s", err) | ||
} | ||
|
||
return []*schema.ResourceData{d}, nil |
12 changes: 12 additions & 0 deletions
12
mmv1/templates/terraform/examples/regional_parameter_version_basic.tf.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resource "google_parameter_manager_regional_parameter" "regional-parameter-basic" { | ||
provider = google-beta | ||
parameter_id = "{{index $.Vars "parameter_id"}}" | ||
location = "us-central1" | ||
} | ||
|
||
resource "google_parameter_manager_regional_parameter_version" "{{$.PrimaryResourceId}}" { | ||
provider = google-beta | ||
parameter = google_parameter_manager_regional_parameter.regional-parameter-basic.id | ||
parameter_version_id = "{{index $.Vars "parameter_version_id"}}" | ||
parameter_data = "regional-parameter-version-data" | ||
} |
13 changes: 13 additions & 0 deletions
13
mmv1/templates/terraform/examples/regional_parameter_version_with_json_format.tf.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "google_parameter_manager_regional_parameter" "regional-parameter-basic" { | ||
provider = google-beta | ||
parameter_id = "{{index $.Vars "parameter_id"}}" | ||
format = "JSON" | ||
location = "us-central1" | ||
} | ||
|
||
resource "google_parameter_manager_regional_parameter_version" "{{$.PrimaryResourceId}}" { | ||
provider = google-beta | ||
parameter = google_parameter_manager_regional_parameter.regional-parameter-basic.id | ||
parameter_version_id = "{{index $.Vars "parameter_version_id"}}" | ||
parameter_data = file("{{index $.Vars "data"}}") | ||
} |
13 changes: 13 additions & 0 deletions
13
mmv1/templates/terraform/examples/regional_parameter_version_with_yaml_format.tf.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "google_parameter_manager_regional_parameter" "regional-parameter-basic" { | ||
provider = google-beta | ||
parameter_id = "{{index $.Vars "parameter_id"}}" | ||
format = "YAML" | ||
location = "us-central1" | ||
} | ||
|
||
resource "google_parameter_manager_regional_parameter_version" "{{$.PrimaryResourceId}}" { | ||
provider = google-beta | ||
parameter = google_parameter_manager_regional_parameter.regional-parameter-basic.id | ||
parameter_version_id = "{{index $.Vars "parameter_version_id"}}" | ||
parameter_data = file("{{index $.Vars "data"}}") | ||
} |
29 changes: 29 additions & 0 deletions
29
mmv1/templates/terraform/pre_create/parameter_manager_regional_parameter_version.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{{/* | ||
The license inside this block applies to this file | ||
Copyright 2024 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ -}} | ||
parameter := d.Get("parameter").(string) | ||
parameterRegex := regexp.MustCompile("projects/(.+)/locations/(.+)/parameters/(.+)$") | ||
|
||
parts := parameterRegex.FindStringSubmatch(parameter) | ||
if len(parts) != 4 { | ||
return fmt.Errorf("parameter does not fit the format `projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/parameters/{{"{{"}}parameter{{"}}"}}`") | ||
} | ||
|
||
if err := d.Set("location", parts[2]); err!=nil { | ||
return fmt.Errorf("Error setting location: %s", err) | ||
} | ||
|
||
// Override the url after setting the location | ||
url, err = tpgresource.ReplaceVars(d, config, "{{"{{"}}ParameterManagerRegionalBasePath{{"}}"}}{{"{{"}}parameter{{"}}"}}/versions?parameter_version_id={{"{{"}}parameter_version_id{{"}}"}}") | ||
if err != nil { | ||
return err | ||
} |
89 changes: 89 additions & 0 deletions
89
...rametermanagerregional/resource_parameter_manager_regional_parameter_version_test.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package parametermanagerregional_test | ||
{{- if ne $.TargetVersionName "ga" }} | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
func TestAccParameterManagerRegionalRegionalParameterVersion_update(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), | ||
CheckDestroy: testAccCheckParameterManagerRegionalRegionalParameterVersionDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccParameterManagerRegionalRegionalParameterVersion_basic(context), | ||
}, | ||
{ | ||
ResourceName: "google_parameter_manager_regional_parameter_version.regional-parameter-version-update", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"parameter", "parameter_version_id"}, | ||
}, | ||
{ | ||
Config: testAccParameterManagerRegionalRegionalParameterVersion_update(context), | ||
}, | ||
{ | ||
ResourceName: "google_parameter_manager_regional_parameter_version.regional-parameter-version-update", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"parameter", "parameter_version_id"}, | ||
}, | ||
{ | ||
Config: testAccParameterManagerRegionalRegionalParameterVersion_basic(context), | ||
}, | ||
{ | ||
ResourceName: "google_parameter_manager_regional_parameter_version.regional-parameter-version-update", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"parameter", "parameter_version_id"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccParameterManagerRegionalRegionalParameterVersion_basic(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_parameter_manager_regional_parameter" "regional-parameter-update" { | ||
provider = google-beta | ||
parameter_id = "tf_test_regional_parameter%{random_suffix}" | ||
location = "us-central1" | ||
} | ||
|
||
resource "google_parameter_manager_regional_parameter_version" "regional-parameter-version-update" { | ||
provider = google-beta | ||
parameter = google_parameter_manager_regional_parameter.regional-parameter-update.id | ||
parameter_version_id = "tf_test_regional_parameter_version%{random_suffix}" | ||
parameter_data = "regional-parameter-version-data" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccParameterManagerRegionalRegionalParameterVersion_update(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_parameter_manager_regional_parameter" "regional-parameter-update" { | ||
provider = google-beta | ||
parameter_id = "tf_test_regional_parameter%{random_suffix}" | ||
location = "us-central1" | ||
} | ||
|
||
resource "google_parameter_manager_regional_parameter_version" "regional-parameter-version-update" { | ||
provider = google-beta | ||
parameter = google_parameter_manager_regional_parameter.regional-parameter-update.id | ||
parameter_version_id = "tf_test_regional_parameter_version%{random_suffix}" | ||
parameter_data = "regional-parameter-version-data" | ||
disabled = true | ||
} | ||
`, context) | ||
} | ||
|
||
{{ end }} |
4 changes: 4 additions & 0 deletions
4
...terraform/services/parametermanagerregional/test-fixtures/parameter_data_json_format.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"key1": "value1", | ||
"key2": "value2" | ||
} |
2 changes: 2 additions & 0 deletions
2
...terraform/services/parametermanagerregional/test-fixtures/parameter_data_yaml_format.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
key1: "value1" | ||
key2: "value2" |