diff --git a/go.mod b/go.mod index f116f390e..3beafac9d 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/vmware/terraform-provider-nsxt go 1.19 replace ( - github.com/vmware/vsphere-automation-sdk-go/lib => github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20241110024359-e42c5fcc5482 - github.com/vmware/vsphere-automation-sdk-go/runtime => github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20241110024359-e42c5fcc5482 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20241110024359-e42c5fcc5482 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20241110024359-e42c5fcc5482 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp => github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20241110024359-e42c5fcc5482 + github.com/vmware/vsphere-automation-sdk-go/lib => github.com/vmware/vsphere-automation-sdk-go/lib v0.7.1-0.20241113023437-5938c535c194 + github.com/vmware/vsphere-automation-sdk-go/runtime => github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.1-0.20241113023437-5938c535c194 + github.com/vmware/vsphere-automation-sdk-go/services/nsxt => github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.12.1-0.20241113023437-5938c535c194 + github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm => github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm v0.9.1-0.20241113023437-5938c535c194 + github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp => github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.6.1-0.20241113023437-5938c535c194 ) require ( diff --git a/go.sum b/go.sum index ebe3f9d77..09a0597fb 100644 --- a/go.sum +++ b/go.sum @@ -6,16 +6,6 @@ github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjA github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20241110024359-e42c5fcc5482 h1:aSqiTMwQQso+tTULhSf/26iAkhTHVfdi9P1Q/X+HpxQ= -github.com/annakhm/vsphere-automation-sdk-go/lib v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:ADkX8BkdnvT1Kc9ZfqHaV4qzaaD+9L8Ok2+pxK4xoD8= -github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20241110024359-e42c5fcc5482 h1:wWKGPhmqvvpxO0G4mlNtZ27ThzPCuOG/kPXgbu0CR8s= -github.com/annakhm/vsphere-automation-sdk-go/runtime v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:DzLetYAmw1+vj7bqElRWEpuy40WYE/woL3alsymYa/c= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20241110024359-e42c5fcc5482 h1:qDHIIezjQTDqgv9YlFee9R3vBWDlbFJGUZRxvomtkgk= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:NSjO9WqelbsTEDb3pVxpYYz4zjgX0XPp43dKNT4Y+9k= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20241110024359-e42c5fcc5482 h1:QkLzAnPXPDxqICfRfo8QMVjim0mY1nYfM+ie0r/pyLQ= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-gm v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:gcEvyczWPFMZX2gkBiBVpOwvUGSNXSpxU19Sx9aiouY= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20241110024359-e42c5fcc5482 h1:/+pwbYwlKBuZAwJVtZhSQorwtDmIGbo/EqRnFkgE7dk= -github.com/annakhm/vsphere-automation-sdk-go/services/nsxt-mp v0.0.0-20241110024359-e42c5fcc5482/go.mod h1:ugk9I4YM62SSAox57l5NAVBCRIkPQ1RNLb3URxyTADc= github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= @@ -142,6 +132,16 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/vmware/go-vmware-nsxt v0.0.0-20220328155605-f49a14c1ef5f h1:NbC9yOr5At92seXK+kOr2TzU3mIWzcJOVzZasGSuwoU= github.com/vmware/go-vmware-nsxt v0.0.0-20220328155605-f49a14c1ef5f/go.mod h1:VEqcmf4Sp7gPB7z05QGyKVmn6xWppr7Nz8cVNvyC80o= +github.com/vmware/vsphere-automation-sdk-go/lib v0.7.1-0.20241113023437-5938c535c194 h1:4+nN9YcmXs8uXoKhsQpg0K8ziNTg8zULbdvc3Mu/Dk0= +github.com/vmware/vsphere-automation-sdk-go/lib v0.7.1-0.20241113023437-5938c535c194/go.mod h1:f3+6YVZpNcK2pYyiQ94BoHWmjMj9BnYav0vNFuTiDVM= +github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.1-0.20241113023437-5938c535c194 h1:4NmoWzW501ZhriPGzGULj6mJmr2Dx6QyUO9CmRbuMg0= +github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.1-0.20241113023437-5938c535c194/go.mod h1:qdzEFm2iK3dvlmm99EYYNxs70HbzuiHyENFD24Ps8fQ= +github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.12.1-0.20241113023437-5938c535c194 h1:M4/j0HbfW+pFbcpZdbg7wid3WxkIFOZRXuWNi+llXEc= +github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.12.1-0.20241113023437-5938c535c194/go.mod h1:M+J1qwzF4o7sAb/2VRu/edl1HLCdC++C4SNUrgiuGlQ= +github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm v0.9.1-0.20241113023437-5938c535c194 h1:/+cOYJUazdOQ8sMePBcCoCnnLrQDvIvxjYYDKcdwe4Y= +github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm v0.9.1-0.20241113023437-5938c535c194/go.mod h1:gcEvyczWPFMZX2gkBiBVpOwvUGSNXSpxU19Sx9aiouY= +github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.6.1-0.20241113023437-5938c535c194 h1:Q2jxex1UrZOMwJVJHSEyZcuWzQjsEeDpzDfc3zrtI1A= +github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.6.1-0.20241113023437-5938c535c194/go.mod h1:ugk9I4YM62SSAox57l5NAVBCRIkPQ1RNLb3URxyTADc= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.14.0 h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc= diff --git a/nsxt/data_source_nsxt_vpc_test.go b/nsxt/data_source_nsxt_vpc_test.go index cb0492c76..5731935e9 100644 --- a/nsxt/data_source_nsxt_vpc_test.go +++ b/nsxt/data_source_nsxt_vpc_test.go @@ -103,7 +103,7 @@ func testAccDataSourceNsxtVPCDeleteByName(name string) error { } for _, objInList := range objList.Results { if *objInList.DisplayName == name { - err := client.Delete(defaultOrgID, projID, *objInList.Id) + err := client.Delete(defaultOrgID, projID, *objInList.Id, nil) if err != nil { return handleDeleteError("VPC", *objInList.Id, err) } diff --git a/nsxt/resource_nsxt_vpc.go b/nsxt/resource_nsxt_vpc.go index fb9703902..4ec4a70bd 100644 --- a/nsxt/resource_nsxt_vpc.go +++ b/nsxt/resource_nsxt_vpc.go @@ -275,7 +275,7 @@ func resourceNsxtVpcDelete(d *schema.ResourceData, m interface{}) error { parents := getVpcParentsFromContext(getSessionContext(d, m)) client := clientLayer.NewVpcsClient(connector) - err := client.Delete(parents[0], parents[1], id) + err := client.Delete(parents[0], parents[1], id, nil) if err != nil { return handleDeleteError("Vpc", id, err) diff --git a/nsxt/resource_nsxt_vpc_service_profile.go b/nsxt/resource_nsxt_vpc_service_profile.go index 29b64d47f..0e862d42b 100644 --- a/nsxt/resource_nsxt_vpc_service_profile.go +++ b/nsxt/resource_nsxt_vpc_service_profile.go @@ -9,7 +9,6 @@ import ( "reflect" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" clientLayer "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects" @@ -61,32 +60,13 @@ var vpcServiceProfileSchema = map[string]*metadata.ExtendedSchema{ Required: true, Elem: &metadata.ExtendedResource{ Schema: map[string]*metadata.ExtendedSchema{ - "ntp_servers": { - Schema: schema.Schema{ - Type: schema.TypeList, - Elem: &metadata.ExtendedSchema{ - Schema: schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validateSingleIPOrHostName(), - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "list", - SdkFieldName: "NtpServers", - }, - }, - "dns_client_config": { + "dhcp_relay_config": { Schema: schema.Schema{ Type: schema.TypeList, MaxItems: 1, Elem: &metadata.ExtendedResource{ Schema: map[string]*metadata.ExtendedSchema{ - "dns_server_ips": { + "server_addresses": { Schema: schema.Schema{ Type: schema.TypeList, Elem: &metadata.ExtendedSchema{ @@ -101,7 +81,7 @@ var vpcServiceProfileSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "list", - SdkFieldName: "DnsServerIps", + SdkFieldName: "ServerAddresses", }, }, }, @@ -110,73 +90,68 @@ var vpcServiceProfileSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "struct", - SdkFieldName: "DnsClientConfig", - ReflectType: reflect.TypeOf(model.DnsClientConfig{}), - }, - }, - "lease_time": { - Schema: schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 86400, - }, - Metadata: metadata.Metadata{ - SchemaType: "int", - SdkFieldName: "LeaseTime", - }, - }, - "mode": { - Schema: schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(vpcServiceProfileModeValues, false), - Optional: true, - Default: model.VpcProfileDhcpConfig_MODE_SERVER, - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - SdkFieldName: "Mode", + SdkFieldName: "DhcpRelayConfig", + ReflectType: reflect.TypeOf(model.VpcDhcpRelayConfig{}), }, }, - "advanced_config": { + "dhcp_server_config": { Schema: schema.Schema{ Type: schema.TypeList, MaxItems: 1, Elem: &metadata.ExtendedResource{ Schema: map[string]*metadata.ExtendedSchema{ - "is_distributed_dhcp": { + "dns_client_config": { Schema: schema.Schema{ - Type: schema.TypeBool, + Type: schema.TypeList, + MaxItems: 1, + Elem: &metadata.ExtendedResource{ + Schema: map[string]*metadata.ExtendedSchema{ + "dns_server_ips": { + Schema: schema.Schema{ + Type: schema.TypeList, + Elem: &metadata.ExtendedSchema{ + Schema: schema.Schema{ + Type: schema.TypeString, + }, + Metadata: metadata.Metadata{ + SchemaType: "string", + }, + }, + Optional: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "list", + SdkFieldName: "DnsServerIps", + }, + }, + }, + }, Optional: true, - Default: true, }, Metadata: metadata.Metadata{ - SchemaType: "bool", - SdkFieldName: "IsDistributedDhcp", + SchemaType: "struct", + SdkFieldName: "DnsClientConfig", + ReflectType: reflect.TypeOf(model.DnsClientConfig{}), }, }, - }, - }, - Optional: true, - Computed: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "struct", - SdkFieldName: "AdvancedConfig", - ReflectType: reflect.TypeOf(model.VpcDhcpAdvancedConfig{}), - }, - }, - "dhcp_relay_config": { - Schema: schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Elem: &metadata.ExtendedResource{ - Schema: map[string]*metadata.ExtendedSchema{ - "server_addresses": { + "lease_time": { + Schema: schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Default: 86400, + }, + Metadata: metadata.Metadata{ + SchemaType: "int", + SdkFieldName: "LeaseTime", + }, + }, + "ntp_servers": { Schema: schema.Schema{ Type: schema.TypeList, Elem: &metadata.ExtendedSchema{ Schema: schema.Schema{ Type: schema.TypeString, + ValidateFunc: validateSingleIPOrHostName(), }, Metadata: metadata.Metadata{ SchemaType: "string", @@ -186,7 +161,35 @@ var vpcServiceProfileSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "list", - SdkFieldName: "ServerAddresses", + SdkFieldName: "NtpServers", + }, + }, + "advanced_config": { + Schema: schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Elem: &metadata.ExtendedResource{ + Schema: map[string]*metadata.ExtendedSchema{ + "is_distributed_dhcp": { + Schema: schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "bool", + SdkFieldName: "IsDistributedDhcp", + }, + }, + }, + }, + Optional: true, + Computed: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "struct", + SdkFieldName: "AdvancedConfig", + ReflectType: reflect.TypeOf(model.VpcDhcpAdvancedConfig{}), }, }, }, @@ -195,8 +198,8 @@ var vpcServiceProfileSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "struct", - SdkFieldName: "DhcpRelayConfig", - ReflectType: reflect.TypeOf(model.VpcDhcpRelayConfig{}), + SdkFieldName: "DhcpServerConfig", + ReflectType: reflect.TypeOf(model.VpcDhcpServerConfig{}), }, }, }, @@ -299,6 +302,11 @@ func resourceNsxtVpcServiceProfileCreate(d *schema.ResourceData, m interface{}) return err } + if obj.DhcpConfig == nil { + // NSX requires to send this struct even if empty + obj.DhcpConfig = &model.VpcProfileDhcpConfig{} + } + log.Printf("[INFO] Creating VpcServiceProfile with ID %s", id) client := clientLayer.NewVpcServiceProfilesClient(connector) @@ -368,6 +376,12 @@ func resourceNsxtVpcServiceProfileUpdate(d *schema.ResourceData, m interface{}) if err := metadata.SchemaToStruct(elem, d, vpcServiceProfileSchema, "", nil); err != nil { return err } + + if obj.DhcpConfig == nil { + // NSX requires to send this struct even if empty + obj.DhcpConfig = &model.VpcProfileDhcpConfig{} + } + client := clientLayer.NewVpcServiceProfilesClient(connector) _, err := client.Update(parents[0], parents[1], id, obj) if err != nil { diff --git a/nsxt/resource_nsxt_vpc_service_profile_test.go b/nsxt/resource_nsxt_vpc_service_profile_test.go index e4b679e70..9cdb16268 100644 --- a/nsxt/resource_nsxt_vpc_service_profile_test.go +++ b/nsxt/resource_nsxt_vpc_service_profile_test.go @@ -16,7 +16,6 @@ var accTestPolicyVpcServiceProfileCreateAttributes = map[string]string{ "description": "terraform created", "ntp_servers": "5.5.5.5", "lease_time": "50840", - "mode": "DHCP_SERVER", "dns_server_ips": "7.7.7.7", "server_addresses": "11.11.11.11", } @@ -26,7 +25,6 @@ var accTestPolicyVpcServiceProfileUpdateAttributes = map[string]string{ "description": "terraform updated", "ntp_servers": "5.5.5.7", "lease_time": "148000", - "mode": "DHCP_SERVER", "dns_server_ips": "7.7.7.2", "server_addresses": "11.11.11.111", } @@ -50,12 +48,13 @@ func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) { resource.TestCheckResourceAttrSet(testDataSourceName, "description"), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyVpcServiceProfileCreateAttributes["display_name"]), resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyVpcServiceProfileCreateAttributes["description"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.ntp_servers.0", accTestPolicyVpcServiceProfileCreateAttributes["ntp_servers"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dns_client_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.lease_time", accTestPolicyVpcServiceProfileCreateAttributes["lease_time"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.mode", accTestPolicyVpcServiceProfileCreateAttributes["mode"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_relay_config.#", "0"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dns_client_config.0.dns_server_ips.0", accTestPolicyVpcServiceProfileCreateAttributes["dns_server_ips"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.ntp_servers.0", accTestPolicyVpcServiceProfileCreateAttributes["ntp_servers"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.lease_time", accTestPolicyVpcServiceProfileCreateAttributes["lease_time"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.dns_client_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.dns_client_config.0.dns_server_ips.0", accTestPolicyVpcServiceProfileCreateAttributes["dns_server_ips"]), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), @@ -72,13 +71,13 @@ func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) { resource.TestCheckResourceAttrSet(testDataSourceName, "description"), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyVpcServiceProfileCreateAttributes["display_name"]), resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyVpcServiceProfileCreateAttributes["description"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.ntp_servers.0", accTestPolicyVpcServiceProfileCreateAttributes["ntp_servers"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dns_client_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.lease_time", accTestPolicyVpcServiceProfileCreateAttributes["lease_time"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.mode", accTestPolicyVpcServiceProfileCreateAttributes["mode"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_relay_config.#", "0"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dns_client_config.0.dns_server_ips.0", accTestPolicyVpcServiceProfileCreateAttributes["dns_server_ips"]), - + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.ntp_servers.0", accTestPolicyVpcServiceProfileCreateAttributes["ntp_servers"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.lease_time", accTestPolicyVpcServiceProfileCreateAttributes["lease_time"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.dns_client_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.dns_client_config.0.dns_server_ips.0", accTestPolicyVpcServiceProfileCreateAttributes["dns_server_ips"]), resource.TestCheckResourceAttrSet(testResourceName, "qos_profile"), resource.TestCheckResourceAttrSet(testResourceName, "spoof_guard_profile"), resource.TestCheckResourceAttrSet(testResourceName, "ip_discovery_profile"), @@ -91,18 +90,19 @@ func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) { ), }, { + // update values, no profiles Config: testAccNsxtVpcServiceProfileTemplate(false, false), Check: resource.ComposeTestCheckFunc( testAccNsxtVpcServiceProfileExists(accTestPolicyVpcServiceProfileUpdateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyVpcServiceProfileUpdateAttributes["display_name"]), resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyVpcServiceProfileUpdateAttributes["description"]), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.ntp_servers.0", accTestPolicyVpcServiceProfileUpdateAttributes["ntp_servers"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dns_client_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.lease_time", accTestPolicyVpcServiceProfileUpdateAttributes["lease_time"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.mode", accTestPolicyVpcServiceProfileUpdateAttributes["mode"]), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_relay_config.#", "0"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dns_client_config.0.dns_server_ips.0", accTestPolicyVpcServiceProfileUpdateAttributes["dns_server_ips"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.ntp_servers.0", accTestPolicyVpcServiceProfileUpdateAttributes["ntp_servers"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.lease_time", accTestPolicyVpcServiceProfileUpdateAttributes["lease_time"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.dns_client_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_config.0.dns_client_config.0.dns_server_ips.0", accTestPolicyVpcServiceProfileUpdateAttributes["dns_server_ips"]), resource.TestCheckResourceAttr(testResourceName, "qos_profile", ""), resource.TestCheckResourceAttr(testResourceName, "spoof_guard_profile", ""), @@ -115,6 +115,20 @@ func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), ), }, + { + Config: testAccNsxtVpcServiceProfileDhcpRelay(), + Check: resource.ComposeTestCheckFunc( + testAccNsxtVpcServiceProfileExists(accTestPolicyVpcServiceProfileCreateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "description", ""), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_relay_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_relay_config.0.server_addresses.#", "1"), + ), + }, { Config: testAccNsxtVpcServiceProfileMinimalistic(), Check: resource.ComposeTestCheckFunc( @@ -124,6 +138,7 @@ func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) { resource.TestCheckResourceAttrSet(testResourceName, "path"), resource.TestCheckResourceAttrSet(testResourceName, "revision"), resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), ), }, }, @@ -256,13 +271,13 @@ resource "nsxt_vpc_service_profile" "test" { description = "%s" dhcp_config { - ntp_servers = ["%s"] - - lease_time = %s - mode = "%s" + dhcp_server_config { + ntp_servers = ["%s"] + lease_time = %s - dns_client_config { - dns_server_ips = ["%s"] + dns_client_config { + dns_server_ips = ["%s"] + } } } @@ -277,17 +292,30 @@ data "nsxt_vpc_service_profile" "test" { display_name = "%s" depends_on = [nsxt_vpc_service_profile.test] -}`, testAccNsxtProjectContext(), profileAssignment, attrMap["display_name"], attrMap["description"], attrMap["ntp_servers"], attrMap["lease_time"], attrMap["mode"], attrMap["dns_server_ips"], testAccNsxtProjectContext(), attrMap["display_name"]) +}`, testAccNsxtProjectContext(), profileAssignment, attrMap["display_name"], attrMap["description"], attrMap["ntp_servers"], attrMap["lease_time"], attrMap["dns_server_ips"], testAccNsxtProjectContext(), attrMap["display_name"]) } -func testAccNsxtVpcServiceProfileMinimalistic() string { +func testAccNsxtVpcServiceProfileDhcpRelay() string { return fmt.Sprintf(` resource "nsxt_vpc_service_profile" "test" { %s display_name = "%s" + dhcp_config { + dhcp_relay_config { + server_addresses = ["%s"] + } + } +}`, testAccNsxtProjectContext(), accTestPolicyVpcServiceProfileUpdateAttributes["display_name"], accTestPolicyVpcServiceProfileUpdateAttributes["server_addresses"]) +} + +func testAccNsxtVpcServiceProfileMinimalistic() string { + return fmt.Sprintf(` +resource "nsxt_vpc_service_profile" "test" { + %s + display_name = "%s" dhcp_config { - mode = "%s" } -}`, testAccNsxtProjectContext(), accTestPolicyVpcServiceProfileUpdateAttributes["display_name"], accTestPolicyVpcServiceProfileUpdateAttributes["mode"]) + +}`, testAccNsxtProjectContext(), accTestPolicyVpcServiceProfileUpdateAttributes["display_name"]) } diff --git a/nsxt/resource_nsxt_vpc_subnet.go b/nsxt/resource_nsxt_vpc_subnet.go index 9516f1d8a..c9328a674 100644 --- a/nsxt/resource_nsxt_vpc_subnet.go +++ b/nsxt/resource_nsxt_vpc_subnet.go @@ -33,6 +33,12 @@ var vpcSubnetConnectivityStateValues = []string{ model.SubnetAdvancedConfig_CONNECTIVITY_STATE_DISCONNECTED, } +var vpcSubnetModeValues = []string{ + model.SubnetDhcpConfig_MODE_SERVER, + model.SubnetDhcpConfig_MODE_RELAY, + model.SubnetDhcpConfig_MODE_DEACTIVATED, +} + var vpcSubnetSchema = map[string]*metadata.ExtendedSchema{ "nsx_id": metadata.GetExtendedSchema(getNsxIDSchema()), "path": metadata.GetExtendedSchema(getPathSchema()), @@ -259,209 +265,114 @@ var vpcSubnetSchema = map[string]*metadata.ExtendedSchema{ Computed: true, Elem: &metadata.ExtendedResource{ Schema: map[string]*metadata.ExtendedSchema{ - "ntp_servers": { - Schema: schema.Schema{ - Type: schema.TypeList, - Elem: &metadata.ExtendedSchema{ - Schema: schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validateSingleIPOrHostName(), - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "list", - SdkFieldName: "NtpServers", - }, - }, - "lease_time": { - Schema: schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Default: 86400, - }, - Metadata: metadata.Metadata{ - SchemaType: "int", - SdkFieldName: "LeaseTime", - }, - }, - "dhcp_relay_config_path": { + "mode": { Schema: schema.Schema{ Type: schema.TypeString, - ValidateFunc: validatePolicyPath(), + ValidateFunc: validation.StringInSlice(vpcSubnetModeValues, false), Optional: true, + Default: model.SubnetDhcpConfig_MODE_DEACTIVATED, }, Metadata: metadata.Metadata{ SchemaType: "string", - SdkFieldName: "DhcpRelayConfigPath", - OmitIfEmpty: true, - }, - }, - "excluded_ips": { - Schema: schema.Schema{ - Type: schema.TypeList, - Elem: &metadata.ExtendedSchema{ - Schema: schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validateSingleIP(), - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "list", - SdkFieldName: "ExcludedIps", + SdkFieldName: "Mode", }, }, - "dns_client_config": { + "dhcp_server_additional_config": { Schema: schema.Schema{ Type: schema.TypeList, MaxItems: 1, Elem: &metadata.ExtendedResource{ Schema: map[string]*metadata.ExtendedSchema{ - "dns_server_ips": { - Schema: schema.Schema{ - Type: schema.TypeList, - Elem: &metadata.ExtendedSchema{ - Schema: schema.Schema{ - Type: schema.TypeString, - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "list", - SdkFieldName: "DnsServerIps", - }, - }, - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "struct", - SdkFieldName: "DnsClientConfig", - ReflectType: reflect.TypeOf(model.DnsClientConfig{}), - }, - }, - "enable_dhcp": { - Schema: schema.Schema{ - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "bool", - SdkFieldName: "EnableDhcp", - }, - }, - "static_pool_config": { - Schema: schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Elem: &metadata.ExtendedResource{ - Schema: map[string]*metadata.ExtendedSchema{ - "ipv4_pool_size": { - Schema: schema.Schema{ - Type: schema.TypeInt, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "int", - SdkFieldName: "Ipv4PoolSize", - }, - }, - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "struct", - SdkFieldName: "StaticPoolConfig", - ReflectType: reflect.TypeOf(model.StaticPoolConfig{}), - }, - }, - "dhcp_relay_config": { - Schema: schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Elem: &metadata.ExtendedResource{ - Schema: map[string]*metadata.ExtendedSchema{ - "server_addresses": { - Schema: schema.Schema{ - Type: schema.TypeList, - Elem: &metadata.ExtendedSchema{ - Schema: schema.Schema{ - Type: schema.TypeString, - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "list", - SdkFieldName: "ServerAddresses", - }, - }, - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "struct", - SdkFieldName: "DhcpRelayConfig", - ReflectType: reflect.TypeOf(model.VpcDhcpRelayConfig{}), - }, - }, - "options": { - Schema: schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Elem: &metadata.ExtendedResource{ - Schema: map[string]*metadata.ExtendedSchema{ - "option121": { + "options": { Schema: schema.Schema{ Type: schema.TypeList, MaxItems: 1, Elem: &metadata.ExtendedResource{ Schema: map[string]*metadata.ExtendedSchema{ - "static_route": { + "option121": { + Schema: schema.Schema{ + Type: schema.TypeList, + MaxItems: 1, + Elem: &metadata.ExtendedResource{ + Schema: map[string]*metadata.ExtendedSchema{ + "static_route": { + Schema: schema.Schema{ + Type: schema.TypeList, + Elem: &metadata.ExtendedResource{ + Schema: map[string]*metadata.ExtendedSchema{ + "next_hop": { + Schema: schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validateSingleIP(), + Optional: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "string", + SdkFieldName: "NextHop", + }, + }, + "network": { + Schema: schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validateCidrOrIPOrRange(), + Optional: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "string", + SdkFieldName: "Network", + }, + }, + }, + }, + Optional: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "list", + SdkFieldName: "StaticRoutes", + ReflectType: reflect.TypeOf(model.ClasslessStaticRoute{}), + }, + }, + }, + }, + Optional: true, + }, + Metadata: metadata.Metadata{ + SchemaType: "struct", + SdkFieldName: "Option121", + ReflectType: reflect.TypeOf(model.DhcpOption121{}), + }, + }, + "other": { Schema: schema.Schema{ Type: schema.TypeList, Elem: &metadata.ExtendedResource{ Schema: map[string]*metadata.ExtendedSchema{ - "next_hop": { + "code": { Schema: schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validateSingleIP(), - Optional: true, + Type: schema.TypeInt, + Optional: true, }, Metadata: metadata.Metadata{ - SchemaType: "string", - SdkFieldName: "NextHop", + SchemaType: "int", + SdkFieldName: "Code", }, }, - "network": { + "values": { Schema: schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validateCidrOrIPOrRange(), - Optional: true, + Type: schema.TypeList, + Elem: &metadata.ExtendedSchema{ + Schema: schema.Schema{ + Type: schema.TypeString, + }, + Metadata: metadata.Metadata{ + SchemaType: "string", + }, + }, + Optional: true, }, Metadata: metadata.Metadata{ - SchemaType: "string", - SdkFieldName: "Network", + SchemaType: "list", + SdkFieldName: "Values", }, }, }, @@ -470,8 +381,8 @@ var vpcSubnetSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "list", - SdkFieldName: "StaticRoutes", - ReflectType: reflect.TypeOf(model.ClasslessStaticRoute{}), + SdkFieldName: "Others", + ReflectType: reflect.TypeOf(model.GenericDhcpOption{}), }, }, }, @@ -480,51 +391,26 @@ var vpcSubnetSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "struct", - SdkFieldName: "Option121", - ReflectType: reflect.TypeOf(model.DhcpOption121{}), + SdkFieldName: "Options", + ReflectType: reflect.TypeOf(model.DhcpV4Options{}), }, }, - "other": { + "reserved_ip_ranges": { Schema: schema.Schema{ Type: schema.TypeList, - Elem: &metadata.ExtendedResource{ - Schema: map[string]*metadata.ExtendedSchema{ - "code": { - Schema: schema.Schema{ - Type: schema.TypeInt, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "int", - SdkFieldName: "Code", - }, - }, - "values": { - Schema: schema.Schema{ - Type: schema.TypeList, - Elem: &metadata.ExtendedSchema{ - Schema: schema.Schema{ - Type: schema.TypeString, - }, - Metadata: metadata.Metadata{ - SchemaType: "string", - }, - }, - Optional: true, - }, - Metadata: metadata.Metadata{ - SchemaType: "list", - SdkFieldName: "Values", - }, - }, + Elem: &metadata.ExtendedSchema{ + Schema: schema.Schema{ + Type: schema.TypeString, + }, + Metadata: metadata.Metadata{ + SchemaType: "string", }, }, Optional: true, }, Metadata: metadata.Metadata{ SchemaType: "list", - SdkFieldName: "Others", - ReflectType: reflect.TypeOf(model.GenericDhcpOption{}), + SdkFieldName: "ReservedIpRanges", }, }, }, @@ -533,8 +419,8 @@ var vpcSubnetSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "struct", - SdkFieldName: "Options", - ReflectType: reflect.TypeOf(model.DhcpV4Options{}), + SdkFieldName: "DhcpServerAdditionalConfig", + ReflectType: reflect.TypeOf(model.DhcpServerAdditionalConfig{}), }, }, }, @@ -543,8 +429,8 @@ var vpcSubnetSchema = map[string]*metadata.ExtendedSchema{ }, Metadata: metadata.Metadata{ SchemaType: "struct", - SdkFieldName: "DhcpConfig", - ReflectType: reflect.TypeOf(model.VpcSubnetDhcpConfig{}), + SdkFieldName: "SubnetDhcpConfig", + ReflectType: reflect.TypeOf(model.SubnetDhcpConfig{}), }, }, } diff --git a/nsxt/resource_nsxt_vpc_subnet_test.go b/nsxt/resource_nsxt_vpc_subnet_test.go index e8f266600..7c2a343e0 100644 --- a/nsxt/resource_nsxt_vpc_subnet_test.go +++ b/nsxt/resource_nsxt_vpc_subnet_test.go @@ -11,18 +11,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) -// TODO - change lease_time to non-default value when platform bug is fixed var accTestVpcSubnetCreateAttributes = map[string]string{ "display_name": getAccTestResourceName(), "description": "terraform created", "access_mode": "Isolated", "enabled": "true", - "enable_dhcp": "true", "ipv4_subnet_size": "32", "ip_addresses": "192.168.240.0/26", - "ntp_servers": "192.168.4.14", - "lease_time": "86400", - "excluded_ips": "2.2.2.2", + "reserved_ip_ranges": "11.11.50.7", } var accTestVpcSubnetUpdateAttributes = map[string]string{ @@ -30,12 +26,9 @@ var accTestVpcSubnetUpdateAttributes = map[string]string{ "description": "terraform updated", "access_mode": "Isolated", "enabled": "true", - "enable_dhcp": "true", "ipv4_subnet_size": "32", "ip_addresses": "192.168.240.0/26", - "ntp_servers": "192.168.4.15", - "lease_time": "86400", - "excluded_ips": "2.2.2.3", + "reserved_ip_ranges": "11.11.50.4-11.11.50.6", } func TestAccResourceNsxtVpcSubnet_basic(t *testing.T) { @@ -60,7 +53,7 @@ func TestAccResourceNsxtVpcSubnet_basic(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "ip_addresses.0", accTestVpcSubnetCreateAttributes["ip_addresses"]), resource.TestCheckResourceAttr(testResourceName, "access_mode", accTestVpcSubnetCreateAttributes["access_mode"]), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.enable_dhcp", accTestVpcSubnetCreateAttributes["enable_dhcp"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.mode", "DHCP_DEACTIVATED"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), @@ -74,10 +67,10 @@ func TestAccResourceNsxtVpcSubnet_basic(t *testing.T) { testAccNsxtVpcSubnetExists(accTestVpcSubnetUpdateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "display_name", accTestVpcSubnetUpdateAttributes["display_name"]), resource.TestCheckResourceAttr(testResourceName, "description", accTestVpcSubnetUpdateAttributes["description"]), - resource.TestCheckResourceAttr(testResourceName, "ip_addresses.0", accTestVpcSubnetCreateAttributes["ip_addresses"]), + resource.TestCheckResourceAttr(testResourceName, "ip_addresses.0", accTestVpcSubnetUpdateAttributes["ip_addresses"]), resource.TestCheckResourceAttr(testResourceName, "access_mode", accTestVpcSubnetUpdateAttributes["access_mode"]), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.enable_dhcp", accTestVpcSubnetUpdateAttributes["enable_dhcp"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.mode", "DHCP_DEACTIVATED"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), @@ -86,7 +79,7 @@ func TestAccResourceNsxtVpcSubnet_basic(t *testing.T) { ), }, { - Config: testAccNsxtVpcSubnetMinimalistic(), + Config: testAccNsxtVpcSubnetMinimalisticIsolated(), Check: resource.ComposeTestCheckFunc( testAccNsxtVpcSubnetExists(accTestVpcSubnetCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "description", ""), @@ -122,15 +115,12 @@ func TestAccResourceNsxtVpcSubnet_subnetSize(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "ipv4_subnet_size", accTestVpcSubnetCreateAttributes["ipv4_subnet_size"]), resource.TestCheckResourceAttr(testResourceName, "ip_addresses.#", "1"), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.enable_dhcp", "true"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.ntp_servers.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.ntp_servers.0", accTestVpcSubnetCreateAttributes["ntp_servers"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.lease_time", accTestVpcSubnetCreateAttributes["lease_time"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.excluded_ips.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.excluded_ips.0", accTestVpcSubnetCreateAttributes["excluded_ips"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.options.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.options.0.option121.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.options.0.other.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.reserved_ip_ranges.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.reserved_ip_ranges.0", accTestVpcSubnetCreateAttributes["reserved_ip_ranges"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.options.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.options.0.option121.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.options.0.other.#", "1"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), @@ -147,15 +137,12 @@ func TestAccResourceNsxtVpcSubnet_subnetSize(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "ip_addresses.#", "1"), resource.TestCheckResourceAttr(testResourceName, "ipv4_subnet_size", accTestVpcSubnetCreateAttributes["ipv4_subnet_size"]), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.enable_dhcp", "true"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.ntp_servers.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.ntp_servers.0", accTestVpcSubnetUpdateAttributes["ntp_servers"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.lease_time", accTestVpcSubnetUpdateAttributes["lease_time"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.excluded_ips.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.excluded_ips.0", accTestVpcSubnetUpdateAttributes["excluded_ips"]), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.options.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.options.0.option121.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.options.0.other.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.reserved_ip_ranges.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.reserved_ip_ranges.0", accTestVpcSubnetUpdateAttributes["reserved_ip_ranges"]), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.options.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.options.0.option121.#", "1"), + resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.dhcp_server_additional_config.0.options.0.other.#", "1"), resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), resource.TestCheckResourceAttrSet(testResourceName, "path"), @@ -164,7 +151,7 @@ func TestAccResourceNsxtVpcSubnet_subnetSize(t *testing.T) { ), }, { - Config: testAccNsxtVpcSubnetMinimalistic(), + Config: testAccNsxtVpcSubnetMinimalisticPublic(), Check: resource.ComposeTestCheckFunc( testAccNsxtVpcSubnetExists(accTestVpcSubnetCreateAttributes["display_name"], testResourceName), resource.TestCheckResourceAttr(testResourceName, "description", ""), @@ -173,7 +160,6 @@ func TestAccResourceNsxtVpcSubnet_subnetSize(t *testing.T) { resource.TestCheckResourceAttrSet(testResourceName, "revision"), resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), resource.TestCheckResourceAttr(testResourceName, "dhcp_config.#", "1"), - resource.TestCheckResourceAttr(testResourceName, "dhcp_config.0.options.#", "0"), ), }, }, @@ -195,7 +181,7 @@ func TestAccResourceNsxtVpcSubnet_importBasic(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccNsxtVpcSubnetMinimalistic(), + Config: testAccNsxtVpcSubnetMinimalisticIsolated(), }, { ResourceName: testResourceName, @@ -272,14 +258,14 @@ resource "nsxt_vpc_subnet" "test" { ip_addresses = ["%s"] access_mode = "%s" dhcp_config { - enable_dhcp = %s + mode = "DHCP_DEACTIVATED" } tag { scope = "scope1" tag = "tag1" } -}`, testAccNsxtPolicyMultitenancyContext(), attrMap["display_name"], attrMap["description"], attrMap["ip_addresses"], attrMap["access_mode"], attrMap["enable_dhcp"]) +}`, testAccNsxtPolicyMultitenancyContext(), attrMap["display_name"], attrMap["description"], attrMap["ip_addresses"], attrMap["access_mode"]) } func testAccNsxtVpcSubnetSizeTemplate(createFlow bool) string { @@ -300,31 +286,42 @@ resource "nsxt_vpc_subnet" "test" { access_mode = "Public" dhcp_config { - enable_dhcp = true - ntp_servers = ["%s"] - lease_time = %s - excluded_ips = ["%s"] - - options { - option121 { - static_route { - network = "2.1.1.0/24" - next_hop = "2.3.1.3" + mode = "DHCP_SERVER" + + dhcp_server_additional_config { + options { + option121 { + static_route { + network = "2.1.1.0/24" + next_hop = "2.3.1.3" + } + } + other { + code = "119" + values = ["abc", "def"] } } - other { - code = "119" - values = ["abc", "def"] - } + reserved_ip_ranges = ["%s"] } } -}`, testAccNsxtPolicyMultitenancyContext(), attrMap["display_name"], attrMap["description"], attrMap["ipv4_subnet_size"], attrMap["ntp_servers"], attrMap["lease_time"], attrMap["excluded_ips"]) +}`, testAccNsxtPolicyMultitenancyContext(), attrMap["display_name"], attrMap["description"], attrMap["ipv4_subnet_size"], attrMap["reserved_ip_ranges"]) +} + +func testAccNsxtVpcSubnetMinimalisticIsolated() string { + return fmt.Sprintf(` +resource "nsxt_vpc_subnet" "test" { +%s + display_name = "%s" + ip_addresses = ["%s"] + access_mode = "Isolated" +}`, testAccNsxtPolicyMultitenancyContext(), accTestVpcSubnetUpdateAttributes["display_name"], accTestVpcSubnetUpdateAttributes["ip_addresses"]) } -func testAccNsxtVpcSubnetMinimalistic() string { +func testAccNsxtVpcSubnetMinimalisticPublic() string { return fmt.Sprintf(` resource "nsxt_vpc_subnet" "test" { %s display_name = "%s" + access_mode = "Public" }`, testAccNsxtPolicyMultitenancyContext(), accTestVpcSubnetUpdateAttributes["display_name"]) } diff --git a/website/docs/r/vpc_service_profile.html.markdown b/website/docs/r/vpc_service_profile.html.markdown index 929b7303a..c1701c988 100644 --- a/website/docs/r/vpc_service_profile.html.markdown +++ b/website/docs/r/vpc_service_profile.html.markdown @@ -32,18 +32,17 @@ resource "nsxt_vpc_service_profile" "vpc1_service_profile" { qos_profile = nsxt_policy_qos_profile.for_vpc1.path dhcp_config { - ntp_servers = ["20.2.60.5"] + dhcp_server_config { + ntp_servers = ["20.2.60.5"] + lease_time = 50840 - lease_time = 50840 - mode = "DHCP_SERVER" + dns_client_config { + dns_server_ips = ["10.204.2.20"] + } - dns_client_config { - dns_server_ips = ["10.204.2.20"] - } - - advanced_config { - is_distributed_dhcp = false - } + advanced_config { + is_distributed_dhcp = false + } } } ``` @@ -64,18 +63,17 @@ The following arguments are supported: * `security_profile` - (Optional) Policy path for Security Profile * `qos_profile` - (Optional) Policy path for QoS profile * `dhcp_config` - (Required) DHCP configuration for this profile - * `ntp_servers` - (Optional) List of NTP servers - * `dns_client_config` - (Optional) DNS Client configuration - * `dns_server_ips` - (Optional) List of IP addresses of the DNS servers which need to be configured on the workload VMs - * `lease_time` - (Optional) DHCP lease time in seconds. - * `mode` - (Optional) DHCP mode of the VPC Profile DHCP Config. Possible values are `DHCP_SERVER`, `DHCP_RELAY`, `DHCP_DEACTIVATED`. Default is `DHCP_SERVER`. + * `dhcp_server_config` - (Optionl) DHCP server configuration for this profile + * `ntp_servers` - (Optional) List of NTP servers + * `dns_client_config` - (Optional) DNS Client configuration + * `dns_server_ips` - (Optional) List of IP addresses of the DNS servers which need to be configured on the workload VMs + * `lease_time` - (Optional) DHCP lease time in seconds. + * `advanced_config` - (Optional) VPC DHCP advanced configuration + * `is_distributed_dhcp` - DHCP server's IP allocation model based on workloads subnet port id. Can be `false` only when Edge cluster is available, in + which case edge cluster in VPC connectivity profile must be configured. This is the traditional DHCP server that dynamically allocates IP per VM's MAC. + If value is `true`, edge cluster will not be required. This is a DHCP server that dynamically assigns IP per VM port. * `dhcp_relay_config` - (Optional) DHCP Relay configuration * `server_addresses` - (Optional) List of DHCP server IP addresses for DHCP relay configuration. Both IPv4 and IPv6 addresses are supported. - * `advanced_config` - (Optional) VPC DHCP advanced configuration - * `is_distributed_dhcp` - DHCP server's IP allocation model based on workloads subnet port id. It is applicable when DHCP mode is DHCP_SERVER. - Value of this field can be False only when Edge cluster is available. If value is False, edge cluster in VPC connectivity profile must be - configured for this mode. This is the traditional DHCP server that dynamically allocates IP per VM's MAC. - If value is True, edge cluster will not be required for this mode. This is a DHCP server that dynamically assigns IP per VM port." ## Attributes Reference diff --git a/website/docs/r/vpc_subnet.html.markdown b/website/docs/r/vpc_subnet.html.markdown index 6a4d7ecb9..ad6d708f6 100644 --- a/website/docs/r/vpc_subnet.html.markdown +++ b/website/docs/r/vpc_subnet.html.markdown @@ -65,6 +65,8 @@ The following arguments are supported: * `key` - (Required) key for vendor-specific configuration * `value` - (Required) value for vendor-specific configuration * `dhcp_config` - (Optional) DHCP configuration block + * `mode` - (Optional) The operational mode of DHCP within the subnet, can be one of `DHCP_SERVER`, `DHCP_RELAY`, `DHCP_DEACTIVATED`. + Default is `DHCP_DEACTIVATED` * `ntp_servers` - (Optional) List of NTP server IP addresses * `dhcp_relay_config_path` - (Optional) Policy path of DHCP-relay-config. If configured then all the subnets will be configured with the DHCP relay server.