Skip to content

Commit

Permalink
Update to cloudflare-go 0.10.0
Browse files Browse the repository at this point in the history
Pulls in the deprecation of `Organization` in favour of `Account`.

Closes cloudflare#227
  • Loading branch information
jacobbednarz committed Aug 21, 2019
1 parent 1b53e57 commit 488d093
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.5
1.12.9
6 changes: 3 additions & 3 deletions cloudflare/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

if orgId, ok := d.GetOk("org_id"); ok {
log.Printf("[INFO] Using specified organization id %s in Cloudflare provider", orgId.(string))
options = append(options, cloudflare.UsingOrganization(orgId.(string)))
options = append(options, cloudflare.UsingAccount(orgId.(string)))
} else if zoneName, ok := d.GetOk("use_org_from_zone"); ok {
zoneId, err := client.ZoneIDByName(zoneName.(string))
if err != nil {
Expand All @@ -157,7 +157,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
}
log.Printf("[DEBUG] Looked up zone to match organization details to: %#v", zone)

orgs, _, err := client.ListOrganizations()
orgs, _, err := client.Accounts(cloudflare.PaginationOptions{})
if err != nil {
return nil, fmt.Errorf("error listing organizations: %s", err.Error())
}
Expand All @@ -170,7 +170,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

if contains(orgIds, zone.Owner.ID) {
log.Printf("[INFO] Using organization %#v in Cloudflare provider", zone.Owner)
options = append(options, cloudflare.UsingOrganization(zone.Owner.ID))
options = append(options, cloudflare.UsingAccount(zone.Owner.ID))
} else {
log.Printf("[INFO] Zone ownership specified but organization owner not found. Falling back to using user API for Cloudflare provider")
}
Expand Down
18 changes: 9 additions & 9 deletions cloudflare/resource_cloudflare_access_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func resourceCloudflareAccessRuleCreate(d *schema.ResourceData, meta interface{}
var err error

if zone == "" && zoneID == "" {
if client.OrganizationID != "" {
r, err = client.CreateOrganizationAccessRule(client.OrganizationID, newRule)
if client.AccountID != "" {
r, err = client.CreateAccountAccessRule(client.AccountID, newRule)
} else {
r, err = client.CreateUserAccessRule(newRule)
}
Expand Down Expand Up @@ -142,8 +142,8 @@ func resourceCloudflareAccessRuleRead(d *schema.ResourceData, meta interface{})
var err error

if zoneID == "" {
if client.OrganizationID != "" {
accessRuleResponse, err = client.OrganizationAccessRule(client.OrganizationID, d.Id())
if client.AccountID != "" {
accessRuleResponse, err = client.AccountAccessRule(client.AccountID, d.Id())
} else {

accessRuleResponse, err = client.UserAccessRule(d.Id())
Expand Down Expand Up @@ -203,8 +203,8 @@ func resourceCloudflareAccessRuleUpdate(d *schema.ResourceData, meta interface{}
var err error

if zoneID == "" {
if client.OrganizationID != "" {
_, err = client.UpdateOrganizationAccessRule(client.OrganizationID, d.Id(), newRule)
if client.AccountID != "" {
_, err = client.UpdateAccountAccessRule(client.AccountID, d.Id(), newRule)
} else {
_, err = client.UpdateUserAccessRule(d.Id(), newRule)
}
Expand All @@ -228,8 +228,8 @@ func resourceCloudflareAccessRuleDelete(d *schema.ResourceData, meta interface{}
var err error

if zoneID == "" {
if client.OrganizationID != "" {
_, err = client.DeleteOrganizationAccessRule(client.OrganizationID, d.Id())
if client.AccountID != "" {
_, err = client.DeleteAccountAccessRule(client.AccountID, d.Id())
} else {
_, err = client.DeleteUserAccessRule(d.Id())
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func resourceCloudflareAccessRuleImport(d *schema.ResourceData, meta interface{}

switch accessRuleType {
case "account":
client.OrganizationID = accessRuleTypeIdentifier
client.AccountID = accessRuleTypeIdentifier
case "zone":
d.Set("zone_id", accessRuleTypeIdentifier)
}
Expand Down
10 changes: 5 additions & 5 deletions cloudflare/resource_cloudflare_account_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func resourceCloudflareAccountMember() *schema.Resource {
func resourceCloudflareAccountMemberRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)

_, err := client.AccountMember(client.OrganizationID, d.Id())
_, err := client.AccountMember(client.AccountID, d.Id())
if err != nil {
if strings.Contains(err.Error(), "Member not found") ||
strings.Contains(err.Error(), "HTTP status 404") {
Expand All @@ -67,7 +67,7 @@ func resourceCloudflareAccountMemberDelete(d *schema.ResourceData, meta interfac

log.Printf("[INFO] Deleting Cloudflare account member ID: %s", d.Id())

err := client.DeleteAccountMember(client.OrganizationID, d.Id())
err := client.DeleteAccountMember(client.AccountID, d.Id())
if err != nil {
return fmt.Errorf("error deleting Cloudflare account member: %s", err)
}
Expand All @@ -86,7 +86,7 @@ func resourceCloudflareAccountMemberCreate(d *schema.ResourceData, meta interfac
accountMemberRoleIDs = append(accountMemberRoleIDs, roleID.(string))
}

r, err := client.CreateAccountMember(client.OrganizationID, memberEmailAddress, accountMemberRoleIDs)
r, err := client.CreateAccountMember(client.AccountID, memberEmailAddress, accountMemberRoleIDs)

if err != nil {
return fmt.Errorf("error creating Cloudflare account member: %s", err)
Expand All @@ -107,12 +107,12 @@ func resourceCloudflareAccountMemberUpdate(d *schema.ResourceData, meta interfac
memberRoles := d.Get("role_ids").([]interface{})

for _, r := range memberRoles {
accountRole, _ := client.AccountRole(client.OrganizationID, r.(string))
accountRole, _ := client.AccountRole(client.AccountID, r.(string))
accountRoles = append(accountRoles, accountRole)
}

updatedAccountMember := cloudflare.AccountMember{Roles: accountRoles}
_, err := client.UpdateAccountMember(client.OrganizationID, d.Id(), updatedAccountMember)
_, err := client.UpdateAccountMember(client.AccountID, d.Id(), updatedAccountMember)
if err != nil {
return fmt.Errorf("failed to update Cloudflare account member: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cloudflare/resource_cloudflare_worker_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func resourceCloudflareWorkerRouteImport(d *schema.ResourceData, meta interface{
routes, err := client.ListWorkerRoutes(zoneID)

for _, r := range routes.Routes {
if r.ID == routeId && client.OrganizationID != "" {
if r.ID == routeId && client.AccountID != "" {
isEnterpriseWorker = true
}
}
Expand Down
6 changes: 3 additions & 3 deletions cloudflare/resource_cloudflare_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ 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,
account := cloudflare.Account{
ID: client.AccountID,
}

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

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

if err != nil {
return fmt.Errorf("Error creating zone %q: %s", zoneName, err)
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/terraform-providers/terraform-provider-cloudflare
go 1.12

require (
github.com/cloudflare/cloudflare-go v0.9.4
github.com/cloudflare/cloudflare-go v0.10.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-hclog v0.9.2 // indirect
github.com/hashicorp/hcl2 v0.0.0-20190812005017-72d32879a5c5 // indirect
github.com/hashicorp/terraform v0.12.6
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/net v0.0.0-20190628185345-da137c7871d7
golang.org/x/time v0.0.0-20190513212739-9d24e82272b4 // indirect
google.golang.org/genproto v0.0.0-20190819205937-24fa4b261c55 // indirect
)
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ github.com/chzyer/readline v0.0.0-20161106042343-c914be64f07d/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/cloudflare-go v0.9.4 h1:L3P7f+/Y9TYqZwjXBpVe/DRXcSmaujdaV2N07ZgDxR4=
github.com/cloudflare/cloudflare-go v0.9.4/go.mod h1:X6KWDVXllCSjZ6KOlwVGfGIiSosjc7/5DtR6sbcwMDw=
github.com/cloudflare/cloudflare-go v0.10.0 h1:wJPNqfrQO0w3fCiQcf/2T4lR2y6Q2fAwRszllljgb8I=
github.com/cloudflare/cloudflare-go v0.10.0/go.mod h1:fOESqHl/jzAmCtEyjceLkw3v0rVjzl8V9iehxZPynXY=
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible h1:jFneRYjIvLMLhDLCzuTuU4rSJUjRplcJQ7pD7MnhC04=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -361,6 +361,8 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d h1:Z4EH+5EffvBEhh37F0C0DnpklTMh00JOkjW5zK3ofBI=
github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
Expand All @@ -371,7 +373,7 @@ github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5 h1:cMjKdf4PxEBN9K5HaD9UM
github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok=
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down Expand Up @@ -409,7 +411,6 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190511005446-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -475,7 +476,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/cloudflare/cloudflare-go/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/cloudflare/cloudflare-go/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions vendor/github.com/cloudflare/cloudflare-go/cloudflare.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions vendor/github.com/cloudflare/cloudflare-go/firewall.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions vendor/github.com/cloudflare/cloudflare-go/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 488d093

Please sign in to comment.