-
Notifications
You must be signed in to change notification settings - Fork 264
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 datasource `goog…
…le_parameter_manager_regional_parameter` (#12640) [upstream:9f506b9edc862aeb6c3bf280059c5539e684408c] Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
dd4bd8c
commit 487e68c
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
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,3 @@ | ||
```release-note:new-datasource | ||
`google_parameter_manager_regional_parameter` (beta) | ||
``` |
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
45 changes: 45 additions & 0 deletions
45
...eta/services/parametermanagerregional/data_source_parameter_manager_regional_parameter.go
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,45 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package parametermanagerregional | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" | ||
) | ||
|
||
func DataSourceParameterManagerRegionalRegionalParameter() *schema.Resource { | ||
|
||
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceParameterManagerRegionalRegionalParameter().Schema) | ||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "parameter_id") | ||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "location") | ||
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceParameterManagerRegionalRegionalParameterRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceParameterManagerRegionalRegionalParameterRead(d *schema.ResourceData, meta interface{}) error { | ||
id, err := tpgresource.ReplaceVars(d, meta.(*transport_tpg.Config), "projects/{{project}}/locations/{{location}}/parameters/{{parameter_id}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
err = resourceParameterManagerRegionalRegionalParameterRead(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 | ||
} |
60 changes: 60 additions & 0 deletions
60
...ervices/parametermanagerregional/data_source_parameter_manager_regional_parameter_test.go
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,60 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package parametermanagerregional_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" | ||
) | ||
|
||
func TestAccDataSourceParameterManagerRegionalRegionalParameter_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: testAccCheckParameterManagerRegionalRegionalParameterDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceParameterManagerRegionalRegionalParameter_basic(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
acctest.CheckDataSourceStateMatchesResourceState( | ||
"data.google_parameter_manager_regional_parameter.regional-parameter-datasource", | ||
"google_parameter_manager_regional_parameter.regional-parameter", | ||
), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceParameterManagerRegionalRegionalParameter_basic(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_parameter_manager_regional_parameter" "regional-parameter" { | ||
provider = google-beta | ||
parameter_id = "tf_test_parameter%{random_suffix}" | ||
location = "us-central1" | ||
format = "YAML" | ||
labels = { | ||
key1 = "val1" | ||
key2 = "val2" | ||
key3 = "val3" | ||
key4 = "val4" | ||
key5 = "val5" | ||
} | ||
} | ||
data "google_parameter_manager_regional_parameter" "regional-parameter-datasource" { | ||
provider = google-beta | ||
parameter_id = google_parameter_manager_regional_parameter.regional-parameter.parameter_id | ||
location = google_parameter_manager_regional_parameter.regional-parameter.location | ||
} | ||
`, context) | ||
} |
34 changes: 34 additions & 0 deletions
34
website/docs/d/parameter_manager_regional_parameter.html.markdown
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,34 @@ | ||
--- | ||
subcategory: "Parameter Manager" | ||
description: |- | ||
Get information about a Parameter Manager Regional Parameter. | ||
--- | ||
|
||
# google_parameter_manager_regional_parameter | ||
|
||
Use this data source to get information about a Parameter Manager Regional 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_regional_parameter" "reg_parameter_datasource" { | ||
parameter_id = "foobar" | ||
location = "us-central1" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `parameter_id` - (required) The name of the regional parameter. | ||
|
||
* `location` - (required) The location of the regional parameter. eg us-central1 | ||
|
||
* `project` - (optional) The ID of the project in which the resource belongs. | ||
|
||
## Attributes Reference | ||
See [google_parameter_manager_regional_parameter](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/parameter_manager_regional_parameter) resource for details of all the available attributes. |