Skip to content
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

ENG-8693: Add value_type support to the Terraform provider #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ output "resource_value" {

### Optional

- `value_type` (String) The value type of the secret
- `visibility` (String) The visibility of the secret

### Read-Only
Expand Down
29 changes: 18 additions & 11 deletions doppler/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ type Secret struct {
}

type SecretValue struct {
Raw *string `json:"raw,omitempty"`
Computed *string `json:"computed,omitempty"`
RawVisibility *string `json:"rawVisibility,omitempty"`
ComputedVisibility *string `json:"computedVisibility,omitempty"`
Raw *string `json:"raw,omitempty"`
Computed *string `json:"computed,omitempty"`
RawVisibility *string `json:"rawVisibility,omitempty"`
ComputedVisibility *string `json:"computedVisibility,omitempty"`
RawValueType *ValueType `json:"rawValueType,omitempty"`
ComputedValueType *ValueType `json:"computedValueType,omitempty"`
}

func getSecretId(project string, config string, name string) string {
Expand All @@ -55,13 +57,18 @@ func parseSecretId(id string) (project string, config string, name string, err e
}

type ChangeRequest struct {
OriginalName *string `json:"originalName,omitempty"`
OriginalValue *string `json:"originalValue,omitempty"`
OriginalVisibility *string `json:"originalVisibility,omitempty"`
Name string `json:"name"`
Value *string `json:"value"`
ShouldDelete bool `json:"shouldDelete"`
Visibility string `json:"visibility,omitempty"`
OriginalName *string `json:"originalName,omitempty"`
OriginalValue *string `json:"originalValue,omitempty"`
OriginalVisibility *string `json:"originalVisibility,omitempty"`
Name string `json:"name"`
Value *string `json:"value"`
ShouldDelete bool `json:"shouldDelete"`
Visibility string `json:"visibility,omitempty"`
ValueType ValueType `json:"valueType,omitempty"`
}

type ValueType struct {
Type string `json:"type"`
}

type Project struct {
Expand Down
15 changes: 15 additions & 0 deletions doppler/resource_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ func resourceSecret() *schema.Resource {
Computed: true,
Sensitive: true,
},
"value_type": {
Description: "The value type of the secret",
Type: schema.TypeString,
christopher-bulger marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"string", "json", "json5", "boolean", "integer", "decimal", "email",
"url", "uuidv4", "cuid2", "ulid", "datetime8601", "date8601", "yaml",
}, false),
},
},
CustomizeDiff: customdiff.ComputedIf("computed", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool {
return d.HasChange("value")
Expand All @@ -75,11 +84,13 @@ func resourceSecretUpdate(ctx context.Context, d *schema.ResourceData, m interfa
name := d.Get("name").(string)
value := d.Get("value").(string)
visibility := d.Get("visibility").(string)
valueType := d.Get("value_type").(string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to adding this field to the resourceSecretUpdate func, we need to add it to resourceSecretRead to detect out-of-band changes to the secret value type. Unfortunately, the GET /v3/configs/config/secret endpoint that we use today doesn't have this data available. We can discuss in ENG-8693 how to go about adding it


changeRequest := ChangeRequest{
Name: name,
Value: &value,
Visibility: visibility,
ValueType: ValueType{Type: valueType},
}
if !d.IsNewResource() {
previousNameValue, _ := d.GetChange("name")
Expand Down Expand Up @@ -159,6 +170,10 @@ func resourceSecretRead(ctx context.Context, d *schema.ResourceData, m interface
return diag.FromErr(err)
}

if err = d.Set("value_type", secret.Value.RawValueType.Type); err != nil {
return diag.FromErr(err)
}

return diags
}

Expand Down
Loading