-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Secret Manager Secret Data Source #4815
Merged
c2thorn
merged 7 commits into
GoogleCloudPlatform:master
from
borg-land:secret-manager-secret-ds
Sep 2, 2021
+122
−168
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5ca3b9
Fix TestAccVertexAIFeaturestore_vertexAiFeaturestoreExample
c2thorn 1697c42
add secret manager secret datasource
upodroid fb48fb0
fix typos
upodroid a2f90f2
fix typo in test
upodroid bcc3b66
fix typo
upodroid c5a5a03
add id to read function
upodroid 2266b94
fix bad copy paste
upodroid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test failed with a
no "id" found in attributes
errorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it similar to this? #4515 (comment)