digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
510 stars 278 forks source link

Add `-static` suffix option to `digitalocean_cdn` for Spaces static website support #1241

Open jahwag opened 1 month ago

jahwag commented 1 month ago

Problem Description

The DigitalOcean provider CDN option should support configurations using website.json. The digitalocean_cdn resource in Terraform currently generates a CNAME record with the value as [bucket-name].[region].cdn.digitaloceanspaces.com.

However, to enable automatic serving of index pages (e.g., index.html defined in website.json), instructions state the need to append -static to the region eg.[bucket-name].[region]-static.digitaloceanspaces.com. This however does not appear to work with CDN, which suggests the feature is not fully ready.

Proposed Solutions

A. Expose the CNAME record value:

   resource "digitalocean_cdn" "frontend" {
     origin           = digitalocean_spaces_bucket.frontend.bucket_domain_name
     custom_domain    = var.custom_domain
     certificate_name = digitalocean_certificate.frontend.name
     cname_value      = "${digitalocean_spaces_bucket.frontend.bucket_domain_name}-static"
   }

B. Add a boolean flag to compute the -static suffix:

   resource "digitalocean_cdn" "frontend" {
     origin           = digitalocean_spaces_bucket.frontend.bucket_domain_name
     custom_domain    = var.custom_domain
     certificate_name = digitalocean_certificate.frontend.name
     website    = true
   }

C. Allow selection of a pre-existing CNAME record:

   resource "digitalocean_cdn" "frontend" {
     origin           = digitalocean_spaces_bucket.frontend.bucket_domain_name
     custom_domain    = var.custom_domain
     certificate_name = digitalocean_certificate.frontend.name
     use_existing_cname = true
   }

Attempted Workaround

Creating the CDN's CNAME record in advance using digitalocean_record causes digitalocean_cdn to fail with a CNAME conflict error.

Additional Context