Skip to content

Commit 2d757a9

Browse files
Feature: CDN custom domain resource and data source (#801)
* Feature: CDN custom domain resource and data source * stabilize acceptance tests * add guide * review changes --------- Co-authored-by: Malte Ehrlen <malte.ehrlen@freiheit.com>
1 parent 0a86417 commit 2d757a9

13 files changed

Lines changed: 914 additions & 19 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackit_cdn_custom_domain Data Source - stackit"
4+
subcategory: ""
5+
description: |-
6+
CDN distribution data source schema.
7+
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
8+
---
9+
10+
# stackit_cdn_custom_domain (Data Source)
11+
12+
CDN distribution data source schema.
13+
14+
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
15+
16+
## Example Usage
17+
18+
```terraform
19+
data "stackit_cdn_custom_domain" "example" {
20+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
21+
distribution_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
22+
name = "https://xxx.xxx"
23+
}
24+
```
25+
26+
<!-- schema generated by tfplugindocs -->
27+
## Schema
28+
29+
### Required
30+
31+
- `distribution_id` (String) CDN distribution ID
32+
- `name` (String)
33+
- `project_id` (String) STACKIT project ID associated with the distribution
34+
35+
### Read-Only
36+
37+
- `errors` (List of String) List of distribution errors
38+
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`distribution_id`".
39+
- `status` (String) Status of the distribution
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
page_title: "Using STACKIT CDN with your own domain"
3+
---
4+
# Using STACKIT CDN with your own domain
5+
6+
## Overview
7+
8+
This guide outlines the process of creating a STACKIT CDN distribution and configuring it to make use of an existing domain using STACKIT DNS.
9+
10+
## Steps
11+
12+
1. **Create a STACKIT CDN and DNS Zone**
13+
14+
Create the CDN distribution and the DNS zone.
15+
16+
```terraform
17+
resource "stackit_cdn_distribution" "example_distribution" {
18+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
19+
config = {
20+
backend = {
21+
type = "http"
22+
origin_url = "mybackend.onstackit.cloud"
23+
}
24+
regions = ["EU", "US", "ASIA", "AF", "SA"]
25+
}
26+
}
27+
28+
resource "stackit_dns_zone" "example_zone" {
29+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
30+
name = "My DNS zone"
31+
dns_name = "myapp.runs.onstackit.cloud"
32+
contact_email = "aa@bb.ccc"
33+
type = "primary"
34+
}
35+
```
36+
37+
2. **Add CNAME record to your DNS zone**
38+
39+
If you want to redirect your entire domain to the CDN, you can instead use an A record.
40+
```terraform
41+
resource "stackit_dns_record_set" "example" {
42+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
43+
zone_id = stackit_dns_zone.example_zone.zone_id
44+
name = "cdn"
45+
type = "CNAME"
46+
records = ["${stackit_cdn_distribution.domains[0].name}."]
47+
}
48+
```
49+
50+
3. **Create a STACKIT CDN Custom Domain**
51+
```terraform
52+
# Create a CDN custom domain
53+
resource "stackit_cdn_custom_domain" "example" {
54+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
55+
distribution_id = stackit_cdn_distribution.example_distribution.distribution_id
56+
name = "${stackit_dns_record_set.example.name}.${stackit_dns_zone.dns_name}"
57+
}
58+
```
59+
60+
Now, you can access your content on the url `cdn.myapp.runs.onstackit.cloud`.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackit_cdn_custom_domain Resource - stackit"
4+
subcategory: ""
5+
description: |-
6+
CDN distribution data source schema.
7+
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
8+
---
9+
10+
# stackit_cdn_custom_domain (Resource)
11+
12+
CDN distribution data source schema.
13+
14+
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
15+
16+
## Example Usage
17+
18+
```terraform
19+
# Create a CDN custom domain
20+
resource "stackit_cdn_custom_domain" "example" {
21+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
22+
distribution_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
23+
name = "https://xxx.xxx"
24+
}
25+
```
26+
27+
<!-- schema generated by tfplugindocs -->
28+
## Schema
29+
30+
### Required
31+
32+
- `distribution_id` (String) CDN distribution ID
33+
- `name` (String)
34+
- `project_id` (String) STACKIT project ID associated with the distribution
35+
36+
### Read-Only
37+
38+
- `errors` (List of String) List of distribution errors
39+
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`distribution_id`".
40+
- `status` (String) Status of the distribution

docs/resources/cdn_distribution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ resource "stackit_cdn_distribution" "example_distribution" {
4040
### Read-Only
4141

4242
- `created_at` (String) Time when the distribution was created
43-
- `distribution_id` (String) STACKIT project ID associated with the distribution
43+
- `distribution_id` (String) CDN distribution ID
4444
- `domains` (Attributes List) List of configured domains for the distribution (see [below for nested schema](#nestedatt--domains))
4545
- `errors` (List of String) List of distribution errors
4646
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`distribution_id`".
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
data "stackit_cdn_custom_domain" "example" {
2+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
3+
distribution_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4+
name = "https://xxx.xxx"
5+
}
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Create a CDN custom domain
2+
resource "stackit_cdn_custom_domain" "example" {
3+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4+
distribution_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
5+
name = "https://xxx.xxx"
6+
}

0 commit comments

Comments
 (0)