Skip to content

Commit 591cf5b

Browse files
Codelaxremyleone
andauthored
feat(secret): add type field (#2698)
* feat(secret): add type field * update cassettes * add doc * remove extra code * add type test to secret_version * add cassette to exceptions * lint --------- Co-authored-by: Rémy Léone <[email protected]>
1 parent 2a024e6 commit 591cf5b

16 files changed

+7143
-4558
lines changed

docs/resources/secret.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The following arguments are supported:
4646
- `ttl` - (Optional) Time frame, from one second and up to one year, during which the secret's versions are valid. Has to be specified in [Go Duration format](https://pkg.go.dev/time#ParseDuration) (ex: "30m", "24h").
4747
- `expires_once_accessed` - (Optional) True if the secret version expires after a single user access.
4848
- `action` - (Required) Action to perform when the version of a secret expires. Available values can be found in [SDK constants](https://pkg.go.dev/github.com/scaleway/scaleway-sdk-go@master/api/secret/v1beta1#pkg-constants).
49+
- `type` - (Optional) Type of the secret. If not specified, the type is Opaque. Available values can be found in [SDK Constants](https://pkg.go.dev/github.com/scaleway/scaleway-sdk-go@master/api/secret/v1beta1#pkg-constants).
4950
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions)
5051
in which the resource exists.
5152
- `project_id` - (Optional) The project ID containing is the secret.

internal/acctest/validate_cassettes_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func exceptionsCassettesCases() map[string]struct{} {
2727
"../services/rdb/testdata/privilege-basic.cassette.yaml": {},
2828
"../services/object/testdata/object-bucket-destroy-force.cassette.yaml": {},
2929
"../services/secret/testdata/secret-protected.cassette.yaml": {},
30+
"../services/secret/testdata/secret-version-type.cassette.yaml": {},
3031
}
3132
}
3233

internal/services/secret/secret.go

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ func ResourceSecret() *schema.Resource {
7777
return filepath.Clean(oldValue) == filepath.Clean(newValue)
7878
},
7979
},
80+
"type": {
81+
ForceNew: true,
82+
Type: schema.TypeString,
83+
Optional: true,
84+
Default: secret.SecretTypeOpaque,
85+
ValidateDiagFunc: verify.ValidateEnum[secret.SecretType](),
86+
},
8087
"protected": {
8188
Type: schema.TypeBool,
8289
Optional: true,
@@ -125,6 +132,7 @@ func ResourceSecretCreate(ctx context.Context, d *schema.ResourceData, m interfa
125132
ProjectID: d.Get("project_id").(string),
126133
Name: d.Get("name").(string),
127134
Protected: d.Get("protected").(bool),
135+
Type: secret.SecretType(d.Get("type").(string)),
128136
}
129137

130138
rawTag, tagExist := d.GetOk("tags")
@@ -193,6 +201,7 @@ func ResourceSecretRead(ctx context.Context, d *schema.ResourceData, m interface
193201
_ = d.Set("path", secretResponse.Path)
194202
_ = d.Set("protected", secretResponse.Protected)
195203
_ = d.Set("ephemeral_policy", flattenEphemeralPolicy(secretResponse.EphemeralPolicy))
204+
_ = d.Set("type", secretResponse.Type)
196205

197206
return nil
198207
}

internal/services/secret/secret_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestAccSecret_Basic(t *testing.T) {
4343
resource.TestCheckResourceAttr("scaleway_secret.main", "tags.2", "terraform"),
4444
resource.TestCheckResourceAttr("scaleway_secret.main", "tags.#", "3"),
4545
resource.TestCheckResourceAttr("scaleway_secret.main", "ephemeral_policy.#", "0"),
46+
resource.TestCheckResourceAttr("scaleway_secret.main", "type", "opaque"),
4647
resource.TestCheckResourceAttrSet("scaleway_secret.main", "updated_at"),
4748
resource.TestCheckResourceAttrSet("scaleway_secret.main", "created_at"),
4849
acctest.CheckResourceAttrUUID("scaleway_secret.main", "id"),

0 commit comments

Comments
 (0)