@@ -26,7 +26,7 @@ func TestDataSourceServiceBasic(t *testing.T) {
2626 resource .TestCheckResourceAttr (rootRef , "policies.#" , fmt .Sprintf ("%d" , len (basicService .Policies ))),
2727 resource .TestCheckResourceAttr (rootRef , "policies.0" , basicService .Policies [0 ]),
2828 resource .TestCheckResourceAttr (rootRef , "enforce" , "false" ),
29- resource .TestCheckResourceAttr (rootRef , "application_scopes.#" , fmt .Sprintf ("%v " , len (basicService .ApplicationScopes ))),
29+ resource .TestCheckResourceAttr (rootRef , "application_scopes.#" , fmt .Sprintf ("%d " , len (basicService .ApplicationScopes ))),
3030 resource .TestCheckResourceAttr (rootRef , "application_scopes.0" , basicService .ApplicationScopes [0 ]),
3131 resource .TestCheckResourceAttr (rootRef , "priority" , "100" ),
3232 resource .TestCheckResourceAttr (rootRef , "target" , basicService .MembershipRules .Target ),
@@ -38,12 +38,23 @@ func TestDataSourceServiceBasic(t *testing.T) {
3838 resource .TestCheckResourceAttrSet (rootRef , "lastupdate" ),
3939 resource .TestCheckResourceAttrSet (rootRef , "evaluated" ),
4040 resource .TestCheckResourceAttrSet (rootRef , "is_registered" ),
41+
42+ // Assert no local policies
43+ resource .TestCheckResourceAttr (rootRef , "local_policies.#" , "0" ),
4144 ),
4245 },
4346 },
4447 })
4548}
4649
50+ func getBasicServiceData () string {
51+ return getBasicServiceResource () + `
52+ data "aquasec_service" "test-svc" {
53+ name = aquasec_service.test-basic-svc.id
54+ policies = aquasec_service.test-basic-svc.policies
55+ }
56+ `
57+ }
4758func TestDataSourceServiceComplex (t * testing.T ) {
4859 t .Parallel ()
4960 rootRef := "data.aquasec_service.test-svc"
@@ -56,24 +67,32 @@ func TestDataSourceServiceComplex(t *testing.T) {
5667 {
5768 Config : getComplexServiceData (),
5869 Check : resource .ComposeAggregateTestCheckFunc (
59- resource .TestCheckResourceAttr (rootRef , "name" , complexService . Name ),
60- resource .TestCheckResourceAttr (rootRef , "description" , complexService . Description ),
70+ resource .TestCheckResourceAttr (rootRef , "name" , "test-complex-svc" ),
71+ resource .TestCheckResourceAttr (rootRef , "description" , "Test complex service" ),
6172 resource .TestCheckResourceAttr (rootRef , "monitoring" , "false" ),
62- resource .TestCheckResourceAttr (rootRef , "policies.#" , fmt .Sprintf ("%d" , len (complexService .Policies ))),
63- resource .TestCheckResourceAttr (rootRef , "policies.0" , complexService .Policies [0 ]),
64- resource .TestCheckResourceAttr (rootRef , "enforce" , fmt .Sprintf ("%v" , complexService .Enforce )),
65- resource .TestCheckResourceAttr (rootRef , "application_scopes.#" , fmt .Sprintf ("%d" , len (complexService .ApplicationScopes ))),
66- resource .TestCheckResourceAttr (rootRef , "application_scopes.0" , complexService .ApplicationScopes [0 ]),
67- resource .TestCheckResourceAttr (rootRef , "priority" , fmt .Sprintf ("%d" , complexService .MembershipRules .Priority )),
68- resource .TestCheckResourceAttr (rootRef , "target" , complexService .MembershipRules .Target ),
69- resource .TestCheckResourceAttr (rootRef , "scope_expression" , complexService .MembershipRules .Scope .Expression ),
70- resource .TestCheckResourceAttr (rootRef , "scope_variables.#" , fmt .Sprintf ("%v" , len (complexService .MembershipRules .Scope .Variables ))),
71- resource .TestCheckResourceAttr (rootRef , "scope_variables.0.attribute" , complexService .MembershipRules .Scope .Variables [0 ].Attribute ),
72- resource .TestCheckResourceAttr (rootRef , "scope_variables.0.value" , complexService .MembershipRules .Scope .Variables [0 ].Value ),
73- resource .TestCheckResourceAttr (rootRef , "scope_variables.1.attribute" , complexService .MembershipRules .Scope .Variables [1 ].Attribute ),
74- resource .TestCheckResourceAttr (rootRef , "scope_variables.1.value" , complexService .MembershipRules .Scope .Variables [1 ].Value ),
75- resource .TestCheckResourceAttr (rootRef , "scope_variables.2.attribute" , complexService .MembershipRules .Scope .Variables [2 ].Attribute ),
76- resource .TestCheckResourceAttr (rootRef , "scope_variables.2.value" , complexService .MembershipRules .Scope .Variables [2 ].Value ),
73+ resource .TestCheckResourceAttr (rootRef , "policies.#" , "2" ),
74+ resource .TestCheckResourceAttr (rootRef , "policies.0" , "local-policy-1" ),
75+ resource .TestCheckResourceAttr (rootRef , "policies.1" , "default" ),
76+ resource .TestCheckResourceAttr (rootRef , "local_policies.#" , "1" ),
77+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.name" , "local-policy-1" ),
78+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.type" , "access.control" ),
79+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.description" , "Local policy for testing" ),
80+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.block_metadata_service" , "true" ),
81+
82+ // Inbound Networks
83+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.inbound_networks.#" , "1" ),
84+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.inbound_networks.0.port_range" , "22-80" ),
85+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.inbound_networks.0.resource_type" , "anywhere" ),
86+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.inbound_networks.0.allow" , "true" ),
87+
88+ // Outbound Networks
89+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.outbound_networks.#" , "1" ),
90+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.outbound_networks.0.port_range" , "443" ),
91+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.outbound_networks.0.resource_type" , "anywhere" ),
92+ resource .TestCheckResourceAttr (rootRef , "local_policies.0.outbound_networks.0.allow" , "false" ),
93+
94+ resource .TestCheckResourceAttr (rootRef , "priority" , "1" ),
95+ resource .TestCheckResourceAttr (rootRef , "target" , "container" ),
7796 resource .TestCheckResourceAttr (rootRef , "author" , os .Getenv ("AQUA_USER" )),
7897 resource .TestCheckResourceAttrSet (rootRef , "containers_count" ),
7998 resource .TestCheckResourceAttrSet (rootRef , "lastupdate" ),
@@ -85,20 +104,11 @@ func TestDataSourceServiceComplex(t *testing.T) {
85104 })
86105}
87106
88- func getBasicServiceData () string {
89- return getBasicServiceResource () + fmt .Sprintf (`
90-
91- data "aquasec_service" "test-svc" {
92- name = aquasec_service.test-basic-svc.id
93- }
94- ` )
95- }
96-
97107func getComplexServiceData () string {
98108 return getComplexServiceResource () + fmt .Sprintf (`
99-
100109 data "aquasec_service" "test-svc" {
101110 name = aquasec_service.test-complex-svc.id
111+ policies = aquasec_service.test-complex-svc.policies
102112 }
103113` )
104114}
0 commit comments