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

[New Data Source:] azurerm_cdn_frontdoor_custom_domain #19357

Merged
merged 6 commits into from
Nov 19, 2022
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
141 changes: 141 additions & 0 deletions internal/services/cdn/cdn_frontdoor_custom_domain_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package cdn

import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func dataSourceCdnFrontDoorCustomDomain() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceCdnFrontDoorCustomDomainRead,

Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.FrontDoorCustomDomainName,
},

"profile_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.FrontDoorName,
},

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"cdn_frontdoor_profile_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"dns_zone_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"host_name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"tls": {
Type: pluginsdk.TypeList,
Computed: true,

Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{

"certificate_type": {
Type: pluginsdk.TypeString,
Computed: true,
},

"minimum_tls_version": {
Type: pluginsdk.TypeString,
Computed: true,
},

"cdn_frontdoor_secret_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},

"expiration_date": {
Type: pluginsdk.TypeString,
Computed: true,
},

"validation_token": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}

func dataSourceCdnFrontDoorCustomDomainRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Cdn.FrontDoorCustomDomainsClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewFrontDoorCustomDomainID(subscriptionId, d.Get("resource_group_name").(string), d.Get("profile_name").(string), d.Get("name").(string))
resp, err := client.Get(ctx, id.ResourceGroup, id.ProfileName, id.CustomDomainName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("retrieving %s: %+v", id, err)
}

d.SetId(id.ID())
d.Set("name", id.CustomDomainName)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("profile_name", id.ProfileName)
d.Set("cdn_frontdoor_profile_id", parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName).ID())

if props := resp.AFDDomainProperties; props != nil {
d.Set("host_name", props.HostName)

dnsZoneId, err := flattenDNSZoneResourceReference(props.AzureDNSZone)
if err != nil {
return fmt.Errorf("flattening `dns_zone_id`: %+v", err)
}

if err := d.Set("dns_zone_id", dnsZoneId); err != nil {
return fmt.Errorf("setting `dns_zone_id`: %+v", err)
}

tls, err := flattenCustomDomainAFDDomainHttpsParameters(props.TLSSettings)
if err != nil {
return fmt.Errorf("flattening `tls`: %+v", err)
}

if err := d.Set("tls", tls); err != nil {
return fmt.Errorf("setting `tls`: %+v", err)
}

if validationProps := props.ValidationProperties; validationProps != nil {
d.Set("expiration_date", validationProps.ExpirationDate)
d.Set("validation_token", validationProps.ValidationToken)
}
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cdn_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type CdnFrontDoorCustomDomainDataSource struct{}

func TestAccCdnFrontDoorCustomDomainDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_custom_domain", "test")
d := CdnFrontDoorCustomDomainDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("dns_zone_id").Exists(),
check.That(data.ResourceName).Key("host_name").Exists(),
check.That(data.ResourceName).Key("cdn_frontdoor_profile_id").Exists(),
check.That(data.ResourceName).Key("tls.0.cdn_frontdoor_secret_id").IsEmpty(),
check.That(data.ResourceName).Key("tls.0.certificate_type").Exists(),
check.That(data.ResourceName).Key("tls.0.minimum_tls_version").Exists(),
check.That(data.ResourceName).Key("expiration_date").Exists(),
check.That(data.ResourceName).Key("validation_token").Exists(),
),
},
})
}

func (CdnFrontDoorCustomDomainDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_cdn_frontdoor_custom_domain" "test" {
name = azurerm_cdn_frontdoor_custom_domain.test.name
profile_name = azurerm_cdn_frontdoor_profile.test.name
resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name
}
`, CdnFrontDoorCustomDomainResource{}.complete(data))
}
1 change: 1 addition & 0 deletions internal/services/cdn/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource {
"azurerm_cdn_profile": dataSourceCdnProfile(),

// FrontDoor
"azurerm_cdn_frontdoor_custom_domain": dataSourceCdnFrontDoorCustomDomain(),
"azurerm_cdn_frontdoor_endpoint": dataSourceCdnFrontDoorEndpoint(),
"azurerm_cdn_frontdoor_firewall_policy": dataSourceCdnFrontDoorFirewallPolicy(),
"azurerm_cdn_frontdoor_origin_group": dataSourceCdnFrontDoorOriginGroup(),
Expand Down
65 changes: 65 additions & 0 deletions website/docs/d/cdn_frontdoor_custom_domain.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
subcategory: "CDN"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_cdn_frontdoor_custom_domain"
description: |-
Gets information about an existing Front Door (standard/premium) Custom Domain.
---

# Data Source: azurerm_cdn_frontdoor_custom_domain

Use this data source to access information about an existing Front Door (standard/premium) Custom Domain.

## Example Usage

```hcl
data "azurerm_cdn_frontdoor_custom_domain" "example" {
name = azurerm_cdn_frontdoor_custom_domain.example.name
profile_name = azurerm_cdn_frontdoor_profile.example.name
resource_group_name = azurerm_cdn_frontdoor_profile.example.resource_group_name
}
```

## Arguments Reference

The following arguments are supported:

* `name` - (Required) The name of the Front Door Custom Domain.

* `profile_name` - (Required) The name of the Front Door Profile which the Front Door Custom Domain is bound to.

* `resource_group_name` - (Required) The name of the Resource Group where the Front Door Profile exists.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Front Door Custom Domain.

* `cdn_frontdoor_profile_id` - The ID of the Front Door Profile which the Front Door Custom Domain is bound to.

* `expiration_date` - The date time that the token expires.

* `host_name` - The host name of the domain.

* `tls` - A `tls` block as defined below.

* `validation_token` - The challenge used for DNS TXT record or file based validation.

---

A `tls` block exports the following:

* `cdn_frontdoor_secret_id` - The Resource ID of the Front Door Secret.

* `certificate_type` - The SSL certificate type.

* `minimum_tls_version` - The TLS protocol version that will be used for Https connections.

---

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Front Door Custom Domain.
Comment on lines +6 to +65
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be CDN Front Door?

Suggested change
Gets information about an existing Front Door (standard/premium) Custom Domain.
---
# Data Source: azurerm_cdn_frontdoor_custom_domain
Use this data source to access information about an existing Front Door (standard/premium) Custom Domain.
## Example Usage
```hcl
data "azurerm_cdn_frontdoor_custom_domain" "example" {
name = azurerm_cdn_frontdoor_custom_domain.example.name
profile_name = azurerm_cdn_frontdoor_profile.example.name
resource_group_name = azurerm_cdn_frontdoor_profile.example.resource_group_name
}
```
## Arguments Reference
The following arguments are supported:
* `name` - (Required) The name of the Front Door Custom Domain.
* `profile_name` - (Required) The name of the Front Door Profile which the Front Door Custom Domain is bound to.
* `resource_group_name` - (Required) The name of the Resource Group where the Front Door Profile exists.
## Attributes Reference
In addition to the Arguments listed above - the following Attributes are exported:
* `id` - The ID of the Front Door Custom Domain.
* `cdn_frontdoor_profile_id` - The ID of the Front Door Profile which the Front Door Custom Domain is bound to.
* `expiration_date` - The date time that the token expires.
* `host_name` - The host name of the domain.
* `tls` - A `tls` block as defined below.
* `validation_token` - The challenge used for DNS TXT record or file based validation.
---
A `tls` block exports the following:
* `cdn_frontdoor_secret_id` - The Resource ID of the Front Door Secret.
* `certificate_type` - The SSL certificate type.
* `minimum_tls_version` - The TLS protocol version that will be used for Https connections.
---
## Timeouts
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
* `read` - (Defaults to 5 minutes) Used when retrieving the Front Door Custom Domain.
Gets information about an existing CDN Front Door (standard/premium) Custom Domain.
---
# Data Source: azurerm_cdn_frontdoor_custom_domain
Use this data source to access information about an existing CDN Front Door (standard/premium) Custom Domain.
## Example Usage
```hcl
data "azurerm_cdn_frontdoor_custom_domain" "example" {
name = azurerm_cdn_frontdoor_custom_domain.example.name
profile_name = azurerm_cdn_frontdoor_profile.example.name
resource_group_name = azurerm_cdn_frontdoor_profile.example.resource_group_name
}

Arguments Reference

The following arguments are supported:

  • name - (Required) The name of the CDN Front Door Custom Domain.

  • profile_name - (Required) The name of the CDN Front Door Profile which the Front Door Custom Domain is bound to.

  • resource_group_name - (Required) The name of the Resource Group where the CDN Front Door Profile exists.

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the CDN Front Door Custom Domain.

  • cdn_frontdoor_profile_id - The ID of the CDN Front Door Profile which the CDN Front Door Custom Domain is bound to.

  • expiration_date - The date time that the token expires.

  • host_name - The host name of the domain.

  • tls - A tls block as defined below.

  • validation_token - The challenge used for DNS TXT record or file based validation.


A tls block exports the following:

  • cdn_frontdoor_secret_id - The ID of the CDN Front Door Secret.

  • certificate_type - The SSL certificate type.

  • minimum_tls_version - The TLS protocol version that will be used for HTTPS connections.


Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • read - (Defaults to 5 minutes) Used when retrieving the CDN Front Door Custom Domain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That used to be true but we have changed all of the documentation to be Front Door (standard/premium) at the request of the service team. However, we did not change the resources, they are still cdn_frontdoor