Skip to content

Commit

Permalink
Merge pull request #53 from humanitec/fix-value-plan
Browse files Browse the repository at this point in the history
fix: value secret_ref shouldn't use state
  • Loading branch information
delca85 authored Oct 20, 2023
2 parents e381abc + 23b25cc commit 6a304c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"
cache: true
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.2.*'
terraform_version: "1.5.*"
terraform_wrapper: false
- run: make testacc
env:
Expand All @@ -27,6 +27,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"
cache: true
- run: go test -v -cover ./...
3 changes: 0 additions & 3 deletions internal/provider/resource_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,16 @@ func (r *ResourceValue) Schema(ctx context.Context, req resource.SchemaRequest,
MarkdownDescription: "Secret reference in the format of the target store. It can't be defined if value is defined.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"store": schema.StringAttribute{
MarkdownDescription: "Secret Store id. This can't be humanitec (our internal Secret Store). It's mandatory if ref is defined and can't be used if value is defined.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"version": schema.StringAttribute{
MarkdownDescription: "Only valid if ref is defined. It's the version of the secret as defined in the target store.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"value": schema.StringAttribute{
MarkdownDescription: "Value to store in the secret store. It can't be defined if ref is defined.",
Expand Down
33 changes: 28 additions & 5 deletions internal/provider/resource_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestAccResourceValueWithSecretValue(t *testing.T) {
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "key", key),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "description", "Example value with secret"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.ref", fmt.Sprintf("orgs/%s/apps/%s/secret_values/%s/.value", orgID, appID, key)),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.version", "1"),
),
},
// ImportState testing
Expand All @@ -78,6 +79,16 @@ func TestAccResourceValueWithSecretValue(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"secret_ref", "value"},
},
// Update
{
Config: testAccResourceVALUETestAccResourceValueSecret(appID, key, "Example value with secret changed"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "key", key),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "description", "Example value with secret changed"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.ref", fmt.Sprintf("orgs/%s/apps/%s/secret_values/%s/.value", orgID, appID, key)),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.version", "2"),
),
},
// Delete testing automatically occurs in TestCase
},
})
Expand All @@ -99,6 +110,7 @@ func TestAccResourceValueWithSecretValueSecretRefValue(t *testing.T) {
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "key", key),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "description", "Example value with secret set via secret reference value"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.ref", fmt.Sprintf("orgs/%s/apps/%s/secret_values/%s/.value", orgID, appID, key)),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.version", "1"),
),
},
// ImportState testing
Expand All @@ -111,6 +123,15 @@ func TestAccResourceValueWithSecretValueSecretRefValue(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"secret_ref"},
},
{
Config: testAccResourceVALUETestAccResourceValueSecretRefValue(appID, key, "Example value with secret set via secret reference value changed"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "key", key),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "description", "Example value with secret set via secret reference value changed"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.ref", fmt.Sprintf("orgs/%s/apps/%s/secret_values/%s/.value", orgID, appID, key)),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.version", "2"),
),
},
// Delete testing automatically occurs in TestCase
},
})
Expand All @@ -127,11 +148,12 @@ func TestAccResourceValueWithSecretRef(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccResourceVALUETestAccResourceValueSecretRef(appID, key, "path/to/secret", "Example value with secret reference"),
Config: testAccResourceVALUETestAccResourceValueSecretRef(appID, key, "path/to/secret", "Example value with secret reference", "1"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "key", key),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "description", "Example value with secret reference"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.ref", "path/to/secret"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.version", "1"),
),
},
// ImportState testing
Expand All @@ -146,10 +168,11 @@ func TestAccResourceValueWithSecretRef(t *testing.T) {
},
// Update and Read testing
{
Config: testAccResourceVALUETestAccResourceValueSecretRef(appID, key, "path/to/secret/changed", "Example value with secret reference changed"),
Config: testAccResourceVALUETestAccResourceValueSecretRef(appID, key, "path/to/secret/changed", "Example value with secret reference changed", "2"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "description", "Example value with secret reference changed"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.ref", "path/to/secret/changed"),
resource.TestCheckResourceAttr("humanitec_value.app_val_with_secret", "secret_ref.version", "2"),
),
},
// Update and Read testing
Expand Down Expand Up @@ -310,7 +333,7 @@ resource "humanitec_value" "app_env_val1" {
`, appID, envID, key, envID, key, description)
}

func testAccResourceVALUETestAccResourceValueSecretRef(appID, key, secretPath, description string) string {
func testAccResourceVALUETestAccResourceValueSecretRef(appID, key, secretPath, description, version string) string {
return fmt.Sprintf(`
resource "humanitec_application" "val_test" {
id = "%s"
Expand All @@ -326,10 +349,10 @@ resource "humanitec_value" "app_val_with_secret" {
secret_ref = {
ref = "%s"
store = "external-store-id"
version = "1"
version = "%s"
}
}
`, appID, key, description, secretPath)
`, appID, key, description, secretPath, version)
}

func testAccResourceVALUETestAccResourceValueSecret(appID, key, description string) string {
Expand Down

0 comments on commit 6a304c6

Please sign in to comment.