Skip to content

Commit

Permalink
Add VPC profile data sources
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Khmelnitsky <[email protected]>
  • Loading branch information
annakhm committed Aug 30, 2024
1 parent 9eb0556 commit aa1d87f
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 3 deletions.
30 changes: 30 additions & 0 deletions nsxt/data_source_nsxt_vpc_connectivity_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright © 2020 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceNsxtVpcConnectivityProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtVpcConnectivityProfileRead,

Schema: map[string]*schema.Schema{
"id": getDataSourceIDSchema(),
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(true, false, false),
},
}
}

func dataSourceNsxtVpcConnectivityProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "VpcConnectivityProfile", nil)
if err != nil {
return err
}
return nil
}
30 changes: 30 additions & 0 deletions nsxt/data_source_nsxt_vpc_service_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright © 2020 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceNsxtVpcServiceProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtVpcServiceProfileRead,

Schema: map[string]*schema.Schema{
"id": getDataSourceIDSchema(),
"display_name": getDataSourceDisplayNameSchema(),
"description": getDataSourceDescriptionSchema(),
"path": getPathSchema(),
"context": getContextSchema(true, false, false),
},
}
}

func dataSourceNsxtVpcServiceProfileRead(d *schema.ResourceData, m interface{}) error {
_, err := policyDataSourceResourceRead(d, getPolicyConnector(m), getSessionContext(d, m), "VpcServiceProfile", nil)
if err != nil {
return err
}
return nil
}
2 changes: 2 additions & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ func Provider() *schema.Provider {
"nsxt_vpc_nat": dataSourceNsxtVpcNat(),
"nsxt_vpc_subnet": dataSourceNsxtVpcSubnet(),
"nsxt_vpc_subnet_port": dataSourceNsxtVpcSubnetPort(),
"nsxt_vpc_service_profile": dataSourceNsxtVpcServiceProfile(),
"nsxt_vpc_connectivity_profile": dataSourceNsxtVpcConnectivityProfile(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
14 changes: 12 additions & 2 deletions nsxt/resource_nsxt_vpc_connectivity_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var accTestVpcConnectivityProfileUpdateAttributes = map[string]string{

func TestAccResourceNsxtVpcConnectivityProfile_basic(t *testing.T) {
testResourceName := "nsxt_vpc_connectivity_profile.test"
testDataSourceName := "nsxt_vpc_connectivity_profile.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -42,6 +43,8 @@ func TestAccResourceNsxtVpcConnectivityProfile_basic(t *testing.T) {
Config: testAccNsxtVpcConnectivityProfileTemplate(true),
Check: resource.ComposeTestCheckFunc(
testAccNsxtVpcConnectivityProfileExists(accTestVpcConnectivityProfileCreateAttributes["display_name"], testResourceName),
resource.TestCheckResourceAttrSet(testDataSourceName, "path"),
resource.TestCheckResourceAttrSet(testDataSourceName, "description"),
resource.TestCheckResourceAttr(testResourceName, "display_name", accTestVpcConnectivityProfileCreateAttributes["display_name"]),
resource.TestCheckResourceAttr(testResourceName, "description", accTestVpcConnectivityProfileCreateAttributes["description"]),
resource.TestCheckResourceAttrSet(testResourceName, "transit_gateway_path"),
Expand All @@ -60,6 +63,8 @@ func TestAccResourceNsxtVpcConnectivityProfile_basic(t *testing.T) {
Config: testAccNsxtVpcConnectivityProfileTemplate(false),
Check: resource.ComposeTestCheckFunc(
testAccNsxtVpcConnectivityProfileExists(accTestVpcConnectivityProfileUpdateAttributes["display_name"], testResourceName),
resource.TestCheckResourceAttrSet(testDataSourceName, "path"),
resource.TestCheckResourceAttrSet(testDataSourceName, "description"),
resource.TestCheckResourceAttr(testResourceName, "display_name", accTestVpcConnectivityProfileUpdateAttributes["display_name"]),
resource.TestCheckResourceAttr(testResourceName, "description", accTestVpcConnectivityProfileUpdateAttributes["description"]),
resource.TestCheckResourceAttrSet(testResourceName, "transit_gateway_path"),
Expand Down Expand Up @@ -197,12 +202,17 @@ resource "nsxt_vpc_connectivity_profile" "test" {
enable = %s
}
tag {
scope = "scope1"
tag = "tag1"
}
}`, testAccNsxtProjectContext(), attrMap["display_name"], attrMap["description"], attrMap["enable_default_snat"], attrMap["enable"])
}
data "nsxt_vpc_connectivity_profile" "test" {
%s
display_name = "%s"
depends_on = [nsxt_vpc_connectivity_profile.test]
}`, testAccNsxtProjectContext(), attrMap["display_name"], attrMap["description"], attrMap["enable_default_snat"], attrMap["enable"], testAccNsxtProjectContext(), attrMap["display_name"])
}

func testAccNsxtVpcConnectivityProfileMinimalistic() string {
Expand Down
14 changes: 13 additions & 1 deletion nsxt/resource_nsxt_vpc_service_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var accTestPolicyVpcServiceProfileUpdateAttributes = map[string]string{

func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) {
testResourceName := "nsxt_vpc_service_profile.test"
testDataSourceName := "data.nsxt_vpc_service_profile.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccOnlyVPC(t) },
Expand All @@ -49,6 +50,8 @@ func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) {
Config: testAccNsxtVpcServiceProfileTemplate(true, false),
Check: resource.ComposeTestCheckFunc(
testAccNsxtVpcServiceProfileExists(accTestPolicyVpcServiceProfileCreateAttributes["display_name"], testResourceName),
resource.TestCheckResourceAttrSet(testDataSourceName, "path"),
resource.TestCheckResourceAttrSet(testDataSourceName, "description"),
resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyVpcServiceProfileCreateAttributes["display_name"]),
resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyVpcServiceProfileCreateAttributes["description"]),
resource.TestCheckResourceAttr(testResourceName, "dns_forwarder_config.#", "1"),
Expand All @@ -72,6 +75,8 @@ func TestAccResourceNsxtVpcServiceProfile_basic(t *testing.T) {
Config: testAccNsxtVpcServiceProfileTemplate(true, true),
Check: resource.ComposeTestCheckFunc(
testAccNsxtVpcServiceProfileExists(accTestPolicyVpcServiceProfileCreateAttributes["display_name"], testResourceName),
resource.TestCheckResourceAttrSet(testDataSourceName, "path"),
resource.TestCheckResourceAttrSet(testDataSourceName, "description"),
resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyVpcServiceProfileCreateAttributes["display_name"]),
resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyVpcServiceProfileCreateAttributes["description"]),
resource.TestCheckResourceAttr(testResourceName, "dns_forwarder_config.#", "1"),
Expand Down Expand Up @@ -283,7 +288,14 @@ resource "nsxt_vpc_service_profile" "test" {
scope = "scope1"
tag = "tag1"
}
}`, testAccNsxtProjectContext(), profileAssignment, attrMap["display_name"], attrMap["description"], attrMap["ntp_servers"], attrMap["lease_time"], attrMap["mode"], attrMap["dns_server_ips"], attrMap["cache_size"], attrMap["log_level"])
}
data "nsxt_vpc_service_profile" "test" {
%s
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"], attrMap["cache_size"], attrMap["log_level"], testAccNsxtProjectContext(), attrMap["display_name"])
}

func testAccNsxtVpcServiceProfileMinimalistic() string {
Expand Down
41 changes: 41 additions & 0 deletions website/docs/d/vpc_connectivity_profile.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
subcategory: "VPC"
layout: "nsxt"
page_title: "NSXT: vpc_connectivity_profile"
description: VPC Connectivity Profile data source.
---

# nsxt_vpc_connectivity_profile

This data source provides information about an inventory Connectivity Profile configured under VPC on NSX.

This data source is applicable to NSX Policy Manager.

## Example Usage

```hcl
data "nsxt_policy_project" "demoproj" {
display_name = "demoproj"
}
data "nsxt_vpc_connectivity_profile" "test" {
context {
project_id = data.nsxt_policy_project.demoproj.id
}
display_name = "profile1"
}
```

## Argument Reference

* `id` - (Optional) The ID of Connectivity Profile to retrieve.
* `display_name` - (Optional) The Display Name prefix of the Connectivity Profile to retrieve.
* `context` - (Required) The context which the object belongs to
* `project_id` - (Required) The ID of the project which the object belongs to

## Attributes Reference

In addition to arguments listed above, the following attributes are exported:

* `description` - The description of the resource.
* `path` - The NSX path of the policy resource.
41 changes: 41 additions & 0 deletions website/docs/d/vpc_service_profile.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
subcategory: "VPC"
layout: "nsxt"
page_title: "NSXT: vpc_service_profile"
description: VPC Service Profile data source.
---

# nsxt_vpc_service_profile

This data source provides information about an inventory Service Profile configured under VPC on NSX.

This data source is applicable to NSX Policy Manager.

## Example Usage

```hcl
data "nsxt_policy_project" "demoproj" {
display_name = "demoproj"
}
data "nsxt_vpc_service_profile" "test" {
context {
project_id = data.nsxt_policy_project.demoproj.id
}
display_name = "profile1"
}
```

## Argument Reference

* `id` - (Optional) The ID of Service Profile to retrieve.
* `display_name` - (Optional) The Display Name prefix of the Service Profile to retrieve.
* `context` - (Required) The context which the object belongs to
* `project_id` - (Required) The ID of the project which the object belongs to

## Attributes Reference

In addition to arguments listed above, the following attributes are exported:

* `description` - The description of the resource.
* `path` - The NSX path of the policy resource.

0 comments on commit aa1d87f

Please sign in to comment.