Skip to content

Commit

Permalink
fixes #8208
Browse files Browse the repository at this point in the history
* frontdoor: updating the ID parsers to enable generation

* frontdoor: adding subscriptionId as an argument to match the upcoming generated code

* frontdoor: updating to match the updated method signature

* frontdoor: removing the direct dependency on subscriptionId

This enables this to be threaded through directly from the FrontDoor ID

* frontdoor: removing the direct dependency on subscriptionId

* frontdoor: refactoring/renaming the existing BackendPoolID method to match the upcoming generated name

* frontdoor: updating to match the upcoming generated names

* frontdoor: updating to match the generated name for the strict method

* frontdoor: updating to match the generated name

* frontdoor_frontend_endpoint: updating to use the generated method name for the strict method

* frontdoor/health_probe: updating to match the generated name

* frontdoor/load_balancing: updating to match the generated name

* frontdoor: renaming routing rule to match the generated name

* r/frontdoor: fixing the build

* frontdoor: renaming to match the generated name

* frontdoor: generating the Resource ID Formatter/Parser/Validator for BackendPool

* frontdoor: renaming to match the generated filenames

* frontdoor: generating the Resource ID Formatter/Parser/Validator

* frontdoor: generating the Resource ID Formatter/Parser/Validator for Frontend Endpoint

* frontdoor: generating the Resource ID Formatters/Parsers and Validators for HealthProbe

* frontdoor: generating the Resource ID Formatter/Parser/Validator for Load Balancing

* frontdoor: generating the Resource ID Formatter/Parser and Validator for Routing Rule

* frontdoor: generating the Resource ID Formatter/Parser/Validator for Web Application Firewall Policy

* frontdoor: fixing the build to match the generated code
  • Loading branch information
