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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump github.com/cloudflare/cloudflare-go from 0.36.0 to 0.37.0 #1563

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changelog/1563.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:note
resource/cloudflare_byo_ip_prefix: now requires an explicit `account_id` parameter instead of implicitly relying on `client.AccountID`
```

```release-note:note
resource/cloudflare_worker_cron_trigger: now requires an explicit `account_id` parameter instead of implicitly relying on `client.AccountID`
```

```release-note:note
resource/cloudflare_magic_firewall_ruleset: no longer sets `client.AccountID` internally for resources
```

```release-note:note
resource/cloudflare_static_route: no longer sets `client.AccountID` internally for resources
```

```release-note:note
resource/cloudflare_ip_list: no longer sets `client.AccountID` internally for resources
```
10 changes: 6 additions & 4 deletions cloudflare/resource_cloudflare_byo_ip_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ func resourceCloudflareBYOIPPrefixImport(d *schema.ResourceData, meta interface{

func resourceCloudflareBYOIPPrefixRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)

prefix, err := client.GetPrefix(context.Background(), d.Id())
prefix, err := client.GetPrefix(context.Background(), accountID, d.Id())
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error reading IP prefix information for %q", d.Id()))
}

d.Set("description", prefix.Description)

advertisementStatus, err := client.GetAdvertisementStatus(context.Background(), d.Id())
advertisementStatus, err := client.GetAdvertisementStatus(context.Background(), accountID, d.Id())
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error reading advertisement status of IP prefix for %q", d.Id()))
}
Expand All @@ -64,15 +65,16 @@ func resourceCloudflareBYOIPPrefixRead(d *schema.ResourceData, meta interface{})

func resourceCloudflareBYOIPPrefixUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)

if _, ok := d.GetOk("description"); ok && d.HasChange("description") {
if _, err := client.UpdatePrefixDescription(context.Background(), d.Id(), d.Get("description").(string)); err != nil {
if _, err := client.UpdatePrefixDescription(context.Background(), accountID, d.Id(), d.Get("description").(string)); err != nil {
return errors.Wrap(err, fmt.Sprintf("cannot update prefix description for %q", d.Id()))
}
}

if _, ok := d.GetOk("advertisement"); ok && d.HasChange("advertisement") {
if _, err := client.UpdateAdvertisementStatus(context.Background(), d.Id(), boolFromString(d.Get("advertisement").(string))); err != nil {
if _, err := client.UpdateAdvertisementStatus(context.Background(), accountID, d.Id(), boolFromString(d.Get("advertisement").(string))); err != nil {
return errors.Wrap(err, fmt.Sprintf("cannot update prefix advertisement status for %q", d.Id()))
}
}
Expand Down
22 changes: 11 additions & 11 deletions cloudflare/resource_cloudflare_ip_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func resourceCloudflareIPList() *schema.Resource {

func resourceCloudflareIPListCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

list, err := client.CreateIPList(context.Background(), d.Get("name").(string), d.Get("description").(string), d.Get("kind").(string))
list, err := client.CreateIPList(context.Background(), accountID, d.Get("name").(string), d.Get("description").(string), d.Get("kind").(string))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error creating IP List %s", d.Get("name").(string)))
}
Expand All @@ -37,7 +37,7 @@ func resourceCloudflareIPListCreate(d *schema.ResourceData, meta interface{}) er

if items, ok := d.GetOk("item"); ok {
IPListItems := buildIPListItemsCreateRequest(items.(*schema.Set).List())
_, err = client.CreateIPListItems(context.Background(), d.Id(), IPListItems)
_, err = client.CreateIPListItems(context.Background(), accountID, d.Id(), IPListItems)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error creating IP List Items"))
}
Expand All @@ -64,9 +64,9 @@ func resourceCloudflareIPListImport(d *schema.ResourceData, meta interface{}) ([

func resourceCloudflareIPListRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

list, err := client.GetIPList(context.Background(), d.Id())
list, err := client.GetIPList(context.Background(), accountID, d.Id())
if err != nil {
if strings.Contains(err.Error(), "could not find list") {
log.Printf("[INFO] IP List %s no longer exists", d.Id())
Expand All @@ -80,7 +80,7 @@ func resourceCloudflareIPListRead(d *schema.ResourceData, meta interface{}) erro
d.Set("description", list.Description)
d.Set("kind", list.Kind)

items, err := client.ListIPListItems(context.Background(), d.Id())
items, err := client.ListIPListItems(context.Background(), accountID, d.Id())
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error reading IP List Items"))
}
Expand All @@ -103,16 +103,16 @@ func resourceCloudflareIPListRead(d *schema.ResourceData, meta interface{}) erro

func resourceCloudflareIPListUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

_, err := client.UpdateIPList(context.Background(), d.Id(), d.Get("description").(string))
_, err := client.UpdateIPList(context.Background(), accountID, d.Id(), d.Get("description").(string))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error updating IP List description"))
}

if items, ok := d.GetOk("item"); ok {
IPListItems := buildIPListItemsCreateRequest(items.(*schema.Set).List())
_, err = client.ReplaceIPListItems(context.Background(), d.Id(), IPListItems)
_, err = client.ReplaceIPListItems(context.Background(), accountID, d.Id(), IPListItems)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error creating IP List Items"))
}
Expand All @@ -123,9 +123,9 @@ func resourceCloudflareIPListUpdate(d *schema.ResourceData, meta interface{}) er

func resourceCloudflareIPListDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

_, err := client.DeleteIPList(context.Background(), d.Id())
_, err := client.DeleteIPList(context.Background(), accountID, d.Id())
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error deleting IP List with ID %q", d.Id()))
}
Expand Down
9 changes: 5 additions & 4 deletions cloudflare/resource_cloudflare_ip_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccCloudflareIPListExists(t *testing.T) {
func TestAccCloudflareIPList_Exists(t *testing.T) {
// Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the IP List
// endpoint does not yet support the API tokens.
if os.Getenv("CLOUDFLARE_API_TOKEN") != "" {
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestAccCloudflareIPListExists(t *testing.T) {
})
}

func TestAccCloudflareIPListUpdateDescription(t *testing.T) {
func TestAccCloudflareIPList_UpdateDescription(t *testing.T) {
// Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the IP List
// endpoint does not yet support the API tokens.
if os.Getenv("CLOUDFLARE_API_TOKEN") != "" {
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestAccCloudflareIPListUpdateDescription(t *testing.T) {
})
}

func TestAccCloudflareIPListUpdate(t *testing.T) {
func TestAccCloudflareIPList_Update(t *testing.T) {
// Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the IP List
// endpoint does not yet support the API tokens.
if os.Getenv("CLOUDFLARE_API_TOKEN") != "" {
Expand Down Expand Up @@ -143,6 +143,7 @@ func TestAccCloudflareIPListUpdate(t *testing.T) {

func testAccCheckCloudflareIPListExists(n string, list *cloudflare.IPList) resource.TestCheckFunc {
return func(s *terraform.State) error {
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("not found: %s", n)
Expand All @@ -153,7 +154,7 @@ func testAccCheckCloudflareIPListExists(n string, list *cloudflare.IPList) resou
}

client := testAccProvider.Meta().(*cloudflare.API)
foundIPList, err := client.GetIPList(context.Background(), rs.Primary.ID)
foundIPList, err := client.GetIPList(context.Background(), accountID, rs.Primary.ID)
if err != nil {
return err
}
Expand Down
17 changes: 8 additions & 9 deletions cloudflare/resource_cloudflare_magic_firewall_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ func resourceCloudflareMagicFirewallRuleset() *schema.Resource {

func resourceCloudflareMagicFirewallRulesetCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

rules, err := buildMagicFirewallRulesetRulesFromResource(d.Get("rules"))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error building ruleset from resource"))
}

ruleset, err := client.CreateMagicFirewallRuleset(context.Background(),
accountID,
d.Get("name").(string),
d.Get("description").(string),
rules)
Expand All @@ -49,7 +50,6 @@ func resourceCloudflareMagicFirewallRulesetCreate(d *schema.ResourceData, meta i
}

func resourceCloudflareMagicFirewallRulesetImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*cloudflare.API)
attributes := strings.SplitN(d.Id(), "/", 2)

if len(attributes) != 2 {
Expand All @@ -59,7 +59,6 @@ func resourceCloudflareMagicFirewallRulesetImport(d *schema.ResourceData, meta i
accountID, rulesetID := attributes[0], attributes[1]
d.SetId(rulesetID)
d.Set("account_id", accountID)
client.AccountID = accountID

resourceCloudflareMagicFirewallRulesetRead(d, meta)

Expand All @@ -68,9 +67,9 @@ func resourceCloudflareMagicFirewallRulesetImport(d *schema.ResourceData, meta i

func resourceCloudflareMagicFirewallRulesetRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

ruleset, err := client.GetMagicFirewallRuleset(context.Background(), d.Id())
ruleset, err := client.GetMagicFirewallRuleset(context.Background(), accountID, d.Id())
if err != nil {
if strings.Contains(err.Error(), "could not find ruleset") {
log.Printf("[INFO] Magic Firewall Ruleset %s no longer exists", d.Id())
Expand All @@ -89,14 +88,14 @@ func resourceCloudflareMagicFirewallRulesetRead(d *schema.ResourceData, meta int

func resourceCloudflareMagicFirewallRulesetUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

rules, err := buildMagicFirewallRulesetRulesFromResource(d.Get("rules"))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error building ruleset from resource"))
}

_, err = client.UpdateMagicFirewallRuleset(context.Background(), d.Id(), d.Get("description").(string), rules)
_, err = client.UpdateMagicFirewallRuleset(context.Background(), accountID, d.Id(), d.Get("description").(string), rules)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error updating Magic Firewall ruleset with ID %q", d.Id()))
}
Expand All @@ -106,9 +105,9 @@ func resourceCloudflareMagicFirewallRulesetUpdate(d *schema.ResourceData, meta i

func resourceCloudflareMagicFirewallRulesetDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

err := client.DeleteMagicFirewallRuleset(context.Background(), d.Id())
err := client.DeleteMagicFirewallRuleset(context.Background(), accountID, d.Id())
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error deleting Magic Firewall ruleset with ID %q", d.Id()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func TestAccCloudflareMagicFirewallRulesetUpdateWithHigherPriority(t *testing.T)

func testAccCheckCloudflareMagicFirewallRulesetExists(n string, ruleset *cloudflare.MagicFirewallRuleset) resource.TestCheckFunc {
return func(s *terraform.State) error {
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("not found: %s", n)
Expand All @@ -211,7 +212,7 @@ func testAccCheckCloudflareMagicFirewallRulesetExists(n string, ruleset *cloudfl
}

client := testAccProvider.Meta().(*cloudflare.API)
foundRuleset, err := client.GetMagicFirewallRuleset(context.Background(), rs.Primary.ID)
foundRuleset, err := client.GetMagicFirewallRuleset(context.Background(), accountID, rs.Primary.ID)
if err != nil {
return err
}
Expand Down
18 changes: 8 additions & 10 deletions cloudflare/resource_cloudflare_static_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func resourceCloudflareStaticRoute() *schema.Resource {

func resourceCloudflareStaticRouteCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

newStaticRoute, err := client.CreateMagicTransitStaticRoute(context.Background(), staticRouteFromResource(d))
newStaticRoute, err := client.CreateMagicTransitStaticRoute(context.Background(), accountID, staticRouteFromResource(d))

if err != nil {
return errors.Wrap(err, fmt.Sprintf("error creating static route for prefix %s", d.Get("prefix").(string)))
Expand All @@ -40,7 +40,6 @@ func resourceCloudflareStaticRouteCreate(d *schema.ResourceData, meta interface{
}

func resourceCloudflareStaticRouteImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*cloudflare.API)
attributes := strings.SplitN(d.Id(), "/", 2)

if len(attributes) != 2 {
Expand All @@ -50,7 +49,6 @@ func resourceCloudflareStaticRouteImport(d *schema.ResourceData, meta interface{
accountID, routeID := attributes[0], attributes[1]
d.SetId(routeID)
d.Set("account_id", accountID)
client.AccountID = accountID

resourceCloudflareStaticRouteRead(d, meta)

Expand All @@ -59,9 +57,9 @@ func resourceCloudflareStaticRouteImport(d *schema.ResourceData, meta interface{

func resourceCloudflareStaticRouteRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

staticRoute, err := client.GetMagicTransitStaticRoute(context.Background(), d.Id())
staticRoute, err := client.GetMagicTransitStaticRoute(context.Background(), accountID, d.Id())
if err != nil {
if strings.Contains(err.Error(), "Route not found") {
log.Printf("[INFO] Static Route %s not found", d.Id())
Expand Down Expand Up @@ -93,9 +91,9 @@ func resourceCloudflareStaticRouteRead(d *schema.ResourceData, meta interface{})

func resourceCloudflareStaticRouteUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

_, err := client.UpdateMagicTransitStaticRoute(context.Background(), d.Id(), staticRouteFromResource(d))
_, err := client.UpdateMagicTransitStaticRoute(context.Background(), accountID, d.Id(), staticRouteFromResource(d))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("error updating static route with ID %q", d.Id()))
}
Expand All @@ -105,11 +103,11 @@ func resourceCloudflareStaticRouteUpdate(d *schema.ResourceData, meta interface{

func resourceCloudflareStaticRouteDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
client.AccountID = d.Get("account_id").(string)
accountID := d.Get("account_id").(string)

log.Printf("[INFO] Deleting Static Route: %s", d.Id())

_, err := client.DeleteMagicTransitStaticRoute(context.Background(), d.Id())
_, err := client.DeleteMagicTransitStaticRoute(context.Background(), accountID, d.Id())
if err != nil {
return fmt.Errorf("error deleting Static Route: %s", err)
}
Expand Down
9 changes: 5 additions & 4 deletions cloudflare/resource_cloudflare_static_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccCloudflareStaticRouteExists(t *testing.T) {
func TestAccCloudflareStaticRoute_Exists(t *testing.T) {
skipMagicTransitTestForNonConfiguredDefaultZone(t)

rnd := generateRandomResourceName()
Expand Down Expand Up @@ -44,6 +44,7 @@ func TestAccCloudflareStaticRouteExists(t *testing.T) {

func testAccCheckCloudflareStaticRouteExists(n string, route *cloudflare.MagicTransitStaticRoute) resource.TestCheckFunc {
return func(s *terraform.State) error {
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("not found: %s", n)
Expand All @@ -54,7 +55,7 @@ func testAccCheckCloudflareStaticRouteExists(n string, route *cloudflare.MagicTr
}

client := testAccProvider.Meta().(*cloudflare.API)
foundStaticRoute, err := client.GetMagicTransitStaticRoute(context.Background(), rs.Primary.ID)
foundStaticRoute, err := client.GetMagicTransitStaticRoute(context.Background(), accountID, rs.Primary.ID)
if err != nil {
return err
}
Expand All @@ -65,7 +66,7 @@ func testAccCheckCloudflareStaticRouteExists(n string, route *cloudflare.MagicTr
}
}

func TestAccCloudflareStaticRouteUpdateDescription(t *testing.T) {
func TestAccCloudflareStaticRoute_UpdateDescription(t *testing.T) {
skipMagicTransitTestForNonConfiguredDefaultZone(t)

rnd := generateRandomResourceName()
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestAccCloudflareStaticRouteUpdateDescription(t *testing.T) {
})
}

func TestAccCloudflareStaticRouteUpdateWeight(t *testing.T) {
func TestAccCloudflareStaticRoute_UpdateWeight(t *testing.T) {
skipMagicTransitTestForNonConfiguredDefaultZone(t)

rnd := generateRandomResourceName()
Expand Down