forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add runtimeconfig variable data source (GoogleCloudPlatform#4475)
- Loading branch information
1 parent
f3fe562
commit 98cf3a8
Showing
7 changed files
with
147 additions
and
7 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
36 changes: 36 additions & 0 deletions
36
mmv1/third_party/terraform/data_sources/data_source_runtimeconfig_variable.go.erb
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,36 @@ | ||
<% autogen_exception -%> | ||
package google | ||
|
||
<% unless version == 'ga' -%> | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleRuntimeconfigVariable() *schema.Resource { | ||
|
||
dsSchema := datasourceSchemaFromResourceSchema(resourceRuntimeconfigVariable().Schema) | ||
addRequiredFieldsToSchema(dsSchema, "name") | ||
addRequiredFieldsToSchema(dsSchema, "parent") | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceGoogleRuntimeconfigVariableRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceGoogleRuntimeconfigVariableRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
id, err := replaceVars(d, config, "projects/{{project}}/configs/{{parent}}/variables/{{name}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
return resourceRuntimeconfigVariableRead(d, meta) | ||
} | ||
|
||
<% end -%> |
58 changes: 58 additions & 0 deletions
58
mmv1/third_party/terraform/tests/data_source_runtimeconfig_variable_test.go.erb
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,58 @@ | ||
<% autogen_exception -%> | ||
package google | ||
|
||
<% unless version == 'ga' -%> | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccRuntimeconfigVariableDatasource_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccRuntimeconfigDatasourceVariable(randString(t, 10), randString(t, 10), randString(t, 10)), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState("data.google_runtimeconfig_variable.default", "google_runtimeconfig_variable.default"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccRuntimeconfigDatasourceVariable(suffix string, name string, text string) string { | ||
return fmt.Sprintf(` | ||
resource "google_project_service" "default" { | ||
service = "runtimeconfig.googleapis.com" | ||
} | ||
|
||
resource "google_runtimeconfig_config" "default" { | ||
project = google_project_service.default.project | ||
name = "runtime-%s" | ||
description = "runtime-%s" | ||
depends_on = [ google_project_service.default ] | ||
} | ||
|
||
resource "google_runtimeconfig_variable" "default" { | ||
project = google_project_service.default.project | ||
parent = google_runtimeconfig_config.default.name | ||
name = "%s" | ||
text = "%s" | ||
} | ||
|
||
data "google_runtimeconfig_variable" "default" { | ||
project = google_project_service.default.project | ||
name = google_runtimeconfig_variable.default.name | ||
parent = google_runtimeconfig_config.default.name | ||
} | ||
`, suffix, suffix, name, text) | ||
} | ||
|
||
<% end -%> |
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
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
41 changes: 41 additions & 0 deletions
41
mmv1/third_party/terraform/website/docs/d/runtimeconfig_variable.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,41 @@ | ||
--- | ||
subcategory: "Runtime Configurator" | ||
layout: "google" | ||
page_title: "Google: google_runtimeconfig_variable" | ||
sidebar_current: "docs-google-datasource-runtimeconfig-variable" | ||
description: |- | ||
Get information about a Google Cloud RuntimeConfig varialbe. | ||
--- | ||
|
||
# google\_runtimeconfig\_variable | ||
|
||
To get more information about RuntimeConfigs, see: | ||
|
||
* [API documentation](https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs) | ||
* How-to Guides | ||
* [Runtime Configurator Fundamentals](https://cloud.google.com/deployment-manager/runtime-configurator/) | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_runtimeconfig_variable" "run-service" { | ||
parent = "my-service" | ||
name = "prod-variables/hostname" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the Runtime Configurator configuration. | ||
* `parent` - (Required) The name of the RuntimeConfig resource containing this variable. | ||
|
||
- - - | ||
|
||
* `project` - (Optional) The project in which the resource belongs. If it | ||
is not provided, the provider project is used. | ||
|
||
## Attributes Reference | ||
|
||
See [google_runtimeconfig_variable](https://www.terraform.io/docs/providers/google/r/runtimeconfig_variable.html#argument-reference) resource for details of the available attributes. |
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