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

frontdoor: updating to use a generated Resource ID Formatter/Parser/Validator #9750

Merged
merged 24 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
77c334a
frontdoor: updating the ID parsers to enable generation
tombuildsstuff Dec 7, 2020
fa5a536
frontdoor: adding subscriptionId as an argument to match the upcoming…
tombuildsstuff Dec 7, 2020
9133376
frontdoor: updating to match the updated method signature
tombuildsstuff Dec 7, 2020
0359fd5
frontdoor: removing the direct dependency on subscriptionId
tombuildsstuff Dec 7, 2020
246388a
frontdoor: removing the direct dependency on subscriptionId
tombuildsstuff Dec 7, 2020
3834494
frontdoor: refactoring/renaming the existing BackendPoolID method to …
tombuildsstuff Dec 7, 2020
a27cb0d
frontdoor: updating to match the upcoming generated names
tombuildsstuff Dec 7, 2020
43eaf29
frontdoor: updating to match the generated name for the strict method
tombuildsstuff Dec 7, 2020
d809c2c
frontdoor: updating to match the generated name
tombuildsstuff Dec 7, 2020
0b8c797
frontdoor_frontend_endpoint: updating to use the generated method nam…
tombuildsstuff Dec 7, 2020
0abf5e4
frontdoor/health_probe: updating to match the generated name
tombuildsstuff Dec 7, 2020
a85b503
frontdoor/load_balancing: updating to match the generated name
tombuildsstuff Dec 7, 2020
87d0310
frontdoor: renaming routing rule to match the generated name
tombuildsstuff Dec 7, 2020
f811f6f
r/frontdoor: fixing the build
tombuildsstuff Dec 7, 2020
2dcfd36
frontdoor: renaming to match the generated name
tombuildsstuff Dec 7, 2020
e49bede
frontdoor: generating the Resource ID Formatter/Parser/Validator for …
tombuildsstuff Dec 7, 2020
6fc0e42
frontdoor: renaming to match the generated filenames
tombuildsstuff Dec 7, 2020
a8ef402
frontdoor: generating the Resource ID Formatter/Parser/Validator
tombuildsstuff Dec 7, 2020
6e83a5e
frontdoor: generating the Resource ID Formatter/Parser/Validator for …
tombuildsstuff Dec 7, 2020
7014891
frontdoor: generating the Resource ID Formatters/Parsers and Validato…
tombuildsstuff Dec 7, 2020
9ac09fe
frontdoor: generating the Resource ID Formatter/Parser/Validator for …
tombuildsstuff Dec 7, 2020
b77eab5
frontdoor: generating the Resource ID Formatter/Parser and Validator …
tombuildsstuff Dec 7, 2020
eb68c9f
frontdoor: generating the Resource ID Formatter/Parser/Validator for …
tombuildsstuff Dec 7, 2020
cc4082d
frontdoor: fixing the build to match the generated code
tombuildsstuff Dec 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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