Skip to content

Commit 8ef00e4

Browse files
committed
simplify zone TF schema: remove scopes field
1 parent d9d8142 commit 8ef00e4

File tree

3 files changed

+34
-72
lines changed

3 files changed

+34
-72
lines changed

sysdig/resource_sysdig_secure_zone.go

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,23 @@ func resourceSysdigSecureZone() *schema.Resource {
4646
Type: schema.TypeString,
4747
Computed: true,
4848
},
49-
SchemaScopesKey: {
50-
Required: true,
49+
SchemaScopeKey: {
5150
Type: schema.TypeSet,
52-
MaxItems: 1,
51+
MinItems: 1,
52+
Required: true,
5353
Elem: &schema.Resource{
5454
Schema: map[string]*schema.Schema{
55-
SchemaScopeKey: {
56-
Type: schema.TypeSet,
57-
MinItems: 1,
55+
SchemaIDKey: {
56+
Type: schema.TypeInt,
57+
Computed: true,
58+
},
59+
SchemaTargetTypeKey: {
60+
Type: schema.TypeString,
5861
Required: true,
59-
Elem: &schema.Resource{
60-
Schema: map[string]*schema.Schema{
61-
SchemaIDKey: {
62-
Type: schema.TypeInt,
63-
Computed: true,
64-
},
65-
SchemaTargetTypeKey: {
66-
Type: schema.TypeString,
67-
Required: true,
68-
},
69-
SchemaRulesKey: {
70-
Type: schema.TypeString,
71-
Optional: true,
72-
},
73-
},
74-
},
62+
},
63+
SchemaRulesKey: {
64+
Type: schema.TypeString,
65+
Optional: true,
7566
},
7667
},
7768
},
@@ -158,7 +149,7 @@ func zoneRequestFromResourceData(d *schema.ResourceData) *v2.ZoneRequest {
158149
zoneRequest := &v2.ZoneRequest{
159150
Name: d.Get("name").(string),
160151
Description: d.Get("description").(string),
161-
Scopes: toZoneScopesRequest(d.Get("scopes").(*schema.Set)),
152+
Scopes: toZoneScopesRequest(d.Get(SchemaScopeKey).(*schema.Set)),
162153
}
163154

164155
if d.Id() != "" {
@@ -173,17 +164,13 @@ func zoneRequestFromResourceData(d *schema.ResourceData) *v2.ZoneRequest {
173164

174165
func toZoneScopesRequest(scopes *schema.Set) []v2.ZoneScope {
175166
var zoneScopes []v2.ZoneScope
176-
for _, scopeData := range scopes.List() {
177-
scopeMap := scopeData.(map[string]interface{})
178-
scopeSet := scopeMap[SchemaScopeKey].(*schema.Set)
179-
for _, attr := range scopeSet.List() {
180-
s := attr.(map[string]interface{})
181-
zoneScopes = append(zoneScopes, v2.ZoneScope{
182-
ID: s[SchemaIDKey].(int),
183-
TargetType: s[SchemaTargetTypeKey].(string),
184-
Rules: s[SchemaRulesKey].(string),
185-
})
186-
}
167+
for _, attr := range scopes.List() {
168+
s := attr.(map[string]interface{})
169+
zoneScopes = append(zoneScopes, v2.ZoneScope{
170+
ID: s[SchemaIDKey].(int),
171+
TargetType: s[SchemaTargetTypeKey].(string),
172+
Rules: s[SchemaRulesKey].(string),
173+
})
187174
}
188175
return zoneScopes
189176
}
@@ -197,28 +184,7 @@ func fromZoneScopesResponse(scopes []v2.ZoneScope) []interface{} {
197184
SchemaRulesKey: scope.Rules,
198185
})
199186
}
200-
response := []interface{}{
201-
map[string]interface{}{
202-
SchemaScopeKey: schema.NewSet(schema.HashResource(&schema.Resource{
203-
Schema: map[string]*schema.Schema{
204-
SchemaIDKey: {
205-
Type: schema.TypeInt,
206-
Computed: true,
207-
},
208-
SchemaTargetTypeKey: {
209-
Type: schema.TypeString,
210-
Required: true,
211-
},
212-
SchemaRulesKey: {
213-
Type: schema.TypeString,
214-
Optional: true,
215-
},
216-
},
217-
}), flattenedScopes),
218-
},
219-
}
220-
221-
return response
187+
return flattenedScopes
222188
}
223189

224190
func getZoneClient(clients SysdigClients) (v2.ZoneInterface, error) {

sysdig/resource_sysdig_secure_zone_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestAccSysdigZone_basic(t *testing.T) {
3030
resource.TestCheckResourceAttr("sysdig_secure_zone.test", "description", zoneDescription),
3131
resource.TestCheckTypeSetElemNestedAttrs(
3232
"sysdig_secure_zone.test",
33-
"scopes.*.scope.*",
33+
"scope.*",
3434
map[string]string{
3535
"target_type": "aws",
3636
"rules": "organization in (\"o1\", \"o2\") and account in (\"a1\", \"a2\")",
@@ -58,11 +58,9 @@ func zoneConfig(name, description string) string {
5858
resource "sysdig_secure_zone" "test" {
5959
name = "%s"
6060
description = "%s"
61-
scopes {
62-
scope {
63-
target_type = "aws"
64-
rules = "organization in (\"o1\", \"o2\") and account in (\"a1\", \"a2\")"
65-
}
61+
scope {
62+
target_type = "aws"
63+
rules = "organization in (\"o1\", \"o2\") and account in (\"a1\", \"a2\")"
6664
}
6765
}
6866
`, name, description)

website/docs/r/secure_zone.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ resource "sysdig_secure_zone" "example" {
1919
name = "example-zone"
2020
description = "An example Sysdig zone"
2121
22-
scopes {
23-
scope {
24-
target_type = "aws"
25-
rules = "organization in (\"o1\", \"o2\") and account in (\"a1\", \"a2\")"
26-
}
27-
28-
scope {
29-
target_type = "azure"
30-
rules = "organization contains \"o1\""
31-
}
22+
scope {
23+
target_type = "aws"
24+
rules = "organization in (\"o1\", \"o2\") and account in (\"a1\", \"a2\")"
25+
}
26+
27+
scope {
28+
target_type = "azure"
29+
rules = "organization contains \"o1\""
3230
}
3331
}
3432
```

0 commit comments

Comments
 (0)