Skip to content

Commit

Permalink
Merge pull request #2939 from cloudflare/support-secondary-zone-type
Browse files Browse the repository at this point in the history
resource/cloudflare_zone: add support for `secondary` types
  • Loading branch information
jacobbednarz authored Nov 14, 2023
2 parents 4118d52 + 60fed84 commit f0080f8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .changelog/2939.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_zone: add support for `secondary` zone types
```
2 changes: 1 addition & 1 deletion docs/resources/zone.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "cloudflare_zone" "example" {
- `jump_start` (Boolean) Whether to scan for DNS records on creation. Ignored after zone is created.
- `paused` (Boolean) Whether this zone is paused (traffic bypasses Cloudflare). Defaults to `false`.
- `plan` (String) The name of the commercial plan to apply to the zone. Available values: `free`, `lite`, `pro`, `pro_plus`, `business`, `enterprise`, `partners_free`, `partners_pro`, `partners_business`, `partners_enterprise`.
- `type` (String) A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or a CNAME setup. Available values: `full`, `partial`. Defaults to `full`.
- `type` (String) A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or a CNAME setup. Available values: `full`, `partial`, `secondary`. Defaults to `full`.

### Read-Only

Expand Down
52 changes: 32 additions & 20 deletions internal/sdkv2provider/resource_cloudflare_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestAccCloudflareZone_PartialSetup(t *testing.T) {
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testZoneConfigWithPartialSetup(rnd, "foo.net", "true", "false", "free", accountID),
Config: testZoneConfigWithTypeSetup(rnd, "foo.net", "true", "false", "free", accountID, "partial"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone", "foo.net"),
resource.TestCheckResourceAttr(name, "paused", "true"),
Expand All @@ -110,7 +110,7 @@ func TestAccCloudflareZone_FullSetup(t *testing.T) {
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testZoneConfigWithExplicitFullSetup(rnd, fmt.Sprintf("%s.cfapi.net", rnd), "true", "false", "free", accountID),
Config: testZoneConfigWithTypeSetup(rnd, fmt.Sprintf("%s.cfapi.net", rnd), "true", "false", "free", accountID, "full"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone", fmt.Sprintf("%s.cfapi.net", rnd)),
resource.TestCheckResourceAttr(name, "paused", "true"),
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestAccCloudflareZone_WithEnterprisePlan(t *testing.T) {
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testZoneConfigWithExplicitFullSetup(rnd, fmt.Sprintf("%s.cfapi.net", rnd), "false", "false", "enterprise", accountID),
Config: testZoneConfigWithTypeSetup(rnd, fmt.Sprintf("%s.cfapi.net", rnd), "false", "false", "enterprise", accountID, "full"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone", fmt.Sprintf("%s.cfapi.net", rnd)),
resource.TestCheckResourceAttr(name, "paused", "false"),
Expand All @@ -226,6 +226,30 @@ func TestAccCloudflareZone_WithEnterprisePlan(t *testing.T) {
})
}

func TestAccCloudflareZone_Secondary(t *testing.T) {
rnd := generateRandomResourceName()
name := "cloudflare_zone." + rnd
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
zoneName := os.Getenv("CLOUDFLARE_DOMAIN")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testZoneConfigWithTypeSetup(rnd, fmt.Sprintf("%s.%s", rnd, zoneName), "true", "false", "enterprise", accountID, "secondary"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "zone", fmt.Sprintf("%s.%s", rnd, zoneName)),
resource.TestCheckResourceAttr(name, "paused", "true"),
resource.TestCheckResourceAttr(name, "name_servers.#", "2"),
resource.TestCheckResourceAttr(name, "plan", planIDEnterprise),
resource.TestCheckResourceAttr(name, "type", "secondary"),
),
},
},
})
}

func testZoneConfig(resourceID, zoneName, paused, jumpStart, accountID string) string {
return fmt.Sprintf(`
resource "cloudflare_zone" "%[1]s" {
Expand Down Expand Up @@ -256,10 +280,10 @@ func TestAccCloudflareZone_SetType(t *testing.T) {
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testZoneConfigWithExplicitFullSetup(rnd, fmt.Sprintf("%s.%s", rnd, zoneName), "true", "false", "enterprise", accountID),
Config: testZoneConfigWithTypeSetup(rnd, fmt.Sprintf("%s.%s", rnd, zoneName), "true", "false", "enterprise", accountID, "full"),
},
{
Config: testZoneConfigWithPartialSetup(rnd, fmt.Sprintf("%s.%s", rnd, zoneName), "true", "false", "enterprise", accountID),
Config: testZoneConfigWithTypeSetup(rnd, fmt.Sprintf("%s.%s", rnd, zoneName), "true", "false", "enterprise", accountID, "partial"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "type", "partial"),
),
Expand All @@ -268,26 +292,14 @@ func TestAccCloudflareZone_SetType(t *testing.T) {
})
}

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

func testZoneConfigWithExplicitFullSetup(resourceID, zoneName, paused, jumpStart, plan, accountID string) string {
return fmt.Sprintf(`
resource "cloudflare_zone" "%[1]s" {
account_id = "%[6]s"
zone = "%[2]s"
paused = %[3]s
jump_start = %[4]s
plan = "%[5]s"
type = "full"
}`, resourceID, zoneName, paused, jumpStart, plan, accountID)
type = "%[7]s"
}`, resourceID, zoneName, paused, jumpStart, plan, accountID, zoneType)
}
4 changes: 2 additions & 2 deletions internal/sdkv2provider/schema_cloudflare_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func resourceCloudflareZoneSchema() map[string]*schema.Schema {
},
"type": {
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"full", "partial"}, false),
ValidateFunc: validation.StringInSlice([]string{"full", "partial", "secondary"}, false),
Default: "full",
Optional: true,
Description: fmt.Sprintf("A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or a CNAME setup. %s", renderAvailableDocumentationValuesStringSlice([]string{"full", "partial"})),
Description: fmt.Sprintf("A full zone implies that DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or a CNAME setup. %s", renderAvailableDocumentationValuesStringSlice([]string{"full", "partial", "secondary"})),
},
"name_servers": {
Type: schema.TypeList,
Expand Down

0 comments on commit f0080f8

Please sign in to comment.