@@ -6,6 +6,7 @@ package vaultsecrets_test
66import (
77 "fmt"
88 "os"
9+ "strings"
910 "testing"
1011
1112 "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service"
@@ -17,11 +18,15 @@ import (
1718)
1819
1920func TestAccVaultSecretsResourceApp (t * testing.T ) {
20- appName1 := generateRandomSlug ()
21- appName2 := generateRandomSlug ()
22-
23- description1 := "my description 1"
24- description2 := "my description 2"
21+ var (
22+ integrationName1 = generateRandomSlug ()
23+ appName1 = generateRandomSlug ()
24+ appName2 = generateRandomSlug ()
25+ description1 = "my description 1"
26+ description2 = "my description 2"
27+ syncName = generateRandomSlug ()
28+ gitLabToken = checkRequiredEnvVarOrFail (t , "GITLAB_ACCESS_TOKEN" )
29+ )
2530
2631 resource .Test (t , resource.TestCase {
2732 ProtoV6ProviderFactories : acctest .ProtoV6ProviderFactories ,
@@ -30,21 +35,50 @@ func TestAccVaultSecretsResourceApp(t *testing.T) {
3035 {
3136 Config : appConfig (appName1 , description1 ),
3237 Check : resource .ComposeTestCheckFunc (
33- appCheckFunc (appName1 , description1 )... ,
38+ appCheckFunc (appName1 , description1 , nil )... ,
3439 ),
3540 },
3641 // Changing an immutable field causes a recreation
3742 {
3843 Config : appConfig (appName2 , description1 ),
3944 Check : resource .ComposeTestCheckFunc (
40- appCheckFunc (appName2 , description1 )... ,
45+ appCheckFunc (appName2 , description1 , nil )... ,
4146 ),
4247 },
4348 // Changing mutable fields causes an update
4449 {
4550 Config : appConfig (appName2 , description2 ),
4651 Check : resource .ComposeTestCheckFunc (
47- appCheckFunc (appName2 , description2 )... ,
52+ appCheckFunc (appName2 , description2 , nil )... ,
53+ ),
54+ },
55+ // Changing the sync_names causes an update
56+ {
57+ Config : fmt .Sprintf (`
58+ resource "hcp_vault_secrets_integration" "acc_test" {
59+ name = %q
60+ capabilities = ["SYNC"]
61+ provider_type = "gitlab"
62+ gitlab_access = {
63+ token = %q
64+ }
65+ }
66+ resource "hcp_vault_secrets_sync" "gitlab_sync" {
67+ name = %q
68+ integration_name = hcp_vault_secrets_integration.acc_test.name
69+ gitlab_config {
70+ scope = "PROJECT"
71+ project_id = "1234"
72+ }
73+ }
74+ resource "hcp_vault_secrets_app" "acc_test_app" {
75+ app_name = %q
76+ description = %q
77+ sync_names = [hcp_vault_secrets_sync.gitlab_sync.name]
78+ }
79+ ` , integrationName1 , gitLabToken , syncName , appName2 , description2 ),
80+ Check : resource .ComposeTestCheckFunc (
81+ appCheckFunc (appName2 , description2 , []string {syncName })... ,
4882 ),
4983 },
5084 // Deleting the app out of band causes a recreation
@@ -63,7 +97,7 @@ func TestAccVaultSecretsResourceApp(t *testing.T) {
6397 },
6498 Config : appConfig (appName2 , description2 ),
6599 Check : resource .ComposeTestCheckFunc (
66- appCheckFunc (appName2 , description2 )... ,
100+ appCheckFunc (appName2 , description2 , nil )... ,
67101 ),
68102 PlanOnly : true ,
69103 ExpectNonEmptyPlan : true ,
@@ -87,7 +121,7 @@ func TestAccVaultSecretsResourceApp(t *testing.T) {
87121 },
88122 Config : appConfig (appName2 , description2 ),
89123 Check : resource .ComposeTestCheckFunc (
90- appCheckFunc (appName2 , description2 )... ,
124+ appCheckFunc (appName2 , description2 , nil )... ,
91125 ),
92126 ResourceName : "hcp_vault_secrets_app.acc_test_app" ,
93127 ImportStateId : appName2 ,
@@ -114,14 +148,19 @@ func appConfig(appName, description string) string {
114148 }` , appName , description )
115149}
116150
117- func appCheckFunc (appName , description string ) []resource.TestCheckFunc {
151+ func appCheckFunc (appName , description string , syncNames []string ) []resource.TestCheckFunc {
152+ formattedSyncs := ""
153+ if len (syncNames ) > 0 {
154+ formattedSyncs = fmt .Sprintf ("[%s]" , strings .Join (syncNames , "," ))
155+ }
118156 return []resource.TestCheckFunc {
119157 resource .TestCheckResourceAttrSet ("hcp_vault_secrets_app.acc_test_app" , "organization_id" ),
120158 resource .TestCheckResourceAttrSet ("hcp_vault_secrets_app.acc_test_app" , "id" ),
121159 resource .TestCheckResourceAttrSet ("hcp_vault_secrets_app.acc_test_app" , "resource_name" ),
122160 resource .TestCheckResourceAttr ("hcp_vault_secrets_app.acc_test_app" , "project_id" , os .Getenv ("HCP_PROJECT_ID" )),
123161 resource .TestCheckResourceAttr ("hcp_vault_secrets_app.acc_test_app" , "app_name" , appName ),
124162 resource .TestCheckResourceAttr ("hcp_vault_secrets_app.acc_test_app" , "description" , description ),
163+ resource .TestCheckResourceAttr ("hcp_vault_secrets_app.acc_test_app" , "sync_names" , formattedSyncs ),
125164 }
126165}
127166
0 commit comments