Skip to content

Commit

Permalink
cdn: handle 'needs-cloudflare-cert' case in read func. (#1095)
Browse files Browse the repository at this point in the history
* cdn: handle 'needs-cloudflare-cert' case in read func.

* Update test to include a custom subdomain.
  • Loading branch information
andrewsomething authored Dec 18, 2023
1 parent 556c2da commit 00eb854
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion digitalocean/cdn/resource_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func resourceDigitalOceanCDNRead(ctx context.Context, d *schema.ResourceData, me
d.Set("created_at", cdn.CreatedAt.UTC().String())
d.Set("custom_domain", cdn.CustomDomain)

if cdn.CertificateID != "" {
if cdn.CertificateID != "" && cdn.CertificateID != needsCloudflareCert {
// When the certificate type is lets_encrypt, the certificate
// ID will change when it's renewed, so we have to rely on the
// certificate name as the primary identifier instead.
Expand All @@ -224,6 +224,11 @@ func resourceDigitalOceanCDNRead(ctx context.Context, d *schema.ResourceData, me
d.Set("certificate_name", cert.Name)
}

if cdn.CertificateID == needsCloudflareCert {
d.Set("certificate_id", cdn.CertificateID)
d.Set("certificate_name", cdn.CertificateID)
}

return nil
}

Expand Down
8 changes: 7 additions & 1 deletion digitalocean/cdn/resource_cdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cdn_test
import (
"context"
"fmt"
"os"
"testing"

"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/acceptance"
Expand Down Expand Up @@ -40,9 +41,13 @@ func TestAccDigitalOceanCDN_Create(t *testing.T) {
}

func TestAccDigitalOceanCDN_CreateWithNeedCloudflareCert(t *testing.T) {
domain := os.Getenv("DO_TEST_SUBDOMAIN")
if domain == "" {
t.Skip("Test requires an active DO manage sub domain. Set DO_TEST_SUBDOMAIN")
}

bucketName := generateBucketName()
cdnCreateConfig := fmt.Sprintf(testAccCheckDigitalOceanCDNConfig_CreateWithNeedCloudflareCert, bucketName)
cdnCreateConfig := fmt.Sprintf(testAccCheckDigitalOceanCDNConfig_CreateWithNeedCloudflareCert, bucketName, domain)

expectedOrigin := bucketName + originSuffix
expectedTTL := "3600"
Expand Down Expand Up @@ -244,6 +249,7 @@ resource "digitalocean_spaces_bucket" "bucket" {
resource "digitalocean_cdn" "foobar" {
origin = digitalocean_spaces_bucket.bucket.bucket_domain_name
certificate_name = "needs-cloudflare-cert"
custom_domain = "%s"
}`

const testAccCheckDigitalOceanCDNConfig_Create_with_TTL = `
Expand Down

0 comments on commit 00eb854

Please sign in to comment.