tombuildsstuff authored Dec 8, 2020
1 parent aaa2bfb commit 07ece4b
Show file tree
Hide file tree
Showing 44 changed files with 3,070 additions and 736 deletions.
2 changes: 1 addition & 1 deletion azurerm/internal/services/frontdoor/customizediff.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func customizeHttpsConfigurationCustomizeDiff(d *schema.ResourceDiff, v interface{}) error {
if v, ok := d.GetOk("frontend_endpoint_id"); ok && v.(string) != "" {
id, err := parse.FrontendEndpointIDForImport(v.(string))
id, err := parse.FrontendEndpointID(v.(string))
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func resourceFrontDoorCustomHttpsConfiguration() *schema.Resource {
Delete: resourceFrontDoorCustomHttpsConfigurationDelete,

Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error {
_, err := parse.FrontendEndpointIDForImport(id)
_, err := parse.FrontendEndpointID(id)
return err
}),

Expand Down Expand Up @@ -79,11 +79,10 @@ func resourceFrontDoorCustomHttpsConfiguration() *schema.Resource {

func resourceFrontDoorCustomHttpsConfigurationCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Frontdoor.FrontDoorsFrontendClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.FrontendEndpointID(d.Get("frontend_endpoint_id").(string))
id, err := parse.FrontendEndpointIDInsensitively(d.Get("frontend_endpoint_id").(string))
if err != nil {
return err
}
Expand All @@ -106,26 +105,24 @@ func resourceFrontDoorCustomHttpsConfigurationCreateUpdate(d *schema.ResourceDat
customHttpsProvisioningEnabled: d.Get("custom_https_provisioning_enabled").(bool),
frontendEndpointId: *id,
provisioningState: props.CustomHTTPSProvisioningState,
subscriptionId: subscriptionId,
}
if err := updateCustomHttpsConfiguration(ctx, client, input); err != nil {
return fmt.Errorf("updating Custom HTTPS configuration for Frontend Endpoint %q (Front Door %q / Resource Group %q): %+v", id.Name, id.FrontDoorName, id.ResourceGroup, err)
}

if d.IsNewResource() {
d.SetId(id.ID(subscriptionId))
d.SetId(id.ID(""))
}

return resourceFrontDoorCustomHttpsConfigurationRead(d, meta)
}

func resourceFrontDoorCustomHttpsConfigurationRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Frontdoor.FrontDoorsFrontendClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.FrontendEndpointID(d.Id())
id, err := parse.FrontendEndpointIDInsensitively(d.Id())
if err != nil {
return err
}
Expand All @@ -141,7 +138,7 @@ func resourceFrontDoorCustomHttpsConfigurationRead(d *schema.ResourceData, meta
return fmt.Errorf("reading Front Door Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

d.Set("frontend_endpoint_id", id.ID(subscriptionId))
d.Set("frontend_endpoint_id", id.ID(""))
d.Set("resource_group_name", id.ResourceGroup)

flattenedHttpsConfig := flattenCustomHttpsConfiguration(resp.FrontendEndpointProperties)
Expand All @@ -157,11 +154,10 @@ func resourceFrontDoorCustomHttpsConfigurationRead(d *schema.ResourceData, meta

func resourceFrontDoorCustomHttpsConfigurationDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Frontdoor.FrontDoorsFrontendClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.FrontendEndpointID(d.Id())
id, err := parse.FrontendEndpointIDInsensitively(d.Id())
if err != nil {
return err
}
Expand All @@ -185,7 +181,6 @@ func resourceFrontDoorCustomHttpsConfigurationDelete(d *schema.ResourceData, met
customHttpsProvisioningEnabled: false,
frontendEndpointId: *id,
provisioningState: props.CustomHTTPSProvisioningState,
subscriptionId: subscriptionId,
}
if err := updateCustomHttpsConfiguration(ctx, client, input); err != nil {
return fmt.Errorf("disabling Custom HTTPS configuration for Frontend Endpoint %q (Front Door %q / Resource Group %q): %+v", id.Name, id.FrontDoorName, id.ResourceGroup, err)
Expand All @@ -200,12 +195,11 @@ type customHttpsConfigurationUpdateInput struct {
customHttpsProvisioningEnabled bool
frontendEndpointId parse.FrontendEndpointId
provisioningState frontdoor.CustomHTTPSProvisioningState
subscriptionId string
}

func updateCustomHttpsConfiguration(ctx context.Context, client *frontdoor.FrontendEndpointsClient, input customHttpsConfigurationUpdateInput) error {
// Locking to prevent parallel changes causing issues
frontendEndpointResourceId := input.frontendEndpointId.ID(input.subscriptionId)
frontendEndpointResourceId := input.frontendEndpointId.ID("")
locks.ByID(frontendEndpointResourceId)
defer locks.UnlockByID(frontendEndpointResourceId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAccFrontDoorCustomHttpsConfiguration_CustomHttps(t *testing.T) {
}

func (FrontDoorCustomHttpsConfigurationResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.FrontendEndpointID(state.ID)
id, err := parse.FrontendEndpointIDInsensitively(state.ID)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func resourceFrontDoorFirewallPolicy() *schema.Resource {
Delete: resourceFrontDoorFirewallPolicyDelete,

Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error {
_, err := parse.WebApplicationFirewallPolicyID(id)
_, err := parse.WebApplicationFirewallPolicyIDInsensitively(id)
return err
}),

Expand Down Expand Up @@ -443,7 +443,7 @@ func resourceFrontDoorFirewallPolicyCreateUpdate(d *schema.ResourceData, meta in

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
id := parse.NewWebApplicationFirewallPolicyID(resourceGroup, name).ID(subscriptionId)
id := parse.NewWebApplicationFirewallPolicyID(subscriptionId, resourceGroup, name).ID("")

if d.IsNewResource() {
existing, err := client.Get(ctx, resourceGroup, name)
Expand Down Expand Up @@ -512,22 +512,22 @@ func resourceFrontDoorFirewallPolicyRead(d *schema.ResourceData, meta interface{
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.WebApplicationFirewallPolicyID(d.Id())
id, err := parse.WebApplicationFirewallPolicyIDInsensitively(d.Id())
if err != nil {
return err
}

resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
resp, err := client.Get(ctx, id.ResourceGroup, id.FrontDoorWebApplicationFirewallPolicyName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[INFO] Front Door Firewall Policy %q does not exist - removing from state", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("retrieving Front Door Firewall Policy %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("retrieving Front Door Firewall Policy %q (Resource Group %q): %+v", id.FrontDoorWebApplicationFirewallPolicyName, id.ResourceGroup, err)
}

d.Set("name", id.Name)
d.Set("name", id.FrontDoorWebApplicationFirewallPolicyName)
d.Set("resource_group_name", id.ResourceGroup)

if location := resp.Location; location != nil {
Expand Down Expand Up @@ -564,22 +564,22 @@ func resourceFrontDoorFirewallPolicyDelete(d *schema.ResourceData, meta interfac
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.WebApplicationFirewallPolicyID(d.Id())
id, err := parse.WebApplicationFirewallPolicyIDInsensitively(d.Id())
if err != nil {
return err
}

future, err := client.Delete(ctx, id.ResourceGroup, id.Name)
future, err := client.Delete(ctx, id.ResourceGroup, id.FrontDoorWebApplicationFirewallPolicyName)
if err != nil {
if response.WasNotFound(future.Response()) {
return nil
}
return fmt.Errorf("deleting Front Door Firewall %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("deleting Front Door Firewall %q (Resource Group %q): %+v", id.FrontDoorWebApplicationFirewallPolicyName, id.ResourceGroup, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
if !response.WasNotFound(future.Response()) {
return fmt.Errorf("waiting for deleting Front Door Firewall %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("waiting for deleting Front Door Firewall %q (Resource Group %q): %+v", id.FrontDoorWebApplicationFirewallPolicyName, id.ResourceGroup, err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ func TestAccFrontDoorFirewallPolicy_complete(t *testing.T) {
}

func (FrontDoorFirewallPolicyResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.WebApplicationFirewallPolicyID(state.ID)
id, err := parse.WebApplicationFirewallPolicyIDInsensitively(state.ID)
if err != nil {
return nil, err
}

resp, err := clients.Frontdoor.FrontDoorsPolicyClient.Get(ctx, id.ResourceGroup, id.Name)
resp, err := clients.Frontdoor.FrontDoorsPolicyClient.Get(ctx, id.ResourceGroup, id.FrontDoorWebApplicationFirewallPolicyName)
if err != nil {
return nil, fmt.Errorf("retrieving Front Door Firewall Policy %q (Resource Group %q): %v", id.Name, id.ResourceGroup, err)
return nil, fmt.Errorf("retrieving Front Door Firewall Policy %q (Resource Group %q): %v", id.FrontDoorWebApplicationFirewallPolicyName, id.ResourceGroup, err)
}

return utils.Bool(resp.WebApplicationFirewallPolicyProperties != nil), nil
Expand Down
Loading

0 comments on commit 07ece4b

Please sign in to comment.