From 6ba0c7d2e70f87b0006133219210d53567028fd4 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Wed, 26 Oct 2022 10:06:44 +0800 Subject: [PATCH 1/5] new resource: `azurerm_private_dns_resolver_outbound_endpoint` --- ...dns_resolver_outbound_endpoint_resource.go | 254 ++++++++++++++++++ ...esolver_outbound_endpoint_resource_test.go | 200 ++++++++++++++ .../privatednsresolver/registration.go | 1 + ...s_resolver_outbound_endpoint.html.markdown | 75 ++++++ 4 files changed, 530 insertions(+) create mode 100644 internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go create mode 100644 internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource_test.go create mode 100644 website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown diff --git a/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go b/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go new file mode 100644 index 000000000000..0604b5e75ea1 --- /dev/null +++ b/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go @@ -0,0 +1,254 @@ +package privatednsresolver + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/dnsresolvers" + "github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/outboundendpoints" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +type PrivateDNSResolverOutboundEndpointModel struct { + Name string `tfschema:"name"` + PrivateDNSResolverDnsResolverId string `tfschema:"private_dns_resolver_id"` + Location string `tfschema:"location"` + SubnetId string `tfschema:"subnet_id"` + Tags map[string]string `tfschema:"tags"` +} + +type PrivateDNSResolverOutboundEndpointResource struct{} + +var _ sdk.ResourceWithUpdate = PrivateDNSResolverOutboundEndpointResource{} + +func (r PrivateDNSResolverOutboundEndpointResource) ResourceType() string { + return "azurerm_private_dns_resolver_outbound_endpoint" +} + +func (r PrivateDNSResolverOutboundEndpointResource) ModelObject() interface{} { + return &PrivateDNSResolverOutboundEndpointModel{} +} + +func (r PrivateDNSResolverOutboundEndpointResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return outboundendpoints.ValidateOutboundEndpointID +} + +func (r PrivateDNSResolverOutboundEndpointResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "private_dns_resolver_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: dnsresolvers.ValidateDnsResolverID, + }, + + "subnet_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: networkValidate.SubnetID, + }, + + "location": commonschema.Location(), + + "tags": commonschema.Tags(), + } +} + +func (r PrivateDNSResolverOutboundEndpointResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r PrivateDNSResolverOutboundEndpointResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var model PrivateDNSResolverOutboundEndpointModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + client := metadata.Client.PrivateDnsResolver.OutboundEndpointsClient + dnsResolverId, err := dnsresolvers.ParseDnsResolverID(model.PrivateDNSResolverDnsResolverId) + if err != nil { + return err + } + + id := outboundendpoints.NewOutboundEndpointID(dnsResolverId.SubscriptionId, dnsResolverId.ResourceGroupName, dnsResolverId.DnsResolverName, model.Name) + existing, err := client.Get(ctx, id) + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for existing %s: %+v", id, err) + } + + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + properties := &outboundendpoints.OutboundEndpoint{ + Location: location.Normalize(model.Location), + Properties: outboundendpoints.OutboundEndpointProperties{ + Subnet: outboundendpoints.SubResource{ + Id: model.SubnetId, + }, + }, + Tags: &model.Tags, + } + + if err := client.CreateOrUpdateThenPoll(ctx, id, *properties, outboundendpoints.CreateOrUpdateOperationOptions{}); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r PrivateDNSResolverOutboundEndpointResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.PrivateDnsResolver.OutboundEndpointsClient + + id, err := outboundendpoints.ParseOutboundEndpointID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + var model PrivateDNSResolverOutboundEndpointModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + resp, err := client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + properties := resp.Model + if properties == nil { + return fmt.Errorf("retrieving %s: properties was nil", id) + } + + properties.SystemData = nil + + if metadata.ResourceData.HasChange("tags") { + properties.Tags = &model.Tags + } + + if err := client.CreateOrUpdateThenPoll(ctx, *id, *properties, outboundendpoints.CreateOrUpdateOperationOptions{}); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r PrivateDNSResolverOutboundEndpointResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.PrivateDnsResolver.OutboundEndpointsClient + + id, err := outboundendpoints.ParseOutboundEndpointID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(id) + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + model := resp.Model + if model == nil { + return fmt.Errorf("retrieving %s: model was nil", id) + } + + state := PrivateDNSResolverOutboundEndpointModel{ + Name: id.OutboundEndpointName, + PrivateDNSResolverDnsResolverId: dnsresolvers.NewDnsResolverID(id.SubscriptionId, id.ResourceGroupName, id.DnsResolverName).ID(), + Location: location.Normalize(model.Location), + } + + properties := &model.Properties + state.SubnetId = properties.Subnet.Id + if model.Tags != nil { + state.Tags = *model.Tags + } + + return metadata.Encode(&state) + }, + } +} + +func (r PrivateDNSResolverOutboundEndpointResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.PrivateDnsResolver.OutboundEndpointsClient + + id, err := outboundendpoints.ParseOutboundEndpointID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if err := client.DeleteThenPoll(ctx, *id, outboundendpoints.DeleteOperationOptions{}); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + log.Printf("[DEBUG] waiting for %s to be deleted", id) + deadline, ok := ctx.Deadline() + if !ok { + return fmt.Errorf("context had no deadline") + } + stateConf := &pluginsdk.StateChangeConf{ + Pending: []string{"Pending"}, + Target: []string{"Succeeded"}, + Refresh: dnsResolverOutboundEndpointDeleteRefreshFunc(ctx, client, id), + MinTimeout: 1 * time.Minute, + Timeout: time.Until(deadline), + ContinuousTargetOccurence: 3, + } + if _, err = stateConf.WaitForStateContext(ctx); err != nil { + return fmt.Errorf("waiting for %s to become deleted: %+v", id, err) + } + + return nil + }, + } +} + +func dnsResolverOutboundEndpointDeleteRefreshFunc(ctx context.Context, client *outboundendpoints.OutboundEndpointsClient, id *outboundendpoints.OutboundEndpointId) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + existing, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(existing.HttpResponse) { + return existing, "Succeeded", nil + } + return existing, "", err + } + return existing, "Pending", fmt.Errorf("checking for existing %s: %+v", id, err) + } +} diff --git a/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource_test.go b/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource_test.go new file mode 100644 index 000000000000..2b1500b71338 --- /dev/null +++ b/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource_test.go @@ -0,0 +1,200 @@ +package privatednsresolver_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/outboundendpoints" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type DNSResolverOutboundEndpointResource struct{} + +func TestAccDNSResolverOutboundEndpoint_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_private_dns_resolver_outbound_endpoint", "test") + r := DNSResolverOutboundEndpointResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDNSResolverOutboundEndpoint_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_private_dns_resolver_outbound_endpoint", "test") + r := DNSResolverOutboundEndpointResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccDNSResolverOutboundEndpoint_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_private_dns_resolver_outbound_endpoint", "test") + r := DNSResolverOutboundEndpointResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDNSResolverOutboundEndpoint_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_private_dns_resolver_outbound_endpoint", "test") + r := DNSResolverOutboundEndpointResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r DNSResolverOutboundEndpointResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := outboundendpoints.ParseOutboundEndpointID(state.ID) + if err != nil { + return nil, err + } + + client := clients.PrivateDnsResolver.OutboundEndpointsClient + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return utils.Bool(false), nil + } + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + return utils.Bool(resp.Model != nil), nil +} + +func (r DNSResolverOutboundEndpointResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctest-rg-%[2]d" + location = "%[1]s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctest-rg-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_subnet" "test" { + name = "outbounddns" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefixes = ["10.0.0.64/28"] + + delegation { + name = "Microsoft.Network.dnsResolvers" + service_delegation { + actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"] + name = "Microsoft.Network/dnsResolvers" + } + } +} + +resource "azurerm_private_dns_resolver" "test" { + name = "acctest-dr-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + virtual_network_id = azurerm_virtual_network.test.id +} +`, data.Locations.Primary, data.RandomInteger) +} + +func (r DNSResolverOutboundEndpointResource) basic(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_private_dns_resolver_outbound_endpoint" "test" { + name = "acctest-droe-%d" + private_dns_resolver_id = azurerm_private_dns_resolver.test.id + location = azurerm_private_dns_resolver.test.location + subnet_id = azurerm_subnet.test.id +} +`, template, data.RandomInteger) +} + +func (r DNSResolverOutboundEndpointResource) requiresImport(data acceptance.TestData) string { + config := r.basic(data) + return fmt.Sprintf(` + %s + +resource "azurerm_private_dns_resolver_outbound_endpoint" "import" { + name = azurerm_private_dns_resolver_outbound_endpoint.test.name + private_dns_resolver_id = azurerm_private_dns_resolver_outbound_endpoint.test.private_dns_resolver_id + location = azurerm_private_dns_resolver_outbound_endpoint.test.location + subnet_id = azurerm_private_dns_resolver_outbound_endpoint.test.subnet_id +} +`, config) +} + +func (r DNSResolverOutboundEndpointResource) complete(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_private_dns_resolver_outbound_endpoint" "test" { + name = "acctest-droe-%d" + private_dns_resolver_id = azurerm_private_dns_resolver.test.id + location = azurerm_private_dns_resolver.test.location + subnet_id = azurerm_subnet.test.id + tags = { + key = "value" + } +} +`, template, data.RandomInteger) +} + +func (r DNSResolverOutboundEndpointResource) update(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s +resource "azurerm_private_dns_resolver_outbound_endpoint" "test" { + name = "acctest-droe-%d" + private_dns_resolver_id = azurerm_private_dns_resolver.test.id + location = azurerm_private_dns_resolver.test.location + subnet_id = azurerm_subnet.test.id + tags = { + key = "updated value" + } +} +`, template, data.RandomInteger) +} diff --git a/internal/services/privatednsresolver/registration.go b/internal/services/privatednsresolver/registration.go index 60bf0a8adeb5..a05b40a02e1f 100644 --- a/internal/services/privatednsresolver/registration.go +++ b/internal/services/privatednsresolver/registration.go @@ -47,5 +47,6 @@ func (r Registration) DataSources() []sdk.DataSource { func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ PrivateDNSResolverDnsResolverResource{}, + PrivateDNSResolverOutboundEndpointResource{}, } } diff --git a/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown new file mode 100644 index 000000000000..4c27b5af4088 --- /dev/null +++ b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown @@ -0,0 +1,75 @@ +--- +subcategory: "Private DNS Resolver" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_private_dns_resolver_outbound_endpoint" +description: |- + Manages a Private DNS Resolver Outbound Endpoint. +--- + +# azurerm_private_dns_resolver_outbound_endpoint + +Manages a Private DNS Resolver Outbound Endpoint. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_private_dns_resolver_private_dns_resolver" "example" { + name = "example-drdr" + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_private_dns_resolver_outbound_endpoint" "example" { + name = "example-droe" + private_dns_resolver_private_dns_resolver_id = azurerm_private_dns_resolver_private_dns_resolver.test.id + location = "West Europe" + subnet { + id = "" + } + tags = { + key = "value" + } + +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name which should be used for this Private DNS Resolver Outbound Endpoint. Changing this forces a new Private DNS Resolver Outbound Endpoint to be created. + +* `private_dns_resolver_private_dns_resolver_id` - (Required) Specifies the ID of the Private DNS Resolver Outbound Endpoint. Changing this forces a new Private DNS Resolver Outbound Endpoint to be created. + +* `location` - (Required) Specifies the Azure Region where the Private DNS Resolver Outbound Endpoint should exist. Changing this forces a new Private DNS Resolver Outbound Endpoint to be created. + +* `subnet_id` - (Required) The ID of the Subnet that is linked to the Private DNS Resolver Outbound Endpoint. + +* `tags` - (Optional) A mapping of tags which should be assigned to the Private DNS Resolver Outbound Endpoint. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Private DNS Resolver Outbound Endpoint. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Private DNS Resolver Outbound Endpoint. +* `read` - (Defaults to 5 minutes) Used when retrieving the Private DNS Resolver Outbound Endpoint. +* `update` - (Defaults to 30 minutes) Used when updating the Private DNS Resolver Outbound Endpoint. +* `delete` - (Defaults to 30 minutes) Used when deleting the Private DNS Resolver Outbound Endpoint. + +## Import + +Private DNS Resolver Outbound Endpoint can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_private_dns_resolver_outbound_endpoint.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Network/dnsResolvers/dnsResolver1/outboundEndpoints/outboundEndpoint1 +``` From 2a55a1b40a6ee96d903220905b8dd742291a7a01 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 27 Oct 2022 09:48:34 +0800 Subject: [PATCH 2/5] update docs --- ...rivate_dns_resolver_outbound_endpoint.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown index 4c27b5af4088..c13c6c9289bf 100644 --- a/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown +++ b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown @@ -18,15 +18,15 @@ resource "azurerm_resource_group" "example" { location = "West Europe" } -resource "azurerm_private_dns_resolver_private_dns_resolver" "example" { +resource "azurerm_private_dns_resolver" "example" { name = "example-drdr" resource_group_name = azurerm_resource_group.example.name } resource "azurerm_private_dns_resolver_outbound_endpoint" "example" { - name = "example-droe" - private_dns_resolver_private_dns_resolver_id = azurerm_private_dns_resolver_private_dns_resolver.test.id - location = "West Europe" + name = "example-droe" + private_dns_resolver_id = azurerm_private_dns_resolver.test.id + location = "West Europe" subnet { id = "" } @@ -43,7 +43,7 @@ The following arguments are supported: * `name` - (Required) Specifies the name which should be used for this Private DNS Resolver Outbound Endpoint. Changing this forces a new Private DNS Resolver Outbound Endpoint to be created. -* `private_dns_resolver_private_dns_resolver_id` - (Required) Specifies the ID of the Private DNS Resolver Outbound Endpoint. Changing this forces a new Private DNS Resolver Outbound Endpoint to be created. +* `private_dns_resolver_id` - (Required) Specifies the ID of the Private DNS Resolver Outbound Endpoint. Changing this forces a new Private DNS Resolver Outbound Endpoint to be created. * `location` - (Required) Specifies the Azure Region where the Private DNS Resolver Outbound Endpoint should exist. Changing this forces a new Private DNS Resolver Outbound Endpoint to be created. From 9b2f644d5963900c64e6fe42bb5a17174f6546b1 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 27 Oct 2022 10:06:06 +0800 Subject: [PATCH 3/5] update docs --- ...s_resolver_outbound_endpoint.html.markdown | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown index c13c6c9289bf..61bcad8cac5d 100644 --- a/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown +++ b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown @@ -15,25 +15,46 @@ Manages a Private DNS Resolver Outbound Endpoint. ```hcl resource "azurerm_resource_group" "example" { name = "example-resources" - location = "West Europe" + location = "west europe" +} + +resource "azurerm_virtual_network" "example" { + name = "example-vnet" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_subnet" "example" { + name = "outbounddns" + resource_group_name = azurerm_resource_group.example.name + virtual_network_name = azurerm_virtual_network.example.name + address_prefixes = ["10.0.0.64/28"] + + delegation { + name = "Microsoft.Network.dnsResolvers" + service_delegation { + actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"] + name = "Microsoft.Network/dnsResolvers" + } + } } resource "azurerm_private_dns_resolver" "example" { - name = "example-drdr" + name = "example-resolver" resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + virtual_network_id = azurerm_virtual_network.example.id } resource "azurerm_private_dns_resolver_outbound_endpoint" "example" { - name = "example-droe" - private_dns_resolver_id = azurerm_private_dns_resolver.test.id - location = "West Europe" - subnet { - id = "" - } + name = "example-endpoint" + private_dns_resolver_id = azurerm_private_dns_resolver.example.id + location = azurerm_private_dns_resolver.example.location + subnet_id = azurerm_subnet.test.id tags = { key = "value" } - } ``` From 2dbe797c633b5435f60d45765d4a4ee0e5b17e3a Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 27 Oct 2022 10:06:31 +0800 Subject: [PATCH 4/5] update docs --- .../docs/r/private_dns_resolver_outbound_endpoint.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown index 61bcad8cac5d..2d910441198e 100644 --- a/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown +++ b/website/docs/r/private_dns_resolver_outbound_endpoint.html.markdown @@ -51,7 +51,7 @@ resource "azurerm_private_dns_resolver_outbound_endpoint" "example" { name = "example-endpoint" private_dns_resolver_id = azurerm_private_dns_resolver.example.id location = azurerm_private_dns_resolver.example.location - subnet_id = azurerm_subnet.test.id + subnet_id = azurerm_subnet.example.id tags = { key = "value" } From 4ce60b8e487de2e39cb0316872d388c127a8877a Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 27 Oct 2022 13:46:15 +0800 Subject: [PATCH 5/5] update model --- ...e_dns_resolver_inbound_endpoint_resource.go | 18 +++++++++--------- ..._dns_resolver_outbound_endpoint_resource.go | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/services/privatednsresolver/private_dns_resolver_inbound_endpoint_resource.go b/internal/services/privatednsresolver/private_dns_resolver_inbound_endpoint_resource.go index 16a9399e2210..88112a74cd32 100644 --- a/internal/services/privatednsresolver/private_dns_resolver_inbound_endpoint_resource.go +++ b/internal/services/privatednsresolver/private_dns_resolver_inbound_endpoint_resource.go @@ -19,11 +19,11 @@ import ( ) type PrivateDNSResolverInboundEndpointModel struct { - Name string `tfschema:"name"` - PrivateDNSResolverDnsResolverId string `tfschema:"private_dns_resolver_id"` - IPConfigurations []IPConfigurationModel `tfschema:"ip_configurations"` - Location string `tfschema:"location"` - Tags map[string]string `tfschema:"tags"` + Name string `tfschema:"name"` + PrivateDNSResolverId string `tfschema:"private_dns_resolver_id"` + IPConfigurations []IPConfigurationModel `tfschema:"ip_configurations"` + Location string `tfschema:"location"` + Tags map[string]string `tfschema:"tags"` } type IPConfigurationModel struct { @@ -112,7 +112,7 @@ func (r PrivateDNSResolverInboundEndpointResource) Create() sdk.ResourceFunc { } client := metadata.Client.PrivateDnsResolver.InboundEndpointsClient - dnsResolverId, err := dnsresolvers.ParseDnsResolverID(model.PrivateDNSResolverDnsResolverId) + dnsResolverId, err := dnsresolvers.ParseDnsResolverID(model.PrivateDNSResolverId) if err != nil { return err } @@ -230,9 +230,9 @@ func (r PrivateDNSResolverInboundEndpointResource) Read() sdk.ResourceFunc { } state := PrivateDNSResolverInboundEndpointModel{ - Name: id.InboundEndpointName, - PrivateDNSResolverDnsResolverId: dnsresolvers.NewDnsResolverID(id.SubscriptionId, id.ResourceGroupName, id.DnsResolverName).ID(), - Location: location.Normalize(model.Location), + Name: id.InboundEndpointName, + PrivateDNSResolverId: dnsresolvers.NewDnsResolverID(id.SubscriptionId, id.ResourceGroupName, id.DnsResolverName).ID(), + Location: location.Normalize(model.Location), } properties := &model.Properties diff --git a/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go b/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go index 0604b5e75ea1..585ec1919741 100644 --- a/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go +++ b/internal/services/privatednsresolver/private_dns_resolver_outbound_endpoint_resource.go @@ -19,11 +19,11 @@ import ( ) type PrivateDNSResolverOutboundEndpointModel struct { - Name string `tfschema:"name"` - PrivateDNSResolverDnsResolverId string `tfschema:"private_dns_resolver_id"` - Location string `tfschema:"location"` - SubnetId string `tfschema:"subnet_id"` - Tags map[string]string `tfschema:"tags"` + Name string `tfschema:"name"` + PrivateDNSResolverId string `tfschema:"private_dns_resolver_id"` + Location string `tfschema:"location"` + SubnetId string `tfschema:"subnet_id"` + Tags map[string]string `tfschema:"tags"` } type PrivateDNSResolverOutboundEndpointResource struct{} @@ -85,7 +85,7 @@ func (r PrivateDNSResolverOutboundEndpointResource) Create() sdk.ResourceFunc { } client := metadata.Client.PrivateDnsResolver.OutboundEndpointsClient - dnsResolverId, err := dnsresolvers.ParseDnsResolverID(model.PrivateDNSResolverDnsResolverId) + dnsResolverId, err := dnsresolvers.ParseDnsResolverID(model.PrivateDNSResolverId) if err != nil { return err } @@ -187,9 +187,9 @@ func (r PrivateDNSResolverOutboundEndpointResource) Read() sdk.ResourceFunc { } state := PrivateDNSResolverOutboundEndpointModel{ - Name: id.OutboundEndpointName, - PrivateDNSResolverDnsResolverId: dnsresolvers.NewDnsResolverID(id.SubscriptionId, id.ResourceGroupName, id.DnsResolverName).ID(), - Location: location.Normalize(model.Location), + Name: id.OutboundEndpointName, + PrivateDNSResolverId: dnsresolvers.NewDnsResolverID(id.SubscriptionId, id.ResourceGroupName, id.DnsResolverName).ID(), + Location: location.Normalize(model.Location), } properties := &model.Properties