Skip to content

Commit

Permalink
Merge pull request #1188 from cloudflare/sdk-v2
Browse files Browse the repository at this point in the history
upgrade to terraform-plugin-sdk v2
  • Loading branch information
jacobbednarz authored Sep 20, 2021
2 parents 522c31d + a6b8d8a commit 389dd41
Show file tree
Hide file tree
Showing 166 changed files with 1,535 additions and 1,044 deletions.
51 changes: 51 additions & 0 deletions .changelog/1188.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
```release-note:upgrade-guide
[2.x to 3.x upgrade guide](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/guides/version-3-upgrade)
```

```release-note:note
provider: Golang version has been upgraded to 1.17
```

```release-note:note
provider: terraform-plugin-sdk has been upgraded to 2.x
```

```release-note:note
provider: Minimum Terraform core version is now 0.14
```

```release-note:note
provider: HTTP user agent is now "terraform/<version> terraform-plugin-sdk/<version> terraform-provider-cloudflare/<version>"
```

```release-note:breaking-change
resource/cloudflare_access_rule: `configuration` is now a `TypeList` instead of a `TypeMap`
```

```release-note:enhancement
resource/cloudflare_custom_hostname: `status` is now `Computed` as the value isn't managed by an end user
```

```release-note:enhancement
resource/cloudflare_custom_hostname: `settings` is now `Optional`/`Computed` to reflect the stricter schema validation introduced in terraform-plugin-sdk v2
```

```release-note:enhancement
resource/cloudflare_custom_hostname: `settings.ciphers` is now a `TypeSet` internally to handle suppress ordering changes. Schema representation remains the same
```

```release-note:breaking-change
resource/cloudflare_custom_ssl: `custom_ssl_options` is now a `TypeList` instead of `TypeMap`
```

```release-note:breaking-change
resource/cloudflare_load_balancer: `fixed_response` is now a `TypeList` instead of a `TypeMap`
```

