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.
1818// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919//
2020// Author Gergely Brautigam
21+ // Author Ewout Prangsma
2122//
2223
2324package pkg
@@ -33,12 +34,13 @@ import (
3334
3435const (
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.
113120func 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.
166180func 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" )
0 commit comments