-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,113 @@ | ||
// Copyright 2024 Canonical Ltd. | ||
// Licensed under the Apache License, Version 2.0, see LICENCE file for details. | ||
|
||
package provider | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
internaltesting "github.com/juju/terraform-provider-juju/internal/testing" | ||
) | ||
|
||
func TestAcc_ResourceSecretAccess_GrantRevoke(t *testing.T) { | ||
if os.Getenv(TestJujuAgentVersion) == "" { | ||
t.Errorf("%s is not set", TestJujuAgentVersion) | ||
} else if internaltesting.CompareVersions(os.Getenv(TestJujuAgentVersion), "3.3.0") < 0 { | ||
t.Skipf("%s is not set or is below 3.3.0", TestJujuAgentVersion) | ||
} | ||
|
||
modelName := acctest.RandomWithPrefix("tf-test-model") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: frameworkProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceSecretWithAccess(modelName, false), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("juju_secret_access.test_secret_access", "model", modelName), | ||
resource.TestCheckResourceAttr("juju_secret_access.test_secret_access", "applications.0", "jul"), | ||
), | ||
}, | ||
{ | ||
Config: testAccResourceSecretWithAccess(modelName, true), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("juju_secret_access.test_secret_access", "model", modelName), | ||
resource.TestCheckResourceAttr("juju_secret_access.test_secret_access", "applications.0", "jul"), | ||
resource.TestCheckResourceAttr("juju_secret_access.test_secret_access", "applications.1", "jul2"), | ||
), | ||
}, | ||
{ | ||
Config: testAccResourceSecretWithAccess(modelName, false), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("juju_secret_access.test_secret_access", "model", modelName), | ||
resource.TestCheckResourceAttr("juju_secret_access.test_secret_access", "applications.0", "jul"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourceSecretWithAccess(modelName string, allApplicationAccess bool) string { | ||
return internaltesting.GetStringFromTemplateWithData( | ||
"testAccResourceSecret", | ||
` | ||
resource "juju_model" "{{.ModelName}}" { | ||
name = "{{.ModelName}}" | ||
} | ||
resource "juju_application" "jul" { | ||
name = "jul" | ||
model = juju_model.{{.ModelName}}.name | ||
charm { | ||
name = "jameinel-ubuntu-lite" | ||
channel = "latest/stable" | ||
} | ||
units = 1 | ||
} | ||
resource "juju_application" "jul2" { | ||
name = "jul2" | ||
model = juju_model.{{.ModelName}}.name | ||
charm { | ||
name = "jameinel-ubuntu-lite" | ||
channel = "latest/stable" | ||
} | ||
units = 1 | ||
} | ||
resource "juju_secret" "test_secret" { | ||
model = juju_model.{{.ModelName}}.name | ||
name = "test_secret_name" | ||
value = { | ||
key1 = "value1" | ||
key2 = "value2" | ||
} | ||
info = "This is my secret" | ||
} | ||
resource "juju_secret_access" "test_secret_access" { | ||
model = juju_model.{{.ModelName}}.name | ||
{{- if .AllApplicationAccess }} | ||
applications = [ | ||
juju_application.jul.name, juju_application.jul2.name | ||
] | ||
{{- else }} | ||
applications = [ | ||
juju_application.jul.name | ||
] | ||
{{- end }} | ||
secret_id = juju_secret.test_secret.secret_id | ||
} | ||
`, internaltesting.TemplateData{ | ||
"ModelName": modelName, | ||
"AllApplicationAccess": allApplicationAccess, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters