Skip to content

Commit

Permalink
feat(DEW): import DEW resource, unit test and document.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zippo-Wang committed Nov 21, 2023
1 parent df09970 commit 784a947
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/data-sources/csms_secret_version.md
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.
2 changes: 2 additions & 0 deletions g42cloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ func Provider() *schema.Provider {
"g42cloud_dcs_maintainwindow": dcs.DataSourceDcsMaintainWindow(),
"g42cloud_dcs_product": deprecated.DataSourceDcsProductV1(),

"g42cloud_csms_secret_version": dew.DataSourceDewCsmsSecret(),

"g42cloud_dms_az": deprecated.DataSourceDmsAZ(),
"g42cloud_dms_product": dms.DataSourceDmsProduct(),
"g42cloud_dms_maintainwindow": dms.DataSourceDmsMaintainWindow(),
Expand Down
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)
}

0 comments on commit 784a947

Please sign in to comment.