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_cdn_endpoint_custom_domain - add supports for HTTPS #13283

Merged
merged 31 commits into from
Jan 6, 2022

Conversation

magodo
Copy link
Collaborator

@magodo magodo commented Sep 9, 2021

For the https case, there are two cases - CDN managed and user managed. For both cases, the https setting doesn't allow in-place update. That is because when updateing an https setting by disabling and enabling. The enabling request after the endpoint turns into disabled state will result into following error:

Custom HTTPS cannot be enabled at the moment because it takes 8 hours to
clean up your previous enablement request for the same custom domain.
Please try again later.

So we only allow toggling update, i.e. enable or disable.

Besides, both CDN managed and user managed test case might take a very long time. Only a disable/enable operation will take up to 8 hours to finish (hence I set the timeout accordingly). Though some configuration runs fast (e.g. for the user managed test case with the Standard_Microsoft sku, it only requires ~5 min to enable https).

Addtionally, for the user managed case, two more environment variables ARM_TEST_DNS_CERTIFICATE and ARM_TEST_DNS_SUBDOMAIN_NAME are needed, which contains the CA signed certificate for that domain and the corresponding subdomain name (i.e. the subdomain in the subject CN).

This should fix #398.

Test Result

💤 export ARM_TEST_DNS_ZONE_RESOURCE_GROUP_NAME=zhwen-domain \
export ARM_TEST_DNS_ZONE_NAME=e-moran.com \
export ARM_TEST_DNS_CERTIFICATE=/home/magodo/github/tf-config/acme/cert.pfx \
export ARM_TEST_DNS_SUBDOMAIN_NAME=sub

