Skip to content

Commit

Permalink
feat: add runtimeconfig variable data source (GoogleCloudPlatform#4475)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonjbjelland authored and venkykuberan committed Feb 11, 2021
1 parent f3fe562 commit 98cf3a8
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 7 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ If you're generating the Terraform providers (`google` and `google-beta`),
you'll need to check out the repo(s) you're generating in your GOPATH. For
example:

```
```bash
git clone https://github.com/hashicorp/terraform-provider-google.git $GOPATH/src/github.com/hashicorp/terraform-provider-google
git clone https://github.com/hashicorp/terraform-provider-google-beta.git $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
```
Expand All @@ -86,7 +86,8 @@ Terraform provider are running on up to date copies of `master`.
Once you've prepared the target folders for the tools, run the following to
finish getting Magic Modules set up by installing the Ruby gems it needs to run:

```
```bash
cd mmv1
bundle install
```

Expand All @@ -102,7 +103,7 @@ Before making any changes, you can compile the "downstream" tool you're working
on by running the following command. If Magic Modules has been installed
correctly, you'll get no errors when you run a command:

```
```bash
bundle exec compiler -a -v "ga" -e {{tool}} -o "{{output_folder}}"
```

Expand All @@ -112,7 +113,7 @@ For Ansible and Inspec, wherever you have cloned those repositories.

For example, to generate Terraform:

```
```bash
bundle exec compiler -a -v "ga" -e terraform -o "$GOPATH/src/github.com/hashicorp/terraform-provider-google"
```

Expand All @@ -126,7 +127,7 @@ Terraform is the only tool to handle Beta features right now; you can generate
`google-beta` by running the following, substitution `"beta"` for the version
and using the repository for the `google-beta` provider.

```
```bash
bundle exec compiler -a -v "beta" -e terraform -o "$GOPATH/src/github.com/hashicorp/terraform-provider-google-beta"
```

Expand Down Expand Up @@ -245,6 +246,7 @@ Once you've gotten approvals from the primary reviewer and the reviewers for
any affected tools, the primary reviewer will merge your changes.

## Glossary

The maintainers of the repository will tend to use specific jargon to describe
concepts related to Magic Modules; here's a quick reference of what some of
those terms are.
Expand Down
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 -%>
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 -%>
3 changes: 3 additions & 0 deletions mmv1/third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func Provider() *schema.Provider {
"google_project_organization_policy": dataSourceGoogleProjectOrganizationPolicy(),
"google_pubsub_topic": dataSourceGooglePubsubTopic(),
"google_runtimeconfig_config": dataSourceGoogleRuntimeconfigConfig(),
<% unless version == 'ga' -%>
"google_runtimeconfig_variable": dataSourceGoogleRuntimeconfigVariable(),
<% end -%>
"google_secret_manager_secret_version": dataSourceSecretManagerSecretVersion(),
"google_service_account": dataSourceGoogleServiceAccount(),
"google_service_account_access_token": dataSourceGoogleServiceAccountAccessToken(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data "google_runtimeconfig_config" "run-service" {

The following arguments are supported:

* `name` - (Required) The name of the Cloud Run Service.
* `name` - (Required) The name of the Runtime Configurator configuration.

- - -

Expand Down
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.
2 changes: 1 addition & 1 deletion tpgtools/overrides/runtimeconfig/variable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
function: runtimeconfigVariableImport
- type: PRE_CREATE_FUNCTION
details:
function: runtimeconfigVariableValidateTextOrValueSet
function: runtimeconfigVariableValidateTextOrValueSet

0 comments on commit 98cf3a8

Please sign in to comment.