Skip to content

Commit

Permalink
Merge pull request #118 from DopplerHQ/christopher-bulger/ENG-8693-ad…
Browse files Browse the repository at this point in the history
…d-tf-value-type

ENG-8693: Add value_type support to the Terraform provider
  • Loading branch information
christopher-bulger authored Jan 29, 2025
2 parents dc86e7f + a07b769 commit b69f19c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
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
16 changes: 16 additions & 0 deletions doppler/resource_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func resourceSecret() *schema.Resource {
Computed: true,
Sensitive: true,
},
"value_type": {
Description: "The value type of the secret",
Type: schema.TypeString,
Optional: true,
Default: "string",
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 +85,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)

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 +171,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

0 comments on commit b69f19c

Please sign in to comment.