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

Add support for parameter manager parameter resource google_parameter_manager_parameter #12630

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
117 changes: 117 additions & 0 deletions mmv1/products/parametermanager/Parameter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# 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: 'Parameter'
description: |
A Parameter resource is a logical parameter.
references:
guides:
api: 'https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters'
docs:
base_url: 'projects/{{project}}/locations/global/parameters'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will parameters ever be location-based? Or are they strictly limited to global forever?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API is regional and global is considered as a region ( so base URL can be parameterised)
However the URL for global and regional API endpoints vary:
Global: parametermanager.googleapis.com
Regional: parametermanager.**{location}.rep.**googleapis.com

@slevenick Just because of this we will have to make keep regional and global resources. Can these be combined?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, does the regional endpoint work for global? Like parametermanager.**global.rep.**googleapis.com?

If so, it should be easy to regionalize it now and allow global as a region.

Otherwise it should be possible, but may require some special casing. A lot of it depends on how you want to surface these resources to customers. Should they be separate resources in Terraform or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the regional endpoint work for global? Like parametermanager.**global.rep.**googleapis.com?

  • It will not for global only parametermanager.googleapis.com will work

Regarding separate resources: Given that we don't have any change in logic, I don't have a strong reason why we should have separate resources apart from segregating the endpoints.

self_link: 'projects/{{project}}/locations/global/parameters/{{parameter_id}}'
create_url: 'projects/{{project}}/locations/global/parameters?parameter_id={{parameter_id}}'
update_verb: 'PATCH'
update_mask: true
import_format:
- 'projects/{{project}}/locations/global/parameters/{{parameter_id}}'
timeouts:
insert_minutes: 20
update_minutes: 20
delete_minutes: 20
examples:
- name: 'parameter_config_basic'
primary_resource_id: 'parameter-basic'
vars:
parameter_id: 'parameter'
- name: 'parameter_with_format'
primary_resource_id: 'parameter-with-format'
vars:
parameter_id: 'parameter'
- name: 'parameter_with_labels'
primary_resource_id: 'parameter-with-labels'
vars:
parameter_id: 'parameter'
parameters:
- name: 'parameterId'
type: String
description: |
This must be unique within the project.
url_param_only: true
required: true
immutable: true
properties:
- name: 'name'
type: String
description: |
The resource name of the Parameter. Format:
`projects/{{project}}/locations/global/parameters/{{parameter_id}}`
output: true
- name: 'createTime'
type: String
description: |
The time at which the Parameter was created.
output: true
- name: 'updateTime'
type: String
description: |
The time at which the Parameter was updated.
output: true
- name: 'policyMember'
type: NestedObject
description: |
Policy member strings of a Google Cloud resource.
output: true
properties:
- name: 'iamPolicyUidPrincipal'
type: String
description: |
IAM policy binding member referring to a Google Cloud resource by system-assigned unique identifier.
If a resource is deleted and recreated with the same name, the binding will not be applicable to the
new resource. Format:
`principal://parametermanager.googleapis.com/projects/{{project}}/uid/locations/global/parameters/{{uid}}`
output: true
- name: 'iamPolicyNamePrincipal'
type: String
description: |
IAM policy binding member referring to a Google Cloud resource by user-assigned name. If a
resource is deleted and recreated with the same name, the binding will be applicable to the
new resource. Format:
`principal://parametermanager.googleapis.com/projects/{{project}}/name/locations/global/parameters/{{parameter_id}}`
output: true
- name: 'labels'
type: KeyValueLabels
description: |
The labels assigned to this Parameter.

Label keys must be between 1 and 63 characters long, have a UTF-8 encoding of maximum 128 bytes,
and must conform to the following PCRE regular expression: [\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}

Label values must be between 0 and 63 characters long, have a UTF-8 encoding of maximum 128 bytes,
and must conform to the following PCRE regular expression: [\p{Ll}\p{Lo}\p{N}_-]{0,63}

No more than 64 labels can be assigned to a given resource.

An object containing a list of "key": value pairs. Example:
{ "name": "wrench", "mass": "1.3kg", "count": "3" }.
- name: 'format'
type: Enum
description: |
The format type of the parameter resource. Default value is UNFORMATTED.
default_from_api: true
immutable: true
enum_values:
- 'UNFORMATTED'
- 'YAML'
- 'JSON'
23 changes: 23 additions & 0 deletions mmv1/products/parametermanager/product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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: 'ParameterManager'
display_name: 'Parameter Manager'
versions:
- name: 'ga'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this API is in a Pre-GA state, so we shouldn't add it to the GA provider at this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let's add this to beta provide only for now.

