Skip to content

Commit b3c1890

Browse files
committed
Add cidr_list attribute to nsxt_policy_ip_block
This attribute is added for NSX v9.1.0. Signed-off-by: Kobi Samoray <[email protected]>
1 parent 302efad commit b3c1890

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

nsxt/resource_nsxt_policy_ip_block.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func resourceNsxtPolicyIPBlock() *schema.Resource {
5555
Optional: true,
5656
ValidateFunc: validation.StringInSlice(visibilityTypes, false),
5757
},
58+
"cidr_list": {
59+
Type: schema.TypeList,
60+
Description: "Array of contiguous IP address spaces represented by network address and prefix length",
61+
Elem: &schema.Schema{
62+
Type: schema.TypeString,
63+
ValidateFunc: validateCidr(),
64+
},
65+
},
5866
},
5967
}
6068
}
@@ -104,6 +112,9 @@ func resourceNsxtPolicyIPBlockRead(d *schema.ResourceData, m interface{}) error
104112
if util.NsxVersionHigherOrEqual("4.2.0") {
105113
d.Set("visibility", block.Visibility)
106114
}
115+
if util.NsxVersionHigherOrEqual("9.1.0") {
116+
d.Set("cidr_list", block.CidrList)
117+
}
107118

108119
return nil
109120
}
@@ -125,6 +136,7 @@ func resourceNsxtPolicyIPBlockCreate(d *schema.ResourceData, m interface{}) erro
125136
cidr := d.Get("cidr").(string)
126137
visibility := d.Get("visibility").(string)
127138
tags := getPolicyTagsFromSchema(d)
139+
cidrList := getStringListFromSchemaList(d, "cidr_list")
128140

129141
obj := model.IpAddressBlock{
130142
DisplayName: &displayName,
@@ -135,6 +147,10 @@ func resourceNsxtPolicyIPBlockCreate(d *schema.ResourceData, m interface{}) erro
135147
if util.NsxVersionHigherOrEqual("4.2.0") && len(visibility) > 0 {
136148
obj.Visibility = &visibility
137149
}
150+
if util.NsxVersionHigherOrEqual("9.1.0") && len(cidrList) > 0 {
151+
obj.CidrList = cidrList
152+
}
153+
138154
// Create the resource using PATCH
139155
log.Printf("[INFO] Creating IP Block with ID %s", id)
140156
err = client.Patch(id, obj)

nsxt/resource_nsxt_policy_ip_block_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,39 @@ func TestAccResourceNsxtPolicyIPBlock_minimal(t *testing.T) {
4242
})
4343
}
4444

45+
func TestAccResourceNsxtPolicyIPBlock_cidrList(t *testing.T) {
46+
name := getAccTestResourceName()
47+
testResourceName := "nsxt_policy_ip_block.test"
48+
cidr := "192.168.1.0/24"
49+
50+
resource.ParallelTest(t, resource.TestCase{
51+
PreCheck: func() {
52+
testAccOnlyLocalManager(t)
53+
testAccPreCheck(t)
54+
testAccNSXVersion(t, "9.1.0")
55+
},
56+
Providers: testAccProviders,
57+
CheckDestroy: func(state *terraform.State) error {
58+
return testAccNSXPolicyIPBlockCheckDestroy(state)
59+
},
60+
Steps: []resource.TestStep{
61+
{
62+
Config: testAccNSXPolicyIPBlockCreateCidrListTemplate(name, cidr, false, false),
63+
Check: resource.ComposeTestCheckFunc(
64+
testAccNSXPolicyIPBlockCheckExists(testResourceName),
65+
resource.TestCheckResourceAttr(testResourceName, "display_name", name),
66+
resource.TestCheckResourceAttr(testResourceName, "cidr_list.#", "1"),
67+
resource.TestCheckResourceAttr(testResourceName, "cidr_list.0", cidr),
68+
resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"),
69+
resource.TestCheckResourceAttrSet(testResourceName, "revision"),
70+
resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"),
71+
resource.TestCheckResourceAttrSet(testResourceName, "path"),
72+
),
73+
},
74+
},
75+
})
76+
}
77+
4578
func TestAccResourceNsxtPolicyIPBlock_basic(t *testing.T) {
4679
testAccResourceNsxtPolicyIPBlockBasic(t, false, false, func() {
4780
testAccPreCheck(t)
@@ -254,6 +287,26 @@ resource "nsxt_policy_ip_block" "test" {
254287
}`, context, displayName, cidr, visibility)
255288
}
256289

290+
func testAccNSXPolicyIPBlockCreateCidrListTemplate(displayName string, cidr string, withContext, withVisibility bool) string {
291+
context := ""
292+
if withContext {
293+
context = testAccNsxtPolicyMultitenancyContext()
294+
}
295+
296+
visibility := ""
297+
if withVisibility {
298+
visibility = " visibility = \"EXTERNAL\""
299+
}
300+
301+
return fmt.Sprintf(`
302+
resource "nsxt_policy_ip_block" "test" {
303+
%s
304+
display_name = "%s"
305+
cidr_list = ["%s"]
306+
%s
307+
}`, context, displayName, cidr, visibility)
308+
}
309+
257310
func testAccNSXPolicyIPBlockUpdateTemplate(displayName string, cidr string, withContext, withVisibility bool) string {
258311
context := ""
259312
if withContext {

website/docs/r/policy_ip_block.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The following arguments are supported:
6565
* `display_name` - (Required) The display name for the IP Block.
6666
* `description` - (Optional) Description of the resource.
6767
* `cidr` - (Required) Network address and the prefix length which will be associated with a layer-2 broadcast domain.
68+
* `cidr_list` - (Optional) Array of contiguous IP address spaces represented by network address and prefix length. This attribute is supported with NSX 9.1.0 onwards.
6869
* `visibility` - (Optional) Visibility of the IP Block. Valid options are `PRIVATE`, `EXTERNAL` or unset. Visibility cannot be changed once the block is associated with other resources.
6970
* `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource.
7071
* `tag` - (Optional) A list of scope + tag pairs to associate with this IP Block.

0 commit comments

Comments
 (0)