💤 💢 TF_ACC=1 go test -v -timeout=20h ./internal/services/cdn -run="TestAccCdnEndpointCustomDomain_httpsUserManagedBasic"
=== RUN   TestAccCdnEndpointCustomDomain_httpsUserManagedBasic
=== PAUSE TestAccCdnEndpointCustomDomain_httpsUserManagedBasic
=== CONT  TestAccCdnEndpointCustomDomain_httpsUserManagedBasic
--- PASS: TestAccCdnEndpointCustomDomain_httpsUserManagedBasic (794.12s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn   794.148s

katbyte
katbyte previously requested changes Sep 9, 2021
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we have a build failure:

./cdn_endpoint_custom_domain_resource.go:249:11: props.CustomHTTPSParameters undefined (type *cdn.CustomDomainProperties has no field or method CustomHTTPSParameters)
[18:11:47]	[Step 4/5] ./cdn_endpoint_custom_domain_resource.go:275:11: props.CustomHTTPSParameters undefined (type *cdn.CustomDomainProperties has no field or method CustomHTTPSParameters)
[18:11:47]	[Step 4/5] ./cdn_endpoint_custom_domain_resource.go:321:25: props.CustomHTTPSParameters undefined (type *cdn.CustomDomainProperties has no field or method CustomHTTPSParameters)
[18:11:47]	[Step 4/5] ./cdn_endpoint_custom_domain_resource.go:370:3: cannot use cdn.None (type cdn.ResponseBasedDetectedErrorTypes) as type cdn.MinimumTLSVersion in field value
[18:11:47]	[Step 4/5] ./cdn_endpoint_custom_domain_resource.go:401:3: cannot use cdn.None (type cdn.ResponseBasedDetectedErrorTypes) as type cdn.MinimumTLSVersion in field value
[18:11:47]	[Step 4/5] ./cdn_endpoint_custom_domain_resource.go:465:31: undefined: cdn.Enabling
[18:11:47]	[Step 4/5] ./cdn_endpoint_custom_domain_resource.go:495:31: undefined: cdn.Disabling

@magodo
Copy link
Collaborator Author

magodo commented Sep 10, 2021

@katbyte It is because of #13282, which updates the api version of CDN from 2019-04-15 to 2021-09-01.

In the Azure/azure-rest-api-specs, there is a commit: Add missing customHttpsParameters field of CustomDomainProperties. The issue here is that in the currently used Go SDK, the model generated for 2019-04-15 has the HTTPS parameters when getting the custom domain, while the model generated for 2021-09-01 doesn't.

@katbyte katbyte modified the milestones: v2.77.0, Blocked Sep 16, 2021
@magodo
Copy link
Collaborator Author

magodo commented Oct 15, 2021

The SDK issue is tracked by Azure/azure-sdk-for-go#15528

@magodo
Copy link
Collaborator Author

magodo commented Nov 3, 2021

@katbyte The build issue is now fixed, please kindly take another look!

@alex-bes
Copy link

alex-bes commented Nov 5, 2021

Hi guys! thanks for your efforts on this! @katbyte, is there a chance this will be merged/released soon?

@wilsonnm02
Copy link

@katbyte Any eta on merge/release for this PR?

@opslivia opslivia modified the milestones: Blocked, v2.87.0 Nov 17, 2021
@magodo magodo requested a review from katbyte November 22, 2021 02:08
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @magodo

Thanks for pushing those changes - I've taken a look through and left some other comments in addition to @jackofallops comments, if we can fix those up then this should otherwise be good to go 👍

Thanks!

Comment on lines +184 to +187
// User managed certificate is only available for Azure CDN from Microsoft and Azure CDN from Verizon profiles.
// https://docs.microsoft.com/en-us/azure/cdn/cdn-custom-ssl?tabs=option-2-enable-https-with-your-own-certificate#tlsssl-certificates
pfClient := meta.(*clients.Client).Cdn.ProfilesClient
cdnEndpointResp, err := pfClient.Get(ctx, id.ResourceGroup, id.ProfileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of outside the scope of this PR, but I've been wondering for a long-time if we should split the CDN endpoints by type, since the Verizon one only supports half of the features (the rest need to be managed in a separate portal) - I have a feeling we're nearing the point where we should make a call on that

},
CustomizeDiff: func(ctx context.Context, diff *pluginsdk.ResourceDiff, _ interface{}) error {
if settings, ok := diff.GetOk("cdn_managed_https"); ok {
settings := settings.([]interface{})[0].(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this'll crash if it's an array containing a computed item? so we'll need to length-check this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIK, in case the properties inside the block are not all optional (i.e. at least one required), then if the returned value from GetOk is not the default value, then it is guaranteed to contain at least one element.

Anyway, it is always safe to length check for this :)

@katbyte katbyte modified the milestones: v2.90.0, v2.91.0 Dec 17, 2021
@magodo
Copy link
Collaborator Author

magodo commented Dec 21, 2021

@tombuildsstuff I've resolved all the comments above and added a new testcase for the multi-step update. Please take another look, thanks!

💤  TF_ACC=1 go test -v -timeout=20h ./internal/services/cdn -run='TestAccCdnEndpointCustomDomain_httpsUpdate'
=== RUN   TestAccCdnEndpointCustomDomain_httpsUpdate
=== PAUSE TestAccCdnEndpointCustomDomain_httpsUpdate
=== CONT  TestAccCdnEndpointCustomDomain_httpsUpdate
--- PASS: TestAccCdnEndpointCustomDomain_httpsUpdate (3806.46s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn   3806.476s

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @magodo
I've run as much of the testing as I can in our test environment, and this looks good to go now.

image

@jackofallops jackofallops dismissed stale reviews from katbyte, stephybun, and tombuildsstuff January 6, 2022 16:57

addressed

@jackofallops jackofallops merged commit ff2a2f9 into hashicorp:main Jan 6, 2022
jackofallops added a commit that referenced this pull request Jan 6, 2022
@github-actions
Copy link

github-actions bot commented Jan 7, 2022

This functionality has been released in v2.91.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@wasfree
Copy link
Contributor

wasfree commented Jan 13, 2022

Maybe it should be mentioned this is a breaking change, if it was manually enabled and is not reflected in terraform configuration https settings will be disabled. Also if the certificate is managed by Azure you have to wait 8 hours to reneable it. @tombuildsstuff

@tombuildsstuff
Copy link
Contributor

@wasfree adding a new field to the Provider isn't a breaking change, this would have been highlighted in the Terraform Plan if it's configured outside of Terraform and not in the config - are you saying that this wasn't reflected in the Terraform Plan?

@wasfree
Copy link
Contributor

wasfree commented Jan 13, 2022

With breaking change I mean https configuration was not possible to be set with terraform for a long time. So looking into issues people worked around it with azure cli or manually enable https settings for cdn custom domains. So if that is the case after updating to version 2.91.0 will disable https settings completely, potentially this will cause some outage. But I also agree with you it's possible to see it in the plan that https settings changed to null (so whatever the default is).

@magodo
Copy link
Collaborator Author

magodo commented Jan 14, 2022

@wasfree Also noted that the Standard_Microsoft with following https configuration takes less than 1 hour to propagate.

    certificate_type = "Dedicated"
    protocol_type    = "ServerNameIndication"

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azurerm_cdn_endpoint support for custom domains
9 participants