base_url: 'https://parametermanager.googleapis.com/v1/'
- name: 'beta'
base_url: 'https://parametermanager.googleapis.com/v1/'
scopes:
- 'https://www.googleapis.com/auth/cloud-platform'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "google_parameter_manager_parameter" "{{$.PrimaryResourceId}}" {
parameter_id = "{{index $.Vars "parameter_id"}}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "google_parameter_manager_parameter" "{{$.PrimaryResourceId}}" {
parameter_id = "{{index $.Vars "parameter_id"}}"
format = "JSON"
}
11 changes: 11 additions & 0 deletions mmv1/templates/terraform/examples/parameter_with_labels.tf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "google_parameter_manager_parameter" "{{$.PrimaryResourceId}}" {
parameter_id = "{{index $.Vars "parameter_id"}}"

labels = {
key1 = "val1"
key2 = "val2"
key3 = "val3"
key4 = "val4"
key5 = "val5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@ var ServicesListBeta = mapOf(
"displayName" to "Parallelstore",
"path" to "./google/services/parallelstore"
),
"parametermanager" to mapOf(
"name" to "parametermanager",
"displayName" to "Parametermanager",
"path" to "./google-beta/services/parametermanager"
),
"privateca" to mapOf(
"name" to "privateca",
"displayName" to "Privateca",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,11 @@ var ServicesListGa = mapOf(
"displayName" to "Parallelstore",
"path" to "./google/services/parallelstore"
),
"parametermanager" to mapOf(
"name" to "parametermanager",
"displayName" to "Parametermanager",
"path" to "./google/services/parametermanager"
),
"privateca" to mapOf(
"name" to "privateca",
"displayName" to "Privateca",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package parametermanager_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
)

func TestAccParameterManagerParameter_import(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.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckParameterManagerParameterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccParameterManagerParameter_import(context),
},
{
ResourceName: "google_parameter_manager_parameter.parameter-import",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "parameter_id", "terraform_labels"},
},
},
})
}

func testAccParameterManagerParameter_import(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_parameter_manager_parameter" "parameter-import" {
parameter_id = "tf_test_parameter%{random_suffix}"
format = "YAML"

labels = {
key1 = "val1"
key2 = "val2"
key3 = "val3"
key4 = "val4"
key5 = "val5"
}
}
`, context)
}

func TestAccParameterManagerParameter_labelsUpdate(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.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckParameterManagerParameterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccParameterManagerParameter_withoutLabels(context),
},
{
ResourceName: "google_parameter_manager_parameter.parameter-with-labels",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "parameter_id", "terraform_labels"},
},
{
Config: testAccParameterManagerParameter_labelsUpdate(context),
},
{
ResourceName: "google_parameter_manager_parameter.parameter-with-labels",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "parameter_id", "terraform_labels"},
},
{
Config: testAccParameterManagerParameter_labelsUpdateOther(context),
},
{
ResourceName: "google_parameter_manager_parameter.parameter-with-labels",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "parameter_id", "terraform_labels"},
},
{
Config: testAccParameterManagerParameter_withoutLabels(context),
},
{
ResourceName: "google_parameter_manager_parameter.parameter-with-labels",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "parameter_id", "terraform_labels"},
},
},
})
}

func testAccParameterManagerParameter_withoutLabels(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_parameter_manager_parameter" "parameter-with-labels" {
parameter_id = "tf_test_parameter%{random_suffix}"
format = "JSON"
}
`, context)
}

func testAccParameterManagerParameter_labelsUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_parameter_manager_parameter" "parameter-with-labels" {
parameter_id = "tf_test_parameter%{random_suffix}"
format = "JSON"

labels = {
key1 = "val1"
key2 = "val2"
key3 = "val3"
key4 = "val4"
key5 = "val5"
}
}
`, context)
}

func testAccParameterManagerParameter_labelsUpdateOther(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_parameter_manager_parameter" "parameter-with-labels" {
parameter_id = "tf_test_parameter%{random_suffix}"
format = "JSON"

labels = {
key1 = "val1"
key2 = "updateval2"
updatekey3 = "val3"
updatekey4 = "updateval4"
key6 = "val6"
}
}
`, context)
}
Loading