Skip to content
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

cloudflare_zone: Support partial zones #303

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cloudflare/resource_cloudflare_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ func resourceCloudflareZone() *schema.Resource {
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"full", "partial"}, false),
Default: "full",
Optional: true,
},
"name_servers": {
Type: schema.TypeList,
Expand All @@ -107,13 +109,14 @@ func resourceCloudflareZoneCreate(d *schema.ResourceData, meta interface{}) erro

zoneName := d.Get("zone").(string)
jumpstart := d.Get("jump_start").(bool)
zoneType := d.Get("type").(string)
organization := cloudflare.Organization{
ID: client.OrganizationID,
}

log.Printf("[INFO] Creating Cloudflare Zone: name %s", zoneName)

zone, err := client.CreateZone(zoneName, jumpstart, organization, "full")
zone, err := client.CreateZone(zoneName, jumpstart, organization, zoneType)

if err != nil {
return fmt.Errorf("Error creating zone %q: %s", zoneName, err)
Expand Down
44 changes: 44 additions & 0 deletions cloudflare/resource_cloudflare_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestZone(t *testing.T) {
resource.TestCheckResourceAttr(name, "paused", "true"),
resource.TestCheckResourceAttr(name, "name_servers.#", "2"),
resource.TestCheckResourceAttr(name, "plan", planIDFree),
resource.TestCheckResourceAttr(name, "type", "full"),
),
},
{
Expand All @@ -30,6 +31,27 @@ func TestZone(t *testing.T) {
resource.TestCheckResourceAttr(name, "paused", "true"),
resource.TestCheckResourceAttr(name, "name_servers.#", "2"),
resource.TestCheckResourceAttr(name, "plan", planIDFree),
resource.TestCheckResourceAttr(name, "type", "full"),
),
},
{
Config: testZoneConfigWithPartialSetup("test", "example.org", "true", "false", "free"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone", "example.org"),
resource.TestCheckResourceAttr(name, "paused", "true"),
resource.TestCheckResourceAttr(name, "name_servers.#", "2"),
resource.TestCheckResourceAttr(name, "plan", planIDFree),
resource.TestCheckResourceAttr(name, "type", "partial"),
),
},
{
Config: testZoneConfigWithExplicitFullSetup("test", "example.org", "true", "false", "free"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone", "example.org"),
resource.TestCheckResourceAttr(name, "paused", "true"),
resource.TestCheckResourceAttr(name, "name_servers.#", "2"),
resource.TestCheckResourceAttr(name, "plan", planIDFree),
resource.TestCheckResourceAttr(name, "type", "full"),
),
},
},
Expand Down Expand Up @@ -104,3 +126,25 @@ func TestPlanIDFallsBackToEmptyIfUnknown(t *testing.T) {
})
}
}

func testZoneConfigWithPartialSetup(resourceID, zoneName, paused, jumpStart, plan string) string {
return fmt.Sprintf(`
resource "cloudflare_zone" "%[1]s" {
zone = "%[2]s"
paused = %[3]s
jump_start = %[4]s
plan = "%[5]s"
type = "partial"
}`, resourceID, zoneName, paused, jumpStart, plan)
}

func testZoneConfigWithExplicitFullSetup(resourceID, zoneName, paused, jumpStart, plan string) string {
return fmt.Sprintf(`
resource "cloudflare_zone" "%[1]s" {
zone = "%[2]s"
paused = %[3]s
jump_start = %[4]s
plan = "%[5]s"
type = "full"
}`, resourceID, zoneName, paused, jumpStart, plan)
}
6 changes: 3 additions & 3 deletions website/docs/r/zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ The following arguments are supported:
* `zone` - (Required) The DNS zone name which will be added.
* `paused` - (Optional) Boolean of whether this zone is paused (traffic bypasses Cloudflare). Default: false.
* `jump_start` - (Optional) Boolean of whether to scan for DNS records on creation. Ignored after zone is created. Default: false.
* `plan` - (Optional) The name of the commercial plan to apply to the zone, can be updated once the one is created; one of `free`, `pro`, `business`, `enterprise`.
* `plan` - (Optional) The name of the commercial plan to apply to the zone, can be updated once the one is created; one of `free`, `pro`, `business`, `enterprise`.
* `type` - A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or a CNAME setup. Valid values: `full`, `partial`. Default is `full`.

## Attributes Reference

Expand All @@ -36,8 +37,7 @@ The following attributes are exported:
* `vanity_name_servers` - List of Vanity Nameservers (if set).
* `meta.wildcard_proxiable` - Indicates whether wildcard DNS records can receive Cloudflare security and performance features.
* `meta.phishing_detected` - Indicates if URLs on the zone have been identified as hosting phishing content.
* `status` - Status of the zone. Valid values: `active`, `pending`, `initializing`, `moved`, `deleted`, `deactivated`
* `type` - A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or a CNAME setup. Valid values: `full`, `partial`
* `status` - Status of the zone. Valid values: `active`, `pending`, `initializing`, `moved`, `deleted`, `deactivated`.
* `name_servers` - Cloudflare-assigned name servers. This is only populated for zones that use Cloudflare DNS.

## Import
Expand Down