Skip to content

Commit

Permalink
Ga secret manager (#3533)
Browse files Browse the repository at this point in the history
* GA secret manager

* Fixing some issues with ga version

* GA datasource as well
  • Loading branch information
slevenick authored May 20, 2020
1 parent 3ecd794 commit 1999d48
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 35 deletions.
7 changes: 4 additions & 3 deletions products/secretmanager/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
name: SecretManager
display_name: Secret Manager
versions:
- !ruby/object:Api::Product::Version
name: ga
base_url: https://secretmanager.googleapis.com/v1/
- !ruby/object:Api::Product::Version
name: beta
base_url: https://secretmanager.googleapis.com/v1beta1/
Expand All @@ -27,7 +30,6 @@ apis_required:
objects:
- !ruby/object:Api::Resource
name: Secret
min_version: beta
self_link: projects/{{project}}/secrets/{{secret_id}}
base_url: projects/{{project}}/secrets
create_url: projects/{{project}}/secrets?secretId={{secret_id}}
Expand All @@ -38,7 +40,7 @@ objects:
method_name_separator: ':'
exclude: false
references: !ruby/object:Api::Resource::ReferenceLinks
api: 'https://cloud.google.com/secret-manager/docs/reference/rest/v1beta1/projects.secrets'
api: 'https://cloud.google.com/secret-manager/docs/reference/rest/v1/projects.secrets'
description: |
A Secret is a logical secret whose value and versions can be accessed.
parameters:
Expand Down Expand Up @@ -114,7 +116,6 @@ objects:
The canonical IDs of the location to replicate data. For example: "us-east1".
- !ruby/object:Api::Resource
name: SecretVersion
min_version: beta
base_url: '{{name}}'
self_link: '{{name}}'
create_url: '{{secret}}:addVersion'
Expand Down
4 changes: 1 addition & 3 deletions products/secretmanager/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "secret_config_basic"
primary_resource_id: "secret-basic"
primary_resource_name: "fmt.Sprintf(\"tf-test-test-secret-basic%s\", context[\"random_suffix\"])"
min_version: beta
primary_resource_name: "fmt.Sprintf(\"secret%s\", context[\"random_suffix\"])"
vars:
secret_id: "secret"
import_format: ["projects/{{project}}/secrets/{{secret_id}}"]
Expand All @@ -34,7 +33,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "secret_version_basic"
primary_resource_id: "secret-version-basic"
min_version: beta
vars:
secret_id: "secret-version"
data: "secret-data"
Expand Down
2 changes: 0 additions & 2 deletions templates/terraform/examples/secret_config_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
resource "google_secret_manager_secret" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta

secret_id = "<%= ctx[:vars]['secret_id'] %>"

labels = {
Expand Down
4 changes: 0 additions & 4 deletions templates/terraform/examples/secret_version_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
resource "google_secret_manager_secret" "secret-basic" {
provider = google-beta

secret_id = "<%= ctx[:vars]['secret_id'] %>"

labels = {
Expand All @@ -14,8 +12,6 @@ resource "google_secret_manager_secret" "secret-basic" {


resource "google_secret_manager_secret_version" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta

secret = google_secret_manager_secret.secret-basic.id

secret_data = "<%= ctx[:vars]['data'] %>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<% autogen_exception -%>
package google
<% unless version == "ga" -%>

import (
"fmt"
Expand Down Expand Up @@ -125,5 +124,3 @@ func dataSourceSecretManagerSecretVersionRead(d *schema.ResourceData, meta inter
d.SetId(time.Now().UTC().String())
return nil
}

<% end -%>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<% autogen_exception -%>
package google
<% unless version == "ga" -%>

import (
"errors"
Expand All @@ -19,7 +18,7 @@ func TestAccDatasourceSecretManagerSecretVersion_basic(t *testing.T) {

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
Providers: testAccProviders,
CheckDestroy: testAccCheckSecretManagerSecretVersionDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand All @@ -39,7 +38,7 @@ func TestAccDatasourceSecretManagerSecretVersion_latest(t *testing.T) {

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
Providers: testAccProviders,
CheckDestroy: testAccCheckSecretManagerSecretVersionDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -78,7 +77,6 @@ func testAccCheckDatasourceSecretManagerSecretVersion(n, expected string) resour
func testAccDatasourceSecretManagerSecretVersion_latest(randomString string) string {
return fmt.Sprintf(`
resource "google_secret_manager_secret" "secret-basic" {
provider = google-beta
secret_id = "tf-test-secret-version-%s"
labels = {
label = "my-label"
Expand All @@ -89,21 +87,18 @@ resource "google_secret_manager_secret" "secret-basic" {
}

resource "google_secret_manager_secret_version" "secret-version-basic-1" {
provider = google-beta
secret = google_secret_manager_secret.secret-basic.name
secret_data = "my-tf-test-secret-first"
}

resource "google_secret_manager_secret_version" "secret-version-basic-2" {
provider = google-beta
secret = google_secret_manager_secret.secret-basic.name
secret_data = "my-tf-test-secret-second"

depends_on = [google_secret_manager_secret_version.secret-version-basic-1]
}

data "google_secret_manager_secret_version" "latest" {
provider = google-beta
secret = google_secret_manager_secret_version.secret-version-basic-2.secret
}
`, randomString)
Expand All @@ -112,7 +107,6 @@ data "google_secret_manager_secret_version" "latest" {
func testAccDatasourceSecretManagerSecretVersion_basic(randomString string) string {
return fmt.Sprintf(`
resource "google_secret_manager_secret" "secret-basic" {
provider = google-beta
secret_id = "tf-test-secret-version-%s"
labels = {
label = "my-label"
Expand All @@ -123,16 +117,13 @@ resource "google_secret_manager_secret" "secret-basic" {
}

resource "google_secret_manager_secret_version" "secret-version-basic" {
provider = google-beta
secret = google_secret_manager_secret.secret-basic.name
secret_data = "my-tf-test-secret-%s"
}

data "google_secret_manager_secret_version" "basic" {
provider = google-beta
secret = google_secret_manager_secret_version.secret-version-basic.secret
version = 1
}
`, randomString, randomString)
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"fmt"
Expand Down Expand Up @@ -57,4 +56,3 @@ resource "google_secret_manager_secret" "secret-basic" {
}
`, context)
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"fmt"
Expand Down Expand Up @@ -99,5 +98,3 @@ resource "google_secret_manager_secret_version" "secret-version-basic" {
}
`, context)
}

<% end -%>
2 changes: 0 additions & 2 deletions third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ func Provider() terraform.ResourceProvider {
"google_project": dataSourceGoogleProject(),
"google_projects": dataSourceGoogleProjects(),
"google_project_organization_policy": dataSourceGoogleProjectOrganizationPolicy(),
<% unless version == 'ga' -%>
"google_secret_manager_secret_version": dataSourceSecretManagerSecretVersion(),
<% end -%>
"google_service_account": dataSourceGoogleServiceAccount(),
"google_service_account_access_token": dataSourceGoogleServiceAccountAccessToken(),
"google_service_account_key": dataSourceGoogleServiceAccountKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ description: |-

# google\_secret\_manager\_secret\_version

Get a Secret Manager secret's version. For more information see the [official documentation](https://cloud.google.com/secret-manager/docs/) and [API](https://cloud.google.com/secret-manager/docs/reference/rest/v1beta1/projects.secrets.versions).
Get a Secret Manager secret's version. For more information see the [official documentation](https://cloud.google.com/secret-manager/docs/) and [API](https://cloud.google.com/secret-manager/docs/reference/rest/v1/projects.secrets.versions).

## Example Usage

```hcl
data "google_secret_manager_secret_version" "basic" {
provider = google-beta
secret = "my-secret"
}
```
Expand Down

0 comments on commit 1999d48

Please sign in to comment.