Skip to content

Commit 0a23517

Browse files
authored
Merge pull request #31 from arangodb-managed/oas-3355
oas-3355 | Added remote-inspection-allowed field to IPAllowList
2 parents 5bbf2c9 + 4e70845 commit 0a23517

File tree

4 files changed

+63
-41
lines changed

4 files changed

+63
-41
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/arangodb-managed/terraform-provider-oasis
22

33
require (
4-
github.com/arangodb-managed/apis v0.69.3
4+
github.com/arangodb-managed/apis v0.70.8
55
github.com/arangodb-managed/log-helper v0.2.0
66
github.com/gogo/protobuf v1.3.0
77
github.com/hashicorp/hcl v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFU
4545
github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
4646
github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0=
4747
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
48-
github.com/arangodb-managed/apis v0.69.3 h1:xgY3wtjzuMp9HDwXgmVkc6pA8f8mqpf3uYEqtrbUCUc=
49-
github.com/arangodb-managed/apis v0.69.3/go.mod h1:dSEV+DTPdZNH06qVqFWA+F0OcaL2ePGEo+odyMaU72Y=
48+
github.com/arangodb-managed/apis v0.70.8 h1:d6NqlgBdmt3l30kFc5NxyAJULD8wRtZGcrhcuqYFJiI=
49+
github.com/arangodb-managed/apis v0.70.8/go.mod h1:dSEV+DTPdZNH06qVqFWA+F0OcaL2ePGEo+odyMaU72Y=
5050
github.com/arangodb-managed/log-helper v0.2.0 h1:QK85i0a+mGM++wK625Oe1z4HuXhvaN3vR/Nunwa1qAA=
5151
github.com/arangodb-managed/log-helper v0.2.0/go.mod h1:WJogNCCXWM5OQx/ZYvtRo/1zwm/IpKj+f4QVtM8hNJw=
5252
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

pkg/resource_ip_allowlist.go

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
2020
// Author Gergely Brautigam
21+
// Author Ewout Prangsma
2122
//
2223

2324
package pkg
@@ -33,12 +34,13 @@ import (
3334

3435
const (
3536
// IP Allowlist fields
36-
ipNameFieldName = "name"
37-
ipProjectFieldName = "project"
38-
ipDescriptionFieldName = "description"
39-
ipCIDRRangeFieldName = "cidr_ranges"
40-
ipIsDeletedFieldName = "is_deleted"
41-
ipCreatedAtFieldName = "created_at"
37+
ipNameFieldName = "name"
38+
ipProjectFieldName = "project"
39+
ipDescriptionFieldName = "description"
40+
ipCIDRRangeFieldName = "cidr_ranges"
41+
ipIsDeletedFieldName = "is_deleted"
42+
ipCreatedAtFieldName = "created_at"
43+
ipRemoteInspectionAllowedFieldName = "remote_inspection_allowed"
4244
)
4345

4446
// resourceIPAllowlist defines the IPAllowlist terraform resource Schema.
@@ -72,6 +74,11 @@ func resourceIPAllowlist() *schema.Resource {
7274
Elem: &schema.Schema{Type: schema.TypeString},
7375
},
7476

77+
ipRemoteInspectionAllowedFieldName: {
78+
Type: schema.TypeBool,
79+
Optional: true,
80+
},
81+
7582
ipIsDeletedFieldName: {
7683
Type: schema.TypeBool,
7784
Computed: true,
@@ -112,10 +119,11 @@ func resourceIPAllowlistCreate(d *schema.ResourceData, m interface{}) error {
112119
// expandToIPAllowlist creates an ip allowlist oasis structure out of a terraform schema.
113120
func expandToIPAllowlist(d *schema.ResourceData, defaultProject string) (*security.IPAllowlist, error) {
114121
var (
115-
name string
116-
description string
117-
cidrRange []string
118-
err error
122+
name string
123+
description string
124+
cidrRange []string
125+
remoteInspectionAllowed bool
126+
err error
119127
)
120128
if v, ok := d.GetOk(ipNameFieldName); ok {
121129
name = v.(string)
@@ -130,6 +138,11 @@ func expandToIPAllowlist(d *schema.ResourceData, defaultProject string) (*securi
130138
} else {
131139
return nil, fmt.Errorf("failed to parse field %s", ipNameFieldName)
132140
}
141+
if v, ok := d.GetOk(ipRemoteInspectionAllowedFieldName); ok {
142+
remoteInspectionAllowed = v.(bool)
143+
} else {
144+
return nil, fmt.Errorf("failed to parse field %s", ipRemoteInspectionAllowedFieldName)
145+
}
133146
project := defaultProject
134147
if v, ok := d.GetOk(ipDescriptionFieldName); ok {
135148
description = v.(string)
@@ -140,10 +153,11 @@ func expandToIPAllowlist(d *schema.ResourceData, defaultProject string) (*securi
140153
}
141154

142155
return &security.IPAllowlist{
143-
Name: name,
144-
Description: description,
145-
ProjectId: project,
146-
CidrRanges: cidrRange,
156+
Name: name,
157+
Description: description,
158+
ProjectId: project,
159+
CidrRanges: cidrRange,
160+
RemoteInspectionAllowed: remoteInspectionAllowed,
147161
}, nil
148162
}
149163

@@ -165,12 +179,13 @@ func expandStringList(list []interface{}) ([]string, error) {
165179
// flattenIPAllowlistResource flattens the ip allowlist data into a map interface for easy storage.
166180
func flattenIPAllowlistResource(ip *security.IPAllowlist) map[string]interface{} {
167181
return map[string]interface{}{
168-
ipNameFieldName: ip.GetName(),
169-
ipProjectFieldName: ip.GetProjectId(),
170-
ipDescriptionFieldName: ip.GetDescription(),
171-
ipCIDRRangeFieldName: ip.GetCidrRanges(),
172-
ipCreatedAtFieldName: ip.GetCreatedAt().String(),
173-
ipIsDeletedFieldName: ip.GetIsDeleted(),
182+
ipNameFieldName: ip.GetName(),
183+
ipProjectFieldName: ip.GetProjectId(),
184+
ipDescriptionFieldName: ip.GetDescription(),
185+
ipCIDRRangeFieldName: ip.GetCidrRanges(),
186+
ipRemoteInspectionAllowedFieldName: ip.GetRemoteInspectionAllowed(),
187+
ipCreatedAtFieldName: ip.GetCreatedAt().String(),
188+
ipIsDeletedFieldName: ip.GetIsDeleted(),
174189
}
175190
}
176191

@@ -254,6 +269,9 @@ func resourceIPAllowlistUpdate(d *schema.ResourceData, m interface{}) error {
254269
}
255270
ipAllowlist.CidrRanges = cidrRange
256271
}
272+
if d.HasChange(ipRemoteInspectionAllowedFieldName) {
273+
ipAllowlist.RemoteInspectionAllowed = d.Get(ipRemoteInspectionAllowedFieldName).(bool)
274+
}
257275
res, err := securityc.UpdateIPAllowlist(client.ctxWithToken, ipAllowlist)
258276
if err != nil {
259277
client.log.Error().Err(err).Str("ipallowlist-id", d.Id()).Msg("Failed to update ip allowlist")

pkg/resource_ip_allowlist_test.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,37 @@ func TestResourceIPAllowlist(t *testing.T) {
7474

7575
func TestFlattenIPAllowlistResource(t *testing.T) {
7676
expected := map[string]interface{}{
77-
ipNameFieldName: "test-name",
78-
ipDescriptionFieldName: "test-description",
79-
ipCreatedAtFieldName: "1980-03-03T01:01:01Z",
80-
ipProjectFieldName: "123456789",
81-
ipCIDRRangeFieldName: []string{"1.2.3.4/32", "88.11.0.0/16", "0.0.0.0/0"},
82-
ipIsDeletedFieldName: false,
77+
ipNameFieldName: "test-name",
78+
ipDescriptionFieldName: "test-description",
79+
ipCreatedAtFieldName: "1980-03-03T01:01:01Z",
80+
ipProjectFieldName: "123456789",
81+
ipCIDRRangeFieldName: []string{"1.2.3.4/32", "88.11.0.0/16", "0.0.0.0/0"},
82+
ipRemoteInspectionAllowedFieldName: true,
83+
ipIsDeletedFieldName: false,
8384
}
8485

8586
created, _ := types.TimestampProto(time.Date(1980, 03, 03, 1, 1, 1, 0, time.UTC))
8687
cert := security.IPAllowlist{
87-
Name: "test-name",
88-
Description: "test-description",
89-
ProjectId: "123456789",
90-
CidrRanges: []string{"1.2.3.4/32", "88.11.0.0/16", "0.0.0.0/0"},
91-
CreatedAt: created,
92-
IsDeleted: false,
88+
Name: "test-name",
89+
Description: "test-description",
90+
ProjectId: "123456789",
91+
CidrRanges: []string{"1.2.3.4/32", "88.11.0.0/16", "0.0.0.0/0"},
92+
RemoteInspectionAllowed: true,
93+
CreatedAt: created,
94+
IsDeleted: false,
9395
}
9496
got := flattenIPAllowlistResource(&cert)
9597
assert.Equal(t, expected, got)
9698
}
9799

98100
func TestExpandingIPAllowlistResource(t *testing.T) {
99101
raw := map[string]interface{}{
100-
ipNameFieldName: "test-name",
101-
ipDescriptionFieldName: "test-description",
102-
ipProjectFieldName: "123456789",
103-
ipCIDRRangeFieldName: []interface{}{"1.2.3.4/32", "88.11.0.0/16", "0.0.0.0/0"},
104-
ipIsDeletedFieldName: false,
102+
ipNameFieldName: "test-name",
103+
ipDescriptionFieldName: "test-description",
104+
ipProjectFieldName: "123456789",
105+
ipCIDRRangeFieldName: []interface{}{"1.2.3.4/32", "88.11.0.0/16", "0.0.0.0/0"},
106+
ipRemoteInspectionAllowedFieldName: true,
107+
ipIsDeletedFieldName: false,
105108
}
106109
cidrRange, err := expandStringList(raw[ipCIDRRangeFieldName].([]interface{}))
107110
assert.NoError(t, err)
@@ -113,6 +116,7 @@ func TestExpandingIPAllowlistResource(t *testing.T) {
113116
assert.Equal(t, raw[ipDescriptionFieldName], allowlist.GetDescription())
114117
assert.Equal(t, raw[ipIsDeletedFieldName], allowlist.GetIsDeleted())
115118
assert.Equal(t, raw[ipProjectFieldName], allowlist.GetProjectId())
119+
assert.Equal(t, raw[ipRemoteInspectionAllowedFieldName], allowlist.GetRemoteInspectionAllowed())
116120
assert.Equal(t, cidrRange, allowlist.GetCidrRanges())
117121
}
118122

0 commit comments

Comments
 (0)