Skip to content

Commit

Permalink
fixes #6571
Browse files Browse the repository at this point in the history
* Fixed requiresImport test case

* Progress exposing dns zone groups

* Work thus far redesign

* Progress thus far

* Progress

* Change data structure

* Close mostly working now

* Remove old resources

* Code complete needs docs and tests

* Add docs and example

* Added Tests and updated docs

* Fix Lint Errors

* Update azurerm/internal/services/network/parse/private_endpoint.go

Co-authored-by: Tom Harvey <tombuildsstuff@users.noreply.github.com>

* Update azurerm/internal/services/network/private_endpoint_resource.go

Co-authored-by: Tom Harvey <tombuildsstuff@users.noreply.github.com>

* Update azurerm/internal/services/network/private_endpoint_resource.go

Co-authored-by: Tom Harvey <tombuildsstuff@users.noreply.github.com>

* Changes per PR

* Fix lint error

* Requested changes per PR comment

Co-authored-by: Tom Harvey <tombuildsstuff@users.noreply.github.com>
  • Loading branch information
WodansSon and tombuildsstuff committed Jun 18, 2020
1 parent 1a7f16d commit ce3eb26
Show file tree
Hide file tree
Showing 11 changed files with 1,131 additions and 18 deletions.
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,
}

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
}

0 comments on commit ce3eb26

Please sign in to comment.