-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Secret Manager Secret Data Source (#4815)
Co-authored-by: upodroid <[email protected]> Co-authored-by: Cameron Thornton <[email protected]>
- Loading branch information
Showing
5 changed files
with
121 additions
and
167 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
mmv1/third_party/terraform/data_sources/data_source_secret_manager_secret.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,28 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceSecretManagerSecret() *schema.Resource { | ||
|
||
dsSchema := datasourceSchemaFromResourceSchema(resourceSecretManagerSecret().Schema) | ||
addRequiredFieldsToSchema(dsSchema, "secret_id") | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceSecretManagerSecretRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceSecretManagerSecretRead(d *schema.ResourceData, meta interface{}) error { | ||
id, err := replaceVars(d, meta.(*Config), "projects/{{project}}/secrets/{{secret_id}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
return resourceSecretManagerSecretRead(d, meta) | ||
} |
56 changes: 56 additions & 0 deletions
56
mmv1/third_party/terraform/tests/data_source_secret_manager_secret_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,56 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceSecretManagerSecret_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": randString(t, 10), | ||
} | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckSecretManagerSecretDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceSecretManagerSecret_basic(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState("data.google_secret_manager_secret.foo", "google_secret_manager_secret.bar"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceSecretManagerSecret_basic(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_secret_manager_secret" "bar" { | ||
secret_id = "tf-test-secret-%{random_suffix}" | ||
labels = { | ||
label = "my-label" | ||
} | ||
replication { | ||
user_managed { | ||
replicas { | ||
location = "us-central1" | ||
} | ||
replicas { | ||
location = "us-east1" | ||
} | ||
} | ||
} | ||
} | ||
data "google_secret_manager_secret" "foo" { | ||
secret_id = google_secret_manager_secret.bar.secret_id | ||
} | ||
`, context) | ||
} |
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
32 changes: 32 additions & 0 deletions
32
mmv1/third_party/terraform/website/docs/d/secret_manager_secret.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,32 @@ | ||
--- | ||
subcategory: "Secret Manager" | ||
layout: "google" | ||
page_title: "Google: google_secret_manager_secret" | ||
sidebar_current: "docs-google-datasource-secret-manager-secret" | ||
description: |- | ||
Get information about a Secret Manager Secret | ||
--- | ||
|
||
# google\_secret\_manager\_secret | ||
|
||
Use this data source to get information about a Secret Manager Secret | ||
|
||
## Example Usage | ||
|
||
|
||
```hcl | ||
data "google_secret_manager_secret" "qa" { | ||
secret_id = "foobar" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `secret_id` - (required) The name of the secret. | ||
|
||
* `project` - (optional) The ID of the project in which the resource belongs. | ||
|
||
## Attributes Reference | ||
See [google_secret_manager_secret](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/secret_manager_secret) resource for details of all 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