Skip to content

Commit

Permalink
Adjust to DHCP changes in service and subnet
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Khmelnitsky <[email protected]>
  • Loading branch information
annakhm committed Nov 18, 2024
1 parent 8aa682d commit f6e2b6e
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 406 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/resource_nsxt_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
164 changes: 89 additions & 75 deletions nsxt/resource_nsxt_vpc_service_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -101,7 +81,7 @@ var vpcServiceProfileSchema = map[string]*metadata.ExtendedSchema{
},
Metadata: metadata.Metadata{
SchemaType: "list",
SdkFieldName: "DnsServerIps",
SdkFieldName: "ServerAddresses",
},
},
},
Expand All @@ -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",
Expand All @@ -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{}),
},
},
},
Expand All @@ -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{}),
},
},
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -368,6 +376,12 @@ func resourceNsxtVpcServiceProfileUpdate(d *schema.ResourceData, m interface{})
if err := metadata.SchemaToStruct(elem, d, vpcServiceProfileSchema, "", nil); err != nil {
return err
}

Check failure on line 379 in nsxt/resource_nsxt_vpc_service_profile.go

View workflow job for this annotation

GitHub Actions / test

File is not `gofmt`-ed with `-s` (gofmt)
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 {
Expand Down
Loading

0 comments on commit f6e2b6e

Please sign in to comment.