-
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
[New Data Source:] azurerm_cdn_frontdoor_custom_domain
#19357
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b4b812d
add cdn frontdoor custom domain data source
WodansSon 54653c5
Fix documentation description for RG name
WodansSon f570329
Update internal/services/cdn/cdn_frontdoor_custom_domain_data_source.go
WodansSon 0ad8597
Resolve PR comments
WodansSon 6817c2f
Revert documentation change
WodansSon aa90e7a
Fix build errors
WodansSon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
internal/services/cdn/cdn_frontdoor_custom_domain_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
44 changes: 44 additions & 0 deletions
44
internal/services/cdn/cdn_frontdoor_custom_domain_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should this be
CDN Front Door
?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
- Atls
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.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.
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