@@ -26,7 +26,7 @@ import (
26
26
policyorganizationmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/policy/organization"
27
27
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy"
28
28
policykindsecurity "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/security"
29
- scoperesource "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/scope"
29
+ "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/scope"
30
30
testhelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/testing"
31
31
)
32
32
@@ -73,21 +73,21 @@ func TestAcceptanceForSecurityPolicyResource(t *testing.T) {
73
73
t .Skip ("KUBECONFIG env var is not set for cluster scoped security policy acceptance test" )
74
74
}
75
75
},
76
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .ClusterScope , policykindsecurity .BaselineRecipe ),
77
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .ClusterScope ),
76
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .ClusterScope , policykindsecurity .BaselineRecipe ),
77
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .ClusterScope ),
78
78
},
79
79
{
80
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .ClusterGroupScope , policykindsecurity .BaselineRecipe ),
81
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .ClusterGroupScope ),
80
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .ClusterGroupScope , policykindsecurity .BaselineRecipe ),
81
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .ClusterGroupScope ),
82
82
},
83
83
{
84
84
PreConfig : func () {
85
85
if testConfig .ScopeHelperResources .OrgID == "" {
86
86
t .Skip ("ORG_ID env var is not set for organization scoped security policy acceptance test" )
87
87
}
88
88
},
89
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .OrganizationScope , policykindsecurity .BaselineRecipe ),
90
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .OrganizationScope ),
89
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .OrganizationScope , policykindsecurity .BaselineRecipe ),
90
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .OrganizationScope ),
91
91
},
92
92
},
93
93
},
@@ -108,21 +108,21 @@ func TestAcceptanceForSecurityPolicyResource(t *testing.T) {
108
108
t .Skip ("KUBECONFIG env var is not set for cluster scoped security policy acceptance test" )
109
109
}
110
110
},
111
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .ClusterScope , policykindsecurity .CustomRecipe ),
112
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .ClusterScope ),
111
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .ClusterScope , policykindsecurity .CustomRecipe ),
112
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .ClusterScope ),
113
113
},
114
114
{
115
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .ClusterGroupScope , policykindsecurity .CustomRecipe ),
116
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .ClusterGroupScope ),
115
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .ClusterGroupScope , policykindsecurity .CustomRecipe ),
116
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .ClusterGroupScope ),
117
117
},
118
118
{
119
119
PreConfig : func () {
120
120
if testConfig .ScopeHelperResources .OrgID == "" {
121
121
t .Skip ("ORG_ID env var is not set for organization scoped security policy acceptance test" )
122
122
}
123
123
},
124
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .OrganizationScope , policykindsecurity .CustomRecipe ),
125
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .OrganizationScope ),
124
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .OrganizationScope , policykindsecurity .CustomRecipe ),
125
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .OrganizationScope ),
126
126
},
127
127
},
128
128
},
@@ -143,21 +143,21 @@ func TestAcceptanceForSecurityPolicyResource(t *testing.T) {
143
143
t .Skip ("KUBECONFIG env var is not set for cluster scoped security policy acceptance test" )
144
144
}
145
145
},
146
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .ClusterScope , policykindsecurity .StrictRecipe ),
147
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .ClusterScope ),
146
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .ClusterScope , policykindsecurity .StrictRecipe ),
147
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .ClusterScope ),
148
148
},
149
149
{
150
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .ClusterGroupScope , policykindsecurity .StrictRecipe ),
151
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .ClusterGroupScope ),
150
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .ClusterGroupScope , policykindsecurity .StrictRecipe ),
151
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .ClusterGroupScope ),
152
152
},
153
153
{
154
154
PreConfig : func () {
155
155
if testConfig .ScopeHelperResources .OrgID == "" {
156
156
t .Skip ("ORG_ID env var is not set for organization scoped security policy acceptance test" )
157
157
}
158
158
},
159
- Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (policy .OrganizationScope , policykindsecurity .StrictRecipe ),
160
- Check : testConfig .checkSecurityPolicyResourceAttributes (policy .OrganizationScope ),
159
+ Config : testConfig .getTestSecurityPolicyResourceBasicConfigValue (scope .OrganizationScope , policykindsecurity .StrictRecipe ),
160
+ Check : testConfig .checkSecurityPolicyResourceAttributes (scope .OrganizationScope ),
161
161
},
162
162
},
163
163
},
@@ -167,7 +167,7 @@ func TestAcceptanceForSecurityPolicyResource(t *testing.T) {
167
167
t .Log ("all security policy resource acceptance tests complete!" )
168
168
}
169
169
170
- func (testConfig * testAcceptanceConfig ) getTestSecurityPolicyResourceBasicConfigValue (scope policy .Scope , recipe policykindsecurity.Recipe ) string {
170
+ func (testConfig * testAcceptanceConfig ) getTestSecurityPolicyResourceBasicConfigValue (scope scope .Scope , recipe policykindsecurity.Recipe ) string {
171
171
helperBlock , scopeBlock := testConfig .ScopeHelperResources .GetTestPolicyResourceHelperAndScope (scope )
172
172
inputBlock := testConfig .getTestSecurityPolicyResourceInput (recipe )
173
173
@@ -357,29 +357,29 @@ func (testConfig *testAcceptanceConfig) getTestSecurityPolicyResourceInput(recip
357
357
}
358
358
359
359
// checkSecurityPolicyResourceAttributes checks for security policy creation along with meta attributes.
360
- func (testConfig * testAcceptanceConfig ) checkSecurityPolicyResourceAttributes (scope policy .Scope ) resource.TestCheckFunc {
360
+ func (testConfig * testAcceptanceConfig ) checkSecurityPolicyResourceAttributes (scopeType scope .Scope ) resource.TestCheckFunc {
361
361
var check = []resource.TestCheckFunc {
362
- testConfig .verifySecurityPolicyResourceCreation (scope ),
362
+ testConfig .verifySecurityPolicyResourceCreation (scopeType ),
363
363
resource .TestCheckResourceAttr (testConfig .SecurityPolicyResourceName , "name" , testConfig .SecurityPolicyName ),
364
364
}
365
365
366
- switch scope {
367
- case policy .ClusterScope :
366
+ switch scopeType {
367
+ case scope .ClusterScope :
368
368
check = append (check , resource .TestCheckResourceAttr (testConfig .SecurityPolicyResourceName , "scope.0.cluster.0.name" , testConfig .ScopeHelperResources .Cluster .Name ))
369
- case policy .ClusterGroupScope :
369
+ case scope .ClusterGroupScope :
370
370
check = append (check , resource .TestCheckResourceAttr (testConfig .SecurityPolicyResourceName , "scope.0.cluster_group.0.cluster_group" , testConfig .ScopeHelperResources .ClusterGroup .Name ))
371
- case policy .OrganizationScope :
371
+ case scope .OrganizationScope :
372
372
check = append (check , resource .TestCheckResourceAttr (testConfig .SecurityPolicyResourceName , "scope.0.organization.0.organization" , testConfig .ScopeHelperResources .OrgID ))
373
- case policy .UnknownScope :
374
- log .Printf ("[ERROR]: No valid scope type block found: minimum one valid scope type block is required among: %v. Please check the schema." , strings .Join (policy .ScopesAllowed [:], `, ` ))
373
+ case scope .UnknownScope :
374
+ log .Printf ("[ERROR]: No valid scope type block found: minimum one valid scope type block is required among: %v. Please check the schema." , strings .Join (scope .ScopesAllowed [:], `, ` ))
375
375
}
376
376
377
377
check = append (check , policy .MetaResourceAttributeCheck (testConfig .SecurityPolicyResourceName )... )
378
378
379
379
return resource .ComposeTestCheckFunc (check ... )
380
380
}
381
381
382
- func (testConfig * testAcceptanceConfig ) verifySecurityPolicyResourceCreation (scope policy .Scope ) resource.TestCheckFunc {
382
+ func (testConfig * testAcceptanceConfig ) verifySecurityPolicyResourceCreation (scopeType scope .Scope ) resource.TestCheckFunc {
383
383
return func (s * terraform.State ) error {
384
384
if testConfig .Provider == nil {
385
385
return fmt .Errorf ("provider not initialised" )
@@ -406,13 +406,13 @@ func (testConfig *testAcceptanceConfig) verifySecurityPolicyResourceCreation(sco
406
406
return errors .Wrap (err , "unable to set the context" )
407
407
}
408
408
409
- switch scope {
410
- case policy .ClusterScope :
409
+ switch scopeType {
410
+ case scope .ClusterScope :
411
411
fn := & policyclustermodel.VmwareTanzuManageV1alpha1ClusterPolicyFullName {
412
412
ClusterName : testConfig .ScopeHelperResources .Cluster .Name ,
413
- ManagementClusterName : scoperesource .AttachedValue ,
413
+ ManagementClusterName : scope .AttachedValue ,
414
414
Name : testConfig .SecurityPolicyName ,
415
- ProvisionerName : scoperesource .AttachedValue ,
415
+ ProvisionerName : scope .AttachedValue ,
416
416
}
417
417
418
418
resp , err := config .TMCConnection .ClusterPolicyResourceService .ManageV1alpha1ClusterPolicyResourceServiceGet (fn )
@@ -423,7 +423,7 @@ func (testConfig *testAcceptanceConfig) verifySecurityPolicyResourceCreation(sco
423
423
if resp == nil {
424
424
return errors .Wrapf (err , "cluster scoped security policy resource is empty, resource: %s" , testConfig .SecurityPolicyResourceName )
425
425
}
426
- case policy .ClusterGroupScope :
426
+ case scope .ClusterGroupScope :
427
427
fn := & policyclustergroupmodel.VmwareTanzuManageV1alpha1ClustergroupPolicyFullName {
428
428
ClusterGroupName : testConfig .ScopeHelperResources .ClusterGroup .Name ,
429
429
Name : testConfig .SecurityPolicyName ,
@@ -437,7 +437,7 @@ func (testConfig *testAcceptanceConfig) verifySecurityPolicyResourceCreation(sco
437
437
if resp == nil {
438
438
return errors .Wrapf (err , "cluster group scoped security policy resource is empty, resource: %s" , testConfig .SecurityPolicyResourceName )
439
439
}
440
- case policy .OrganizationScope :
440
+ case scope .OrganizationScope :
441
441
fn := & policyorganizationmodel.VmwareTanzuManageV1alpha1OrganizationPolicyFullName {
442
442
OrgID : testConfig .ScopeHelperResources .OrgID ,
443
443
Name : testConfig .SecurityPolicyName ,
@@ -451,8 +451,8 @@ func (testConfig *testAcceptanceConfig) verifySecurityPolicyResourceCreation(sco
451
451
if resp == nil {
452
452
return errors .Wrapf (err , "organization scoped security policy resource is empty, resource: %s" , testConfig .SecurityPolicyResourceName )
453
453
}
454
- case policy .UnknownScope :
455
- return errors .Errorf ("[ERROR]: No valid scope type block found: minimum one valid scope type block is required among: %v. Please check the schema." , strings .Join (policy .ScopesAllowed [:], `, ` ))
454
+ case scope .UnknownScope :
455
+ return errors .Errorf ("[ERROR]: No valid scope type block found: minimum one valid scope type block is required among: %v. Please check the schema." , strings .Join (scope .ScopesAllowed [:], `, ` ))
456
456
}
457
457
458
458
return nil
0 commit comments