-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DEW): import DEW resource, unit test and document.
- Loading branch information
1 parent
df09970
commit 784a947
Showing
3 changed files
with
116 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
subcategory: "Data Encryption Workshop (DEW)" | ||
--- | ||
|
||
# g42cloud_csms_secret_version | ||
|
||
Use this data source to query the version and plaintext of the CSMS(Cloud Secret Management Service) secret. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "g42cloud_csms_secret_version" "version_1" { | ||
secret_name = "your_secret_name" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to obtain the CSMS secrets. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `secret_name` - (Required, String) The name of the CSMS secret to query. | ||
|
||
* `version` - (Optional, String) The version ID of the CSMS secret version to query. | ||
If omitted, the latest version will be used. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `secret_text` - The plaintext of a secret in text format. | ||
|
||
* `kms_key_id` - The ID of the KMS CMK used for secret encryption. | ||
|
||
* `status` - The status of the CSMS secret version. | ||
|
||
* `created_at` - Time when the CSMS secret version created, in UTC format. |
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
73 changes: 73 additions & 0 deletions
73
g42cloud/services/acceptance/dew/data_source_g42cloud_csms_secret_version_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,73 @@ | ||
package dew | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/g42cloud-terraform/terraform-provider-g42cloud/g42cloud/services/acceptance" | ||
) | ||
|
||
func TestAccDewCsmsSecretVersion_basic(t *testing.T) { | ||
name := acceptance.RandomAccResourceName() | ||
resourceName := "data.g42cloud_csms_secret_version.version_1" | ||
|
||
dc := acceptance.InitDataSourceCheck(resourceName) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.TestAccPreCheck(t) }, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDewCsmsSecretVersion_basic(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(resourceName, "secret_name", name), | ||
resource.TestCheckResourceAttrSet(resourceName, "version"), | ||
resource.TestCheckResourceAttr(resourceName, "secret_text", "this is a password"), | ||
), | ||
}, | ||
{ | ||
Config: testAccDewCsmsSecretVersion_version(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(resourceName, "secret_name", name), | ||
resource.TestCheckResourceAttr(resourceName, "version", "v1"), | ||
resource.TestCheckResourceAttr(resourceName, "secret_text", "this is a password"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDewCsmsSecretVersion_basic(name string) string { | ||
return fmt.Sprintf(` | ||
resource "g42cloud_csms_secret" "secret_1" { | ||
name = "%s" | ||
secret_text = "this is a password" | ||
} | ||
data "g42cloud_csms_secret_version" "version_1" { | ||
secret_name = "%s" | ||
depends_on = [g42cloud_csms_secret.secret_1] | ||
} | ||
`, name, name) | ||
} | ||
|
||
func testAccDewCsmsSecretVersion_version(name string) string { | ||
return fmt.Sprintf(` | ||
resource "g42cloud_csms_secret" "secret_1" { | ||
name = "%s" | ||
secret_text = "this is a new password" | ||
} | ||
data "g42cloud_csms_secret_version" "version_1" { | ||
secret_name = "%s" | ||
version = "v1" | ||
depends_on = [g42cloud_csms_secret.secret_1] | ||
} | ||
`, name, name) | ||
} |