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

azurerm_private_endpoint - expose private_dns_zone_group, private_dns_zone_configs, and custom_dns_configs #7246

Merged
merged 18 commits into from Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions azurerm/internal/services/network/client/client.go
Expand Up @@ -42,6 +42,7 @@ type Client struct {
VpnServerConfigurationsClient *network.VpnServerConfigurationsClient
WatcherClient *network.WatchersClient
WebApplicationFirewallPoliciesClient *network.WebApplicationFirewallPoliciesClient
PrivateDnsZoneGroupClient *network.PrivateDNSZoneGroupsClient
PrivateLinkServiceClient *network.PrivateLinkServicesClient
}

Expand Down Expand Up @@ -112,6 +113,9 @@ func NewClient(o *common.ClientOptions) *Client {
PublicIPPrefixesClient := network.NewPublicIPPrefixesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PublicIPPrefixesClient.Client, o.ResourceManagerAuthorizer)

PrivateDnsZoneGroupClient := network.NewPrivateDNSZoneGroupsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PrivateDnsZoneGroupClient.Client, o.ResourceManagerAuthorizer)

PrivateLinkServiceClient := network.NewPrivateLinkServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PrivateLinkServiceClient.Client, o.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -194,6 +198,7 @@ func NewClient(o *common.ClientOptions) *Client {
VpnServerConfigurationsClient: &vpnServerConfigurationsClient,
WatcherClient: &WatcherClient,
WebApplicationFirewallPoliciesClient: &WebApplicationFirewallPoliciesClient,
PrivateDnsZoneGroupClient: &PrivateDnsZoneGroupClient,
PrivateLinkServiceClient: &PrivateLinkServiceClient,
}
}
71 changes: 71 additions & 0 deletions azurerm/internal/services/network/parse/private_endpoint.go
@@ -0,0 +1,71 @@
package parse

import (
"fmt"
"strings"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type NameResourceGroup struct {
ResourceGroup string
Name string
ID string
}

func PrivateDnsZoneGroupResourceID(input string) (nrg NameResourceGroup, err error) {
WodansSon marked this conversation as resolved.
Show resolved Hide resolved
if len(strings.TrimSpace(input)) == 0 {
return NameResourceGroup{}, fmt.Errorf("input is empty for parse.PrivateDnsZoneGroupResourceID")
}

id, err := azure.ParseAzureResourceID(input)
if err != nil {
return NameResourceGroup{}, fmt.Errorf("unable to parse Private DNS Zone Group ID %q: %+v", input, err)
}

privateDnsZoneGroup := NameResourceGroup{
Name: id.Path["privateDnsZoneGroups"],
ResourceGroup: id.ResourceGroup,
ID: input,
}
Copy link
Member

Choose a reason for hiding this comment

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

we should use the PopSegment and ValidateNoEmptySegments functions here to ensure this is the ID of a private endpoint and not something else

Copy link
Collaborator Author

@WodansSon WodansSon Jun 18, 2020

Choose a reason for hiding this comment

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

Mostly Fixed. I can't use ValidateNoEmptySegments because I am parsing the information for multiple resources from one resource ID(e.g. /subscriptions/XXXX/resourceGroups/jcline-privateDns-rg/providers/Microsoft.Network/privateEndpoints/contoso-cosmosdb/privateDnsZoneGroups/privatelink.postgres.database.azure.com2/privateDnsZoneConfigs/finance-contoso-com.


return privateDnsZoneGroup, nil
}

func PrivateDnsZoneResourceIDs(input []interface{}) ([]NameResourceGroup, error) {
Copy link
Member

Choose a reason for hiding this comment

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

(same here)

results := make([]NameResourceGroup, 0)

for _, item := range input {
v := item.(string)

id, err := azure.ParseAzureResourceID(v)
if err != nil {
return nil, fmt.Errorf("unable to parse Private DNS Zone ID %q: %+v", input, err)
}

privateDnsZone := NameResourceGroup{
Name: id.Path["privateDnsZones"],
Copy link
Member

Choose a reason for hiding this comment

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

can we pull this out into a separate ParseDNSZoneResourceID method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

ResourceGroup: id.ResourceGroup,
ID: v,
}
Copy link
Member

Choose a reason for hiding this comment

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

(same here)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.


results = append(results, privateDnsZone)
}

return results, nil
}

func PrivateEndpointResourceID(input string) (NameResourceGroup, error) {
Copy link
Member

Choose a reason for hiding this comment

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

(same here)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

id, err := azure.ParseAzureResourceID(input)
if err != nil {
return NameResourceGroup{}, fmt.Errorf("unable to parse Private Endpoint ID %q: %+v", input, err)
}

privateEndpoint := NameResourceGroup{
Name: id.Path["privateEndpoints"],
ResourceGroup: id.ResourceGroup,
ID: input,
}

return privateEndpoint, nil
}