```release-note:breaking-change
resource/cloudflare_load_balancer: fixed_response.status_code` is now a `TypeInt` instead of a `TypeString`
```

```release-note:breaking-change
resource/cloudflare_record: `data` is now a `TypeList` instead of a `TypeMap`
```
4 changes: 3 additions & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Acceptance Tests

on:
push:
branches: [ master ]
branches:
- master
- sdk-v2
paths-ignore:
- 'README.md'
- 'CHANGELOG.md'
Expand Down
2 changes: 1 addition & 1 deletion cloudflare/cloudflare_sweeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestMain(m *testing.M) {
Expand Down
2 changes: 1 addition & 1 deletion cloudflare/data_source_api_token_permission_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceCloudflareApiTokenPermissionGroups() *schema.Resource {
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/data_source_api_token_permission_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareApiTokenPermissionGroups(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions cloudflare/data_source_ip_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"strings"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
Expand Down Expand Up @@ -70,7 +69,7 @@ func dataSourceCloudflareIPRangesRead(d *schema.ResourceData, meta interface{})
all = append(all, IPv6s...)
sort.Strings(all)

d.SetId(strconv.Itoa(hashcode.String(strings.Join(all, "|"))))
d.SetId(strconv.Itoa(hashCodeString(strings.Join(all, "|"))))

if err := d.Set("cidr_blocks", all); err != nil {
return fmt.Errorf("error setting all cidr blocks: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/data_source_ip_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareIPRanges(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/data_source_origin_ca_root_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func dataSourceCloudflareOriginCARootCertificate() *schema.Resource {
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/data_source_origin_ca_root_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareOriginCARootCertificate(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions cloudflare/data_source_waf_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"regexp"

cloudflare "github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func dataSourceCloudflareWAFGroups() *schema.Resource {
Expand Down Expand Up @@ -142,7 +142,7 @@ func dataSourceCloudflareWAFGroupsRead(d *schema.ResourceData, meta interface{})

err = d.Set("groups", groupDetails)
if err != nil {
return fmt.Errorf("Error setting WAF groups: %s", err)
return fmt.Errorf("error setting WAF groups: %s", err)
}

d.SetId(stringListChecksum(groupIds))
Expand Down
12 changes: 9 additions & 3 deletions cloudflare/data_source_waf_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareWAFGroups_NoFilter(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -32,6 +34,8 @@ func TestAccCloudflareWAFGroups_NoFilter(t *testing.T) {
}

func TestAccCloudflareWAFGroups_MatchName(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -53,6 +57,8 @@ func TestAccCloudflareWAFGroups_MatchName(t *testing.T) {
}

func TestAccCloudflareWAFGroups_MatchMode(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -77,7 +83,7 @@ func testAccCheckCloudflareWAFGroupsDataSourceID(n string) resource.TestCheckFun
all := s.RootModule().Resources
rs, ok := all[n]
if !ok {
return fmt.Errorf("Can't find WAF Groups data source: %s", n)
return fmt.Errorf("can't find WAF Groups data source: %s", n)
}

if rs.Primary.ID == "" {
Expand Down
6 changes: 3 additions & 3 deletions cloudflare/data_source_waf_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"regexp"

cloudflare "github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func dataSourceCloudflareWAFPackages() *schema.Resource {
Expand Down Expand Up @@ -133,7 +133,7 @@ func dataSourceCloudflareWAFPackagesRead(d *schema.ResourceData, meta interface{

err = d.Set("packages", packageDetails)
if err != nil {
return fmt.Errorf("Error setting WAF packages: %s", err)
return fmt.Errorf("error setting WAF packages: %s", err)
}

d.SetId(stringListChecksum(packageIds))
Expand Down
16 changes: 13 additions & 3 deletions cloudflare/data_source_waf_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareWAFPackages_NoFilter(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -32,6 +34,8 @@ func TestAccCloudflareWAFPackages_NoFilter(t *testing.T) {
}

func TestAccCloudflareWAFPackages_MatchName(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -53,6 +57,8 @@ func TestAccCloudflareWAFPackages_MatchName(t *testing.T) {
}

func TestAccCloudflareWAFPackages_MatchDetectionMode(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -74,6 +80,8 @@ func TestAccCloudflareWAFPackages_MatchDetectionMode(t *testing.T) {
}

func TestAccCloudflareWAFPackages_MatchSensitivity(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -94,6 +102,8 @@ func TestAccCloudflareWAFPackages_MatchSensitivity(t *testing.T) {
}

func TestAccCloudflareWAFPackages_MatchActionMode(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -118,7 +128,7 @@ func testAccCheckCloudflareWAFPackagesDataSourceID(n string) resource.TestCheckF
all := s.RootModule().Resources
rs, ok := all[n]
if !ok {
return fmt.Errorf("Can't find WAF Packages data source: %s", n)
return fmt.Errorf("can't find WAF Packages data source: %s", n)
}

if rs.Primary.ID == "" {
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/data_source_waf_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"regexp"

cloudflare "github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceCloudflareWAFRules() *schema.Resource {
Expand Down Expand Up @@ -174,7 +174,7 @@ func dataSourceCloudflareWAFRulesRead(d *schema.ResourceData, meta interface{})

err = d.Set("rules", ruleDetails)
if err != nil {
return fmt.Errorf("Error setting WAF rules: %s", err)
return fmt.Errorf("error setting WAF rules: %s", err)
}

d.SetId(stringListChecksum(ruleIds))
Expand Down
12 changes: 9 additions & 3 deletions cloudflare/data_source_waf_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareWAFRules_NoFilter(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -32,6 +34,8 @@ func TestAccCloudflareWAFRules_NoFilter(t *testing.T) {
}

func TestAccCloudflareWAFRules_MatchDescription(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -53,6 +57,8 @@ func TestAccCloudflareWAFRules_MatchDescription(t *testing.T) {
}

func TestAccCloudflareWAFRules_MatchMode(t *testing.T) {
skipV1WAFTestForNonConfiguredDefaultZone(t)

t.Parallel()
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
Expand All @@ -77,7 +83,7 @@ func testAccCheckCloudflareWAFRulesDataSourceID(n string) resource.TestCheckFunc
all := s.RootModule().Resources
rs, ok := all[n]
if !ok {
return fmt.Errorf("Can't find WAF Rules data source: %s", n)
return fmt.Errorf("can't find WAF Rules data source: %s", n)
}

if rs.Primary.ID == "" {
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/data_source_zone_dnssec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceCloudflareZoneDNSSEC() *schema.Resource {
Expand Down Expand Up @@ -71,7 +71,7 @@ func dataSourceCloudflareZoneDNSSECRead(d *schema.ResourceData, meta interface{}

dnssec, err := client.ZoneDNSSECSetting(context.Background(), zoneID)
if err != nil {
return fmt.Errorf("Error finding Zone DNSSEC %q: %s", zoneID, err)
return fmt.Errorf("error finding Zone DNSSEC %q: %s", zoneID, err)
}

d.Set("zone_id", zoneID)
Expand Down
6 changes: 3 additions & 3 deletions cloudflare/data_source_zone_dnssec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareZoneDNSSEC(t *testing.T) {
Expand Down Expand Up @@ -45,7 +45,7 @@ func testAccCheckCloudflareZoneDNSSECDataSourceID(n string) resource.TestCheckFu
all := s.RootModule().Resources
rs, ok := all[n]
if !ok {
return fmt.Errorf("Can't find Zone DNSSEC data source: %s", n)
return fmt.Errorf("can't find Zone DNSSEC data source: %s", n)
}

if rs.Primary.ID == "" {
Expand Down
Loading

0 comments on commit 389dd41

Please sign in to comment.