issues/204 - Initial outline of the CDN resource, (schema, resource, test and docs).
This commit is contained in:
parent
6eb3f27492
commit
dff9585dac
|
@ -53,6 +53,7 @@ func Provider() terraform.ResourceProvider {
|
|||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"digitalocean_certificate": resourceDigitalOceanCertificate(),
|
||||
"digitalocean_cdn": resourceDigitalOceanCDN(),
|
||||
"digitalocean_database_cluster": resourceDigitalOceanDatabaseCluster(),
|
||||
"digitalocean_domain": resourceDigitalOceanDomain(),
|
||||
"digitalocean_droplet": resourceDigitalOceanDroplet(),
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package digitalocean
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
)
|
||||
|
||||
func resourceDigitalOceanCDN() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceDigitalOceanCDNCreate,
|
||||
Read: resourceDigitalOceanCDNRead,
|
||||
Update: resourceDigitalOceanCDNUpdate,
|
||||
Delete: resourceDigitalOceanCDNDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"origin": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "fully qualified domain name (FQDN) for the origin server",
|
||||
ValidateFunc: validation.NoZeroValues,
|
||||
},
|
||||
"ttl": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "The amount of time the content is cached in the CDN",
|
||||
},
|
||||
"certificate_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "ID of a DigitalOcean managed TLS certificate for use with custom domains",
|
||||
},
|
||||
"custom_domain": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "fully qualified domain name (FQDN) for custom subdomain, (requires certificate_id)",
|
||||
},
|
||||
"endpoint": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "fully qualified domain name (FQDN) to serve the CDN content",
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The date and time (ISO8601) of when the CDN endpoint was created.",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceDigitalOceanCDNCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*CombinedConfig).godoClient()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDigitalOceanCDNRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*CombinedConfig).godoClient()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDigitalOceanCDNUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*CombinedConfig).godoClient()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDigitalOceanCDNDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*CombinedConfig).godoClient()
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package digitalocean
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccDigitalOceanCDN_Basic(t *testing.T) {
|
||||
digitalOceanBucketName := fmt.Sprintf("tf-test-bucket-%d", acctest.RandInt())
|
||||
cdnConfig := fmt.Sprintf(testAccCheckDigitalOceanCDNConfig_basic, digitalOceanBucketName)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckDigitalOceanCDNDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: cdnConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckDigitalOceanCDNExists("digitalocean_cdn.foobar"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_cdn.foobar", "origin", digitalOceanBucketName+".ams3.digitaloceanspaces.com"),
|
||||
resource.TestCheckResourceAttr("digitalocean_cdn.foobar", "ttl", "3600"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanCDNDestroy(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*CombinedConfig).godoClient()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanCDNExists(resource string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
const testAccCheckDigitalOceanCDNConfig_basic = `
|
||||
resource "digitalocean_spaces_bucket" "bucket" {
|
||||
name = "%s"
|
||||
region = "ams3"
|
||||
acl = "public-read"
|
||||
}
|
||||
|
||||
resource "digitalocean_cdn" "foobar" {
|
||||
origin = "${digitalocean_spaces_bucket.bucket.bucket_domain_name}"
|
||||
}`
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
layout: "digitalocean"
|
||||
page_title: "DigitalOcean: digitalocean_cdn"
|
||||
sidebar_current: "docs-do-resource-cdn"
|
||||
description: |-
|
||||
Provides a DigitalOcean CDN Endpoint resource.
|
||||
---
|
||||
|
||||
# digitalocean\_cdn
|
||||
|
||||
Provides a DigitalOcean CDN Endpoint resource.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```hcl
|
||||
# Create a new Spaces Bucket
|
||||
resource "digitalocean_spaces_bucket" "bucket" {
|
||||
name = "example.sfo2.digitaloceanspaces.com"
|
||||
region = "sfo2"
|
||||
acl = "public-read"
|
||||
}
|
||||
|
||||
# Add a CDN endpoint to the Spaces Bucket
|
||||
resource "digitalocean_cdn" "cdn" {
|
||||
origin = "${digitalocean_spaces_bucket.bucket.bucket_domain_name}"
|
||||
}
|
||||
|
||||
# Output the endpoint for the CDN reosurce
|
||||
output "fqdn" {
|
||||
value = "${digitalocean_cdn.cdn.endpoint}"
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
*
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
*
|
||||
|
||||
## Import
|
||||
|
||||
|
Loading…
Reference in New Issue