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 all 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,
}
}
117 changes: 117 additions & 0 deletions azurerm/internal/services/network/parse/private_endpoint.go
@@ -0,0 +1,117 @@
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) (*NameResourceGroup, error) {
if len(strings.TrimSpace(input)) == 0 {
return nil, fmt.Errorf("unable to parse Private DNS Zone Group ID %q: input is empty", input)
}

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

privateDnsZoneGroup := NameResourceGroup{
ResourceGroup: id.ResourceGroup,
}
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.


if privateDnsZoneGroup.Name, err = id.PopSegment("privateDnsZoneGroups"); err != nil {
return nil, err
}

if privateDnsZoneGroup.ID = input; err != nil {
return nil, err
}

return &privateDnsZoneGroup, nil
}

func PrivateDnsZoneResourceIDs(input []interface{}) (*[]NameResourceGroup, error) {
results := make([]NameResourceGroup, 0)

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

if privateDnsZone, err := PrivateDnsZoneResourceID(v); err != nil {
return nil, fmt.Errorf("unable to parse Private DNS Zone ID %q: %+v", v, err)
} else {
results = append(results, *privateDnsZone)
}
}

return &results, nil
}

func PrivateDnsZoneResourceID(input string) (*NameResourceGroup, error) {
if len(strings.TrimSpace(input)) == 0 {
return nil, fmt.Errorf("unable to parse Private DNS Zone ID %q: input is empty", input)
}

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

privateDnsZone := NameResourceGroup{
ResourceGroup: id.ResourceGroup,
}

if privateDnsZone.Name, err = id.PopSegment("privateDnsZones"); err != nil {
return nil, err
}

if privateDnsZone.ID = input; err != nil {
return nil, err
}

return &privateDnsZone, nil
}

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

privateEndpoint := NameResourceGroup{
ResourceGroup: id.ResourceGroup,
}

if privateEndpoint.Name, err = id.PopSegment("privateEndpoints"); err != nil {
return nil, err
}

if privateEndpoint.ID = input; err != nil {
return nil, err
}

return &privateEndpoint, nil
}

func ValidatePrivateDnsZoneResourceID(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return
}

if id, err := azure.ParseAzureResourceID(v); err != nil {
errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err))
} else if _, err = id.PopSegment("privateDnsZones"); err != nil {
errors = append(errors, fmt.Errorf("Can not parse %q as a private dns zone resource id: %v", k, err))
}

return warnings, errors
}