-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_nsxt_dhcp_v4_static_binding_config_test.go
157 lines (148 loc) · 6.57 KB
/
resource_nsxt_dhcp_v4_static_binding_config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/***************************************************************************
* ========================================================================
* Copyright 2022-2023 VMware, Inc. All rights reserved. VMware Confidential
* SPDX-License-Identifier: MPL-2.0
* ========================================================================
*/
// Auto generated code. DO NOT EDIT.
// nolint
package nsxt
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
nsxtclient "github.com/vmware/terraform-provider-nsxt-virtual-private-cloud/nsxt/clients"
)
func TestNSXTDhcpV4StaticBindingConfigBasic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNSXTDhcpV4StaticBindingConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccNSXTDhcpV4StaticBindingConfigConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckNSXTDhcpV4StaticBindingConfigExists("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "display_name", "test-dhcpv4staticbindingconfig-abc"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "description", "DHCP v4 static binding config description"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "nsx_id", "test-dhcpv4staticbinding-abc"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "host_name", "vm1.vmware.com"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "mac_address", "11:22:33:44:55:67"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "ip_address", "192.168.4.96"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "resource_type", "DhcpV4StaticBindingConfig"),
),
},
{
Config: testAccNSXTDhcpV4StaticBindingConfigupdatedConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckNSXTDhcpV4StaticBindingConfigExists("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "display_name", "test-dhcpv4staticbindingconfig-abc-updated"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "description", "DHCP v4 static binding config description"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "nsx_id", "test-dhcpv4staticbinding-abc"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "host_name", "vm1.vmware.com"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "mac_address", "11:22:33:44:55:67"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "ip_address", "192.168.4.96"),
resource.TestCheckResourceAttr("nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig", "resource_type", "DhcpV4StaticBindingConfig"),
),
},
{
ResourceName: "nsxt_vpc_dhcp_v4_static_binding_config.testDhcpV4StaticBindingConfig",
ImportState: true,
ImportStateVerify: false,
Config: testAccNSXTDhcpV4StaticBindingConfigConfig,
},
},
})
}
func testAccCheckNSXTDhcpV4StaticBindingConfigExists(resourcename string) resource.TestCheckFunc {
return func(s *terraform.State) error {
nsxtClient := testAccProvider.Meta().(*nsxtclient.NsxtClient)
var obj interface{}
rs, ok := s.RootModule().Resources[resourcename]
if !ok {
return fmt.Errorf("Not found: %s", resourcename)
}
path := nsxtClient.Config.BasePath + rs.Primary.Attributes["path"]
if path == "" {
return fmt.Errorf("No NSXT DhcpV4StaticBindingConfig policy path is set")
}
err := nsxtClient.NsxtSession.Get(path, &obj)
if err != nil {
return err
}
return nil
}
}
func testAccCheckNSXTDhcpV4StaticBindingConfigDestroy(s *terraform.State) error {
nsxtClient := testAccProvider.Meta().(*nsxtclient.NsxtClient)
var obj interface{}
for _, rs := range s.RootModule().Resources {
if rs.Type != "nsxt_vpc_dhcp_v4_static_binding_config" {
continue
}
path := nsxtClient.Config.BasePath + rs.Primary.Attributes["path"]
err := nsxtClient.NsxtSession.Get(path, &obj)
if err != nil {
if strings.Contains(err.Error(), "404") || strings.Contains(err.Error(), "400") {
return nil
}
return err
}
if len(obj.(map[string]interface{})) > 0 {
return fmt.Errorf("NSXT DhcpV4StaticBindingConfig still exists")
}
}
return nil
}
const testAccNSXTDhcpV4StaticBindingConfigConfig = `
resource "nsxt_vpc_subnet" "testVpcSubnet" {
ipv4_subnet_size = 16
nsx_id = "test-vpcsubnet-abc-1"
display_name = "test-vpcsubnet-abc-1"
description = "VpcSubnet 1 description"
access_mode = "Public"
}
resource "nsxt_vpc_dhcp_v4_static_binding_config" "testDhcpV4StaticBindingConfig" {
display_name = "test-dhcpv4staticbindingconfig-abc"
description = "DHCP v4 static binding config description"
parent_path = nsxt_vpc_subnet.testVpcSubnet.path
nsx_id = "test-dhcpv4staticbinding-abc"
host_name = "vm1.vmware.com"
mac_address = "11:22:33:44:55:67"
ip_address = "192.168.4.96"
options {
option121 {
static_routes {
next_hop = "2.2.2.2"
network = "10.22.12.1/23"
}
static_routes {
next_hop = "0.0.0.0"
network = "129.0.0.1/32"
}
}
}
resource_type = "DhcpV4StaticBindingConfig"
}
`
const testAccNSXTDhcpV4StaticBindingConfigupdatedConfig = `
resource "nsxt_vpc_subnet" "testVpcSubnet" {
ipv4_subnet_size = 16
nsx_id = "test-vpcsubnet-abc-1"
display_name = "test-vpcsubnet-abc-1-updated"
description = "updated VpcSubnet 1 description"
access_mode = "Public"
}
resource "nsxt_vpc_dhcp_v4_static_binding_config" "testDhcpV4StaticBindingConfig" {
display_name = "test-dhcpv4staticbindingconfig-abc-updated"
description = "DHCP v4 static binding config description"
parent_path = nsxt_vpc_subnet.testVpcSubnet.path
nsx_id = "test-dhcpv4staticbinding-abc"
host_name = "vm1.vmware.com"
mac_address = "11:22:33:44:55:67"
ip_address = "192.168.4.96"
resource_type = "DhcpV4StaticBindingConfig"
}
`