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 datasource google_parameter_manager_parameter #12639

Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
"google_oracle_database_cloud_vm_cluster": oracledatabase.DataSourceOracleDatabaseCloudVmCluster(),
"google_organization": resourcemanager.DataSourceGoogleOrganization(),
{{- if ne $.TargetVersionName "ga" }}
"google_parameter_manager_parameter": parametermanager.DataSourceParameterManagerParameter(),
"google_parameter_manager_regional_parameter": parametermanagerregional.DataSourceParameterManagerRegionalRegionalParameter(),
{{- end }}
"google_privateca_certificate_authority": privateca.DataSourcePrivatecaCertificateAuthority(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package parametermanager
{{ if ne $.TargetVersionName `ga` -}}

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)

func DataSourceParameterManagerParameter() *schema.Resource {

dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceParameterManagerParameter().Schema)
tpgresource.AddRequiredFieldsToSchema(dsSchema, "parameter_id")
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project")

return &schema.Resource{
Read: dataSourceParameterManagerParameterRead,
Schema: dsSchema,
}
}

func dataSourceParameterManagerParameterRead(d *schema.ResourceData, meta interface{}) error {
id, err := tpgresource.ReplaceVars(d, meta.(*transport_tpg.Config), "projects/{{"{{"}}project{{"}}"}}/locations/global/parameters/{{"{{"}}parameter_id{{"}}"}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
err = resourceParameterManagerParameterRead(d, meta)
if err != nil {
return err
}

if err := tpgresource.SetDataSourceLabels(d); err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}
return nil
}

{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package parametermanager_test
{{ if ne $.TargetVersionName `ga` -}}

import (
"testing"

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

func TestAccDataSourceParameterManagerParameter_basic(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: testAccCheckParameterManagerParameterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceParameterManagerParameter_basic(context),
Check: resource.ComposeTestCheckFunc(
acctest.CheckDataSourceStateMatchesResourceState(
"data.google_parameter_manager_parameter.parameter-datasource",
"google_parameter_manager_parameter.parameter",
),
),
},
},
})
}

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

labels = {
key1 = "val1"
key2 = "val2"
key3 = "val3"
key4 = "val4"
key5 = "val5"
}
}

data "google_parameter_manager_parameter" "parameter-datasource" {
provider = google-beta
parameter_id = google_parameter_manager_parameter.parameter.parameter_id
}
`, context)
}

{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
subcategory: "Parameter Manager"
description: |-
Get information about a Parameter Manager Parameter.
---

# google_parameter_manager_parameter

Use this data source to get information about a Parameter Manager Parameter.

~> **Warning:** This datasource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta datasources.

## Example Usage

```hcl
data "google_parameter_manager_parameter" "parameter_datasource" {
parameter_id = "foobar"
}
```

## Argument Reference

The following arguments are supported:

* `parameter_id` - (required) The name of the parameter.

* `project` - (optional) The ID of the project in which the resource belongs.

## Attributes Reference
See [google_parameter_manager_parameter](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/parameter_manager_parameter) resource for details of all the available attributes.
Loading