-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Dependency:] azurerm_cdn_frontdoor_*
- update dependencies to use 2024-02-01
API
#28233
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @WodansSon - I wasn't sure if this was intended to cover all the resources migrating onto the go-azure-sdk
, so I've assumed a partial scope for the review given the number of resources and complexity of change.
Looking good so far, I've called out a few pattern changes we've adopted as part of the migrations, particularly around Read
functions because of the behaviour of the new SDKs. If you can take a look at the changes/comments below I'll loop back asap, also feel free to ping me offline if there are any questions.
Thanks!
if model.Sku == nil { | ||
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", id) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a behavioural change? lines 86-87 below just set this if it's not nil
, rather than returning an error, we should probably keep this the same? something like:
if model.Sku == nil { | |
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", id) | |
} | |
if sku := model.Sku; sku != nil { | |
d.Set("sku_name", pointer.From(sku.Name)) | |
} |
(maybe in the appropriate place below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if err != nil { | ||
return err | ||
} | ||
|
||
existing, err := client.Get(ctx, id.ResourceGroup, id.FrontDoorWebApplicationFirewallPolicyName) | ||
result, err := client.PoliciesGet(ctx, pointer.From(id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this isn't technically wrong, the ID Parse functions are nil-safe when error checked, so we're safe to use the dereference here and it's the standard pattern
result, err := client.PoliciesGet(ctx, pointer.From(id)) | |
result, err := client.PoliciesGet(ctx, *id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if model.Sku == nil { | ||
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", *id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth moving this check inside the d.HasChange("managed_rule")
block below, it appears that's the only place it's used from the code here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if model.Sku == nil { | ||
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", *id) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, this looks like a behavioural change, so again I think we should maintain the previous behaviour by removing this and allowing the conditional set below to run?
if model.Sku == nil { | |
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", *id) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if sku := model.Sku; sku != nil { | ||
skuName = string(pointer.From(sku.Name)) | ||
} | ||
d.Set("sku_name", skuName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified to
if sku := model.Sku; sku != nil { | |
skuName = string(pointer.From(sku.Name)) | |
} | |
d.Set("sku_name", skuName) | |
if sku := model.Sku; sku != nil { | |
d.Set("sku_name", string(pointer.From(sku.Name)) | |
} |
(and remove the skuName
declaration above, GH won't let me "suggest" it here 🙄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if profileModel.Sku.Name == nil { | ||
return fmt.Errorf("profileModel.Sku.Name is 'nil'") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this since we're checking the value of this safely below in for the isStandardSku
bool below?
if profileModel.Sku.Name == nil { | |
return fmt.Errorf("profileModel.Sku.Name is 'nil'") | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to return the error here, but I do believe we should still check for nil
, however I will just update the code to be like below to error on the side of caution if we cannot get the value for the sku:
isStandardSku := true
if profileModel.Sku.Name != nil {
isStandardSku = strings.HasPrefix(strings.ToLower(string(pointer.From(profileModel.Sku.Name))), "standard")
}
I will also remove the check for the profile properties as they are not used in this function.
if model == nil { | ||
return fmt.Errorf("model is 'nil'") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too, for the if model := resp.Model; model != nil { d.Set() }
pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
if id := v["cdn_frontdoor_domain_id"].(string); id != "" { | ||
results = append(results, securitypolicies.ActivatedResourceReference{ | ||
Id: utils.String(id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Id: utils.String(id), | |
Id: pointer.To(id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
active := false | ||
if item.IsActive != nil { | ||
active = *item.IsActive | ||
} | ||
|
||
results = append(results, map[string]interface{}{ | ||
"active": active, | ||
"cdn_frontdoor_domain_id": frontDoorDomainId, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify this to
active := false | |
if item.IsActive != nil { | |
active = *item.IsActive | |
} | |
results = append(results, map[string]interface{}{ | |
"active": active, | |
"cdn_frontdoor_domain_id": frontDoorDomainId, | |
}) | |
results = append(results, map[string]interface{}{ | |
"active": pointer.From(item.IsActive), | |
"cdn_frontdoor_domain_id": frontDoorDomainId, | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// NOTE: These const were taken from the 2021-06-01 API to remove the dependency on the legacy API. | ||
// SslProtocol enumerates the values for ssl protocol. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like an oversight from this API, is it worth referring this to the service team to get these added in to this version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they did include it in the new API, but I will need to import a different package to access it. In the old API everything was in the CDN package and now they have split them out. Let me see if I can find those values in the new API.
Additional:
I did find it, the type is now defined in the 2024-09-01/rules package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @WodansSon for those changes. I spotted a handful of others this pass, but I think once they're covered we're good to go (maybe check the other Reads
for the if model := resp.Model; model != nil {}
In case I still missed any in my haste? 🙈 )
future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.FrontDoorWebApplicationFirewallPolicyName, existing) | ||
model.Properties = pointer.To(props) | ||
|
||
err = client.PoliciesCreateOrUpdateThenPoll(ctx, pointer.From(id), pointer.From(model)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are nil
safe at this point, so we should probably just use them directly as we do elsewhere in the provider.
err = client.PoliciesCreateOrUpdateThenPoll(ctx, pointer.From(id), pointer.From(model)) | |
err = client.PoliciesCreateOrUpdateThenPoll(ctx, *id, *model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if err != nil { | ||
return err | ||
} | ||
|
||
resp, err := client.Get(ctx, id.ResourceGroup, id.FrontDoorWebApplicationFirewallPolicyName) | ||
result, err := client.PoliciesGet(ctx, pointer.From(id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, nil
safe, so we usually use directly:
result, err := client.PoliciesGet(ctx, pointer.From(id)) | |
result, err := client.PoliciesGet(ctx, *id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
internal/services/cdn/cdn_frontdoor_firewall_policy_data_source.go
Outdated
Show resolved
Hide resolved
model := result.Model | ||
|
||
if model == nil { | ||
return fmt.Errorf("retrieving %s: 'model' was nil", *id) | ||
} | ||
|
||
if model.Properties == nil { | ||
return fmt.Errorf("retrieving %s: 'model.Properties' was nil", *id) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think I missed this on the last pass? Can we use the if model := result.Model; model != nil {}
pattern here for the read? The d.Set()
items from the ID can be performed outside this, ofc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if response.WasNotFound(profileResp.HttpResponse) { | ||
d.SetId("") | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unusual behaviour for an Update
, if it's not found, Read
on this resource (probably the parent actually) should have caught it and removed it from state? Is this a copy-paste error perhaps?
if response.WasNotFound(profileResp.HttpResponse) { | |
d.SetId("") | |
return nil | |
if response.WasNotFound(profileResp.HttpResponse) { | |
return fmt.Errorf("retrieving parent %s: not found", profileId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May have been a CaP issue... Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @WodansSon - This LGTM now 👍
and the tests look good too:
Community Note
Description
This is the first step in implementing the new
identity
field andjschallenge
field for CDN Front Door:Data Source:
azurerm_cdn_frontdoor_firewall_policy
- update dependencies to use2024-02-01
APIData Source:
azurerm_cdn_frontdoor_profile
- update dependencies to use2024-02-01
APIclient
- update dependencies to use2024-02-01/profiles
,2024-02-01/securitypolicies
and2024-02-01/webapplicationfirewallpolicies
APIazurerm_cdn_frontdoor_custom_domain
- update dependencies to use2024-02-01/profiles
azurerm_cdn_frontdoor_custom_domain
- added a deprecated message fortls.minimum_tls_version
propertyazurerm_cdn_frontdoor_firewall_policy
- update dependencies to use2024-02-01
APIazurerm_cdn_frontdoor_origin
- update dependencies to use2024-02-01/profiles
APIazurerm_cdn_frontdoor_profile
- update dependencies to use2024-02-01
APIazurerm_cdn_frontdoor_security_policy
- update dependencies to use2024-02-01
,2024-02-01/profiles
and2024-02-01/webapplicationfirewallpolicies
APIcdn_frontdoor_shared_schema
- update dependencies to use2024-02-01/webapplicationfirewallpolicies
and2024-09-01/rules
APINote: The API upgrades have been scoped specifically to target the resources to implement the new
identity
andmschallenge
fields.PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
Data Source:
azurerm_cdn_frontdoor_firewall_policy
- update dependencies to use2024-02-01
APIData Source:
azurerm_cdn_frontdoor_profile
- update dependencies to use2024-02-01
API./internal/services/cdn/client
- update dependencies to use2024-02-01/profiles
API./internal/services/cdn/client
- update dependencies to use2024-02-01/securitypolicies
API./internal/services/cdn/client
- update dependencies to use2024-02-01/webapplicationfirewallpolicies
APIazurerm_cdn_frontdoor_custom_domain
- update dependencies to use2024-02-01/profiles
azurerm_cdn_frontdoor_custom_domain
- added a deprecated message fortls.minimum_tls_version
propertyazurerm_cdn_frontdoor_firewall_policy
- update dependencies to use2024-02-01
APIazurerm_cdn_frontdoor_origin
- update dependencies to use2024-02-01/profiles
APIazurerm_cdn_frontdoor_profile
- update dependencies to use2024-02-01
APIazurerm_cdn_frontdoor_security_policy
- update dependencies to use2024-02-01
APIazurerm_cdn_frontdoor_security_policy
- update dependencies2024-02-01/webapplicationfirewallpolicies
APIazurerm_cdn_frontdoor_security_policy
- update dependencies to use2024-02-01/profiles
APIcdn_frontdoor_shared_schema
- update dependencies to use2024-02-01/webapplicationfirewallpolicies
APIcdn_frontdoor_shared_schema
- update dependencies to use2024-09-01/rules
APIThis is a (please select all that apply):
Note
If this PR changes meaningfully during the course of review please update the title and description as required.