Skip to content

Commit

Permalink
Merge pull request #1064 from qiyueyao/datasource-dns-forwarder
Browse files Browse the repository at this point in the history
Datasource Gateway DNS Forwarder
  • Loading branch information
qiyueyao authored Jan 22, 2024
2 parents 1c61486 + ebf4f92 commit e4a68a6
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
40 changes: 40 additions & 0 deletions nsxt/data_source_nsxt_policy_gateway_dns_forwarder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"fmt"

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

func dataSourceNsxtPolicyGatewayDNSForwarder() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtPolicyGatewayDNSForwarderRead,

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

func dataSourceNsxtPolicyGatewayDNSForwarderRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)

gwPath := d.Get("gateway_path").(string)
query := make(map[string]string)
if len(gwPath) > 0 {
query["parent_path"] = fmt.Sprintf("%s*", gwPath)
}
_, err := policyDataSourceResourceReadWithValidation(d, connector, getSessionContext(d, m), "PolicyDnsForwarder", query, false)
if err != nil {
return err
}
return nil
}
1 change: 1 addition & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func Provider() *schema.Provider {
"nsxt_policy_l2_vpn_service": dataSourceNsxtPolicyL2VpnService(),
"nsxt_policy_segment": dataSourceNsxtPolicySegment(),
"nsxt_policy_project": dataSourceNsxtPolicyProject(),
"nsxt_policy_gateway_dns_forwarder": dataSourceNsxtPolicyGatewayDNSForwarder(),
"nsxt_policy_gateway_prefix_list": dataSourceNsxtPolicyGatewayPrefixList(),
"nsxt_policy_gateway_route_map": dataSourceNsxtPolicyGatewayRouteMap(),
"nsxt_policy_uplink_host_switch_profile": dataSourceNsxtUplinkHostSwitchProfile(),
Expand Down
10 changes: 9 additions & 1 deletion nsxt/resource_nsxt_policy_gateway_dns_forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ resource "nsxt_policy_gateway_dns_forwarder" "test" {
tag = "tag1"
}
}
`, context, attrMap["display_name"], attrMap["description"], whyDoesGoNeedToBeSoComplicated[isT0], attrMap["listener_ip"], attrMap["enabled"], attrMap["log_level"], attrMap["cache_size"])
data "nsxt_policy_gateway_dns_forwarder" "test" {
%s
display_name = "%s"
gateway_path = nsxt_policy_tier%d_gateway.test.path
depends_on = [nsxt_policy_gateway_dns_forwarder.test]
}
`, context, attrMap["display_name"], attrMap["description"], whyDoesGoNeedToBeSoComplicated[isT0], attrMap["listener_ip"], attrMap["enabled"], attrMap["log_level"], attrMap["cache_size"], context, attrMap["display_name"], whyDoesGoNeedToBeSoComplicated[isT0])
}

func testAccNsxtPolicyGatewayDNSForwarderMinimalistic(isT0, withContext bool) string {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/policy_context_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data "nsxt_policy_context_profile" "demoprof" {
* `id` - (Optional) The ID of Profile to retrieve.
* `display_name` - (Optional) The Display Name prefix of the Profile to retrieve.
* `context` - (Optional) The context which the object belongs to
* `project_id` - (Required) The ID of the project which the object belongs to
* `project_id` - (Required) The ID of the project which the object belongs to

## Attributes Reference

Expand Down
36 changes: 36 additions & 0 deletions website/docs/d/policy_gateway_dns_forwarder.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
subcategory: "DNS"
layout: "nsxt"
page_title: "NSXT: policy_gateway_dns_forwarder"
description: A policy gateway DNS forwarder data source.
---

# nsxt_policy_gateway_dns_forwarder

This data source provides information about policy gateways DNS forwarder.

This data source is applicable to NSX Policy Manager, NSX Global Manager and VMC.

## Example Usage

```hcl
data "nsxt_policy_gateway_dns_forwarder" "my_dns_forwarder" {
display_name = "dns-forwarder1"
gateway_path = data.nsxt_policy_tier1_gateway.path
}
```

## Argument Reference

* `id` - (Optional) The ID of gateway DNS forwarder to retrieve.
* `display_name` - (Optional) The Display Name of the gateway DNS forwarder to retrieve.
* `gateway_path` - (Optional) Gateway Path for this Service.
* `context` - (Optional) 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 e4a68a6

Please sign in to comment.