Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VPC data source #1207

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_context_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyContextProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_dhcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyDhcpServer() *schema.Resource {
"display_name": getDataSourceExtendedDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyDistributedFloodProtectionProfile() *schema.Resource {
"display_name": getDataSourceExtendedDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_gateway_dns_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func dataSourceNsxtPolicyGatewayDNSForwarder() *schema.Resource {
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"gateway_path": getPolicyPathSchema(false, false, "Gateway path"),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyGatewayFloodProtectionProfile() *schema.Resource {
"display_name": getDataSourceExtendedDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func dataSourceNsxtPolicyGatewayInterfaceRealization() *schema.Resource {

Schema: map[string]*schema.Schema{
"id": getDataSourceIDSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
"gateway_path": {
Type: schema.TypeString,
Description: "The path for the gateway",
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_gateway_locale_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func dataSourceNsxtPolicyGatewayLocaleService() *schema.Resource {
Optional: true,
Computed: true,
},
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_gateway_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func dataSourceNsxtPolicyGatewayPolicy() *schema.Resource {
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"domain": getDataSourceDomainNameSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
"category": {
Type: schema.TypeString,
Description: "Category",
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_gateway_qos_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyGatewayQosProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func dataSourceNsxtPolicyGroup() *schema.Resource {
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"domain": getDomainNameSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_intrusion_service_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyIntrusionServiceProfile() *schema.Resource {
"display_name": getDataSourceExtendedDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ip_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func dataSourceNsxtPolicyIPBlock() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
12 changes: 6 additions & 6 deletions nsxt/data_source_nsxt_policy_ip_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func testAccDataSourceNsxtPolicyIPBlockBasic(t *testing.T, withContext bool, pre
Steps: []resource.TestStep{
{
PreConfig: func() {
if err := testAccDataSourceNsxtPolicyIPBlockCreate(name); err != nil {
if err := testAccDataSourceNsxtPolicyIPBlockCreate(name, newUUID(), "4001::/64", false); err != nil {
t.Error(err)
}
},
Expand All @@ -57,7 +57,7 @@ func testAccDataSourceNsxtPolicyIPBlockBasic(t *testing.T, withContext bool, pre
})
}

func testAccDataSourceNsxtPolicyIPBlockCreate(name string) error {
func testAccDataSourceNsxtPolicyIPBlockCreate(name, id, cidr string, isPrivate bool) error {
connector, err := testAccGetPolicyConnector()
if err != nil {
return fmt.Errorf("Error during test client initialization: %v", err)
Expand All @@ -66,15 +66,15 @@ func testAccDataSourceNsxtPolicyIPBlockCreate(name string) error {

displayName := name
description := name
cidr := "4001::/64"
obj := model.IpAddressBlock{
Description: &description,
DisplayName: &displayName,
Cidr: &cidr,
}

// Generate a random ID for the resource
id := newUUID()
if isPrivate {
visibility := model.IpAddressBlock_VISIBILITY_PRIVATE
obj.Visibility = &visibility
}

err = client.Patch(id, obj)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ip_discovery_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyIPDiscoveryProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ip_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func dataSourceNsxtPolicyIPPool() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
"realized_id": {
Type: schema.TypeString,
Description: "The ID of the realized resource",
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ipv6_dad_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyIpv6DadProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_ipv6_ndra_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyIpv6NdraProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_mac_discovery_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyMacDiscoveryProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
41 changes: 22 additions & 19 deletions nsxt/data_source_nsxt_policy_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,7 @@ func dataSourceNsxtPolicyProject() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"site_info": {
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"edge_cluster_paths": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
"site_path": {
Type: schema.TypeString,
Optional: true,
},
},
},
Optional: true,
},
"site_info": getSiteInfoSchema(),
"tier0_gateway_paths": {
Type: schema.TypeList,
Elem: &schema.Schema{
Expand All @@ -57,6 +39,27 @@ func dataSourceNsxtPolicyProject() *schema.Resource {
}
}

func getSiteInfoSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"edge_cluster_paths": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
"site_path": {
Type: schema.TypeString,
Optional: true,
},
},
},
Optional: true,
}
}
func dataSourceNsxtPolicyProjectRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)
client := infra.NewProjectsClient(connector)
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_qos_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyQosProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_realization_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func dataSourceNsxtPolicyRealizationInfo() *schema.Resource {
Required: true,
ValidateFunc: validatePolicyPath(),
},
"context": getContextSchema(),
"context": getContextSchema(false, false),
"entity_type": {
Type: schema.TypeString,
Description: "The entity type of the realized resource",
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func dataSourceNsxtPolicySecurityPolicy() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
"domain": getDataSourceDomainNameSchema(),
"is_default": {
Type: schema.TypeBool,
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicySegment() *schema.Resource {
"display_name": getDataSourceExtendedDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_segment_realization.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func dataSourceNsxtPolicySegmentRealization() *schema.Resource {

Schema: map[string]*schema.Schema{
"id": getDataSourceIDSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
"path": {
Type: schema.TypeString,
Description: "The path for the policy segment",
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_segment_security_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicySegmentSecurityProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicyService() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_spoofguard_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceNsxtPolicySpoofGuardProfile() *schema.Resource {
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_tier1_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func dataSourceNsxtPolicyTier1Gateway() *schema.Resource {
Optional: true,
Computed: true,
},
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func dataSourceNsxtPolicyVM() *schema.Resource {
"external_id": getDataSourceStringSchema("External ID of the Virtual Machine"),
"bios_id": getDataSourceStringSchema("BIOS UUID of the Virtual Machine"),
"instance_id": getDataSourceStringSchema("Instance UUID of the Virtual Machine"),
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsxt/data_source_nsxt_policy_vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func dataSourceNsxtPolicyVMs() *schema.Resource {
Type: schema.TypeString,
},
},
"context": getContextSchema(),
"context": getContextSchema(false, false),
},
}
}
Expand Down
45 changes: 45 additions & 0 deletions nsxt/data_source_nsxt_policy_vpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Copyright © 2024 Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/vsphere-automation-sdk-go/runtime/bindings"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
)

func dataSourceNsxtPolicyVPC() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtPolicyVPCRead,
Schema: map[string]*schema.Schema{
"id": getDataSourceIDSchema(),
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(true, false),
"short_id": {
Type: schema.TypeString,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the code this is fully computed, in which case Optional: true should be removed, so that terraform does not allow user to specify it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is assigned by NSX if not set by user, and therefore has to be computed. It can also be set by the user (it should be unique - NSX will enforce that).
The UI doesn't allow updating it (on create there's the text "This field can be set at VPC creation time and cannot be edited later. Max 8 characters allowed.").
BTW there's an open issue for this in the Project.

},
},
}
}

func dataSourceNsxtPolicyVPCRead(d *schema.ResourceData, m interface{}) error {
obj, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "Vpc", nil)
if err != nil {
return err
}

converter := bindings.NewTypeConverter()
dataValue, errors := converter.ConvertToGolang(obj, model.VpcBindingType())
if len(errors) > 0 {
return errors[0]
}
vpc := dataValue.(model.Vpc)

d.Set("short_id", vpc.ShortId)

return nil
}
Loading
Loading