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 - fix API error when given an empty origin_host_header #11852

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions azurerm/internal/services/cdn/cdn_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func resourceCdnEndpointCreate(d *schema.ResourceData, meta interface{}) error {
httpAllowed := d.Get("is_http_allowed").(bool)
httpsAllowed := d.Get("is_https_allowed").(bool)
cachingBehaviour := d.Get("querystring_caching_behaviour").(string)
originHostHeader := d.Get("origin_host_header").(string)
originPath := d.Get("origin_path").(string)
probePath := d.Get("probe_path").(string)
optimizationType := d.Get("optimization_type").(string)
Expand All @@ -250,11 +249,14 @@ func resourceCdnEndpointCreate(d *schema.ResourceData, meta interface{}) error {
IsHTTPAllowed: &httpAllowed,
IsHTTPSAllowed: &httpsAllowed,
QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(cachingBehaviour),
OriginHostHeader: utils.String(originHostHeader),
},
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("origin_host_header"); ok {
endpoint.EndpointProperties.OriginHostHeader = utils.String(v.(string))
}

if _, ok := d.GetOk("content_types_to_compress"); ok {
contentTypes := expandArmCdnEndpointContentTypesToCompress(d)
endpoint.EndpointProperties.ContentTypesToCompress = &contentTypes
Expand Down Expand Up @@ -343,7 +345,6 @@ func resourceCdnEndpointUpdate(d *schema.ResourceData, meta interface{}) error {
httpAllowed := d.Get("is_http_allowed").(bool)
httpsAllowed := d.Get("is_https_allowed").(bool)
cachingBehaviour := d.Get("querystring_caching_behaviour").(string)
hostHeader := d.Get("origin_host_header").(string)
originPath := d.Get("origin_path").(string)
probePath := d.Get("probe_path").(string)
optimizationType := d.Get("optimization_type").(string)
Expand All @@ -354,11 +355,14 @@ func resourceCdnEndpointUpdate(d *schema.ResourceData, meta interface{}) error {
IsHTTPAllowed: utils.Bool(httpAllowed),
IsHTTPSAllowed: utils.Bool(httpsAllowed),
QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(cachingBehaviour),
OriginHostHeader: utils.String(hostHeader),
},
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("origin_host_header"); ok {
endpoint.EndpointPropertiesUpdateParameters.OriginHostHeader = utils.String(v.(string))
}

if _, ok := d.GetOk("content_types_to_compress"); ok {
contentTypes := expandArmCdnEndpointContentTypesToCompress(d)
endpoint.EndpointPropertiesUpdateParameters.ContentTypesToCompress = &contentTypes
Expand Down
7 changes: 0 additions & 7 deletions azurerm/internal/services/cdn/cdn_endpoint_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ func TestAccCdnEndpoint_updateHostHeader(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.hostHeader(data, ""),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.hostHeader(data, "www.example2.com"),
Check: resource.ComposeTestCheckFunc(
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cdn_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The following arguments are supported:

* `origin` - (Required) The set of origins of the CDN endpoint. When multiple origins exist, the first origin will be used as primary and rest will be used as failover options. Each `origin` block supports fields documented below.

* `origin_host_header` - (Optional) The host header CDN provider will send along with content requests to origins. Defaults to the host name of the origin.
* `origin_host_header` - (Optional) The host header CDN provider will send along with content requests to origins.

* `origin_path` - (Optional) The path used at for origin requests.

Expand Down