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

remove internal reliance on client.AccountID #2154

Merged
merged 1 commit into from
Jan 13, 2023
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
27 changes: 27 additions & 0 deletions .changelog/2154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```release-note:breaking-change
resource/cloudflare_workers_kv: no longer sets `client.AccountID` internally and relies on the resource provided value
```

```release-note:breaking-change
resource/cloudflare_load_balancer_monitor: no longer sets `client.AccountID` internally and relies on the resource provided value
```

```release-note:breaking-change
resource/cloudflare_workers_script: no longer sets `client.AccountID` internally and relies on the resource provided value
```

```release-note:breaking-change
resource/cloudflare_workers_kv_namespace: no longer sets `client.AccountID` internally and relies on the resource provided value
```

```release-note:breaking-change
resource/cloudflare_load_balancer_pool: no longer sets `client.AccountID` internally and relies on the resource provided value
```

```release-note:breaking-change
resource/cloudflare_zone: no longer sets `client.AccountID` internally and relies on the resource provided value
```

```release-note:breaking-change
resource/cloudflare_account_member: no longer sets `client.AccountID` internally and relies on the resource provided value
```
34 changes: 4 additions & 30 deletions internal/provider/resource_cloudflare_account_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ func resourceCloudflareAccountMember() *schema.Resource {

func resourceCloudflareAccountMemberRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*cloudflare.API)

var accountID string
if d.Get("account_id").(string) != "" {
accountID = d.Get("account_id").(string)
} else {
accountID = client.AccountID
}
accountID := d.Get("account_id").(string)

member, err := client.AccountMember(ctx, accountID, d.Id())
if err != nil {
Expand Down Expand Up @@ -65,16 +59,9 @@ func resourceCloudflareAccountMemberRead(ctx context.Context, d *schema.Resource

func resourceCloudflareAccountMemberDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*cloudflare.API)

accountID := d.Get("account_id").(string)
tflog.Debug(ctx, fmt.Sprintf("Deleting Cloudflare account member ID: %s", d.Id()))

var accountID string
if d.Get("account_id").(string) != "" {
accountID = d.Get("account_id").(string)
} else {
accountID = client.AccountID
}

err := client.DeleteAccountMember(ctx, accountID, d.Id())
if err != nil {
return diag.FromErr(fmt.Errorf("error deleting Cloudflare account member: %w", err))
Expand All @@ -86,21 +73,14 @@ func resourceCloudflareAccountMemberDelete(ctx context.Context, d *schema.Resour
func resourceCloudflareAccountMemberCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
memberEmailAddress := d.Get("email_address").(string)
requestedMemberRoles := d.Get("role_ids").(*schema.Set).List()

accountID := d.Get("account_id").(string)
client := meta.(*cloudflare.API)

var accountMemberRoleIDs []string
for _, roleID := range requestedMemberRoles {
accountMemberRoleIDs = append(accountMemberRoleIDs, roleID.(string))
}

var accountID string
if d.Get("account_id").(string) != "" {
accountID = d.Get("account_id").(string)
} else {
accountID = client.AccountID
}

status := d.Get("status").(string)
r, err := client.CreateAccountMemberWithStatus(ctx, accountID, memberEmailAddress, accountMemberRoleIDs, status)

Expand All @@ -121,13 +101,7 @@ func resourceCloudflareAccountMemberUpdate(ctx context.Context, d *schema.Resour
client := meta.(*cloudflare.API)
accountRoles := []cloudflare.AccountRole{}
memberRoles := d.Get("role_ids").(*schema.Set).List()

var accountID string
if d.Get("account_id").(string) != "" {
accountID = d.Get("account_id").(string)
} else {
accountID = client.AccountID
}
accountID := d.Get("account_id").(string)

for _, r := range memberRoles {
accountRole, _ := client.AccountRole(ctx, accountID, r.(string))
Expand Down
12 changes: 0 additions & 12 deletions internal/provider/resource_cloudflare_load_balancer_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ func resourceCloudflareLoadBalancerPoolMonitorCreate(ctx context.Context, d *sch
tflog.Debug(ctx, fmt.Sprintf("Creating Cloudflare Load Balancer Monitor from struct: %+v", loadBalancerMonitor))

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}
r, err := client.CreateLoadBalancerMonitor(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.CreateLoadBalancerMonitorParams{LoadBalancerMonitor: loadBalancerMonitor})
if err != nil {
return diag.FromErr(errors.Wrap(err, "error creating load balancer monitor"))
Expand Down Expand Up @@ -194,9 +191,6 @@ func resourceCloudflareLoadBalancerPoolMonitorUpdate(ctx context.Context, d *sch
tflog.Debug(ctx, fmt.Sprintf("Update Cloudflare Load Balancer Monitor from struct: %+v", loadBalancerMonitor))

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}
_, err := client.UpdateLoadBalancerMonitor(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.UpdateLoadBalancerMonitorParams{LoadBalancerMonitor: loadBalancerMonitor})
if err != nil {
return diag.FromErr(errors.Wrap(err, "error modifying load balancer monitor"))
Expand All @@ -221,9 +215,6 @@ func resourceCloudflareLoadBalancerPoolMonitorRead(ctx context.Context, d *schem
client := meta.(*cloudflare.API)

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}
loadBalancerMonitor, err := client.GetLoadBalancerMonitor(ctx, cloudflare.AccountIdentifier(accountID), d.Id())
if err != nil {
var notFoundError *cloudflare.NotFoundError
Expand Down Expand Up @@ -282,9 +273,6 @@ func resourceCloudflareLoadBalancerPoolMonitorDelete(ctx context.Context, d *sch
tflog.Info(ctx, fmt.Sprintf("Deleting Cloudflare Load Balancer Monitor: %s ", d.Id()))

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}
err := client.DeleteLoadBalancerMonitor(ctx, cloudflare.AccountIdentifier(accountID), d.Id())
if err != nil {
var notFoundError *cloudflare.NotFoundError
Expand Down
12 changes: 0 additions & 12 deletions internal/provider/resource_cloudflare_load_balancer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ func resourceCloudflareLoadBalancerPoolCreate(ctx context.Context, d *schema.Res
tflog.Debug(ctx, fmt.Sprintf("Creating Cloudflare Load Balancer Pool from struct: %+v", loadBalancerPool))

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

r, err := client.CreateLoadBalancerPool(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.CreateLoadBalancerPoolParams{LoadBalancerPool: loadBalancerPool})
if err != nil {
Expand Down Expand Up @@ -145,9 +142,6 @@ func resourceCloudflareLoadBalancerPoolUpdate(ctx context.Context, d *schema.Res
tflog.Debug(ctx, fmt.Sprintf("Updating Cloudflare Load Balancer Pool from struct: %+v", loadBalancerPool))

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}
_, err := client.UpdateLoadBalancerPool(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.UpdateLoadBalancerPoolParams{LoadBalancer: loadBalancerPool})
if err != nil {
return diag.FromErr(errors.Wrap(err, "error updating load balancer pool"))
Expand Down Expand Up @@ -230,9 +224,6 @@ func resourceCloudflareLoadBalancerPoolRead(ctx context.Context, d *schema.Resou
client := meta.(*cloudflare.API)

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

loadBalancerPool, err := client.GetLoadBalancerPool(ctx, cloudflare.AccountIdentifier(accountID), d.Id())
if err != nil {
Expand Down Expand Up @@ -328,9 +319,6 @@ func resourceCloudflareLoadBalancerPoolDelete(ctx context.Context, d *schema.Res
tflog.Info(ctx, fmt.Sprintf("Deleting Cloudflare Load Balancer Pool: %s ", d.Id()))

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}
err := client.DeleteLoadBalancerPool(ctx, cloudflare.AccountIdentifier(accountID), d.Id())
if err != nil {
return diag.FromErr(errors.Wrap(err, "error deleting Cloudflare Load Balancer Pool"))
Expand Down
9 changes: 0 additions & 9 deletions internal/provider/resource_cloudflare_workers_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ func resourceCloudflareWorkersKVRead(ctx context.Context, d *schema.ResourceData
}

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

value, err := client.GetWorkersKV(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.GetWorkersKVParams{
NamespaceID: namespaceID,
Expand All @@ -63,9 +60,6 @@ func resourceCloudflareWorkersKVUpdate(ctx context.Context, d *schema.ResourceDa
value := d.Get("value").(string)

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

_, err := client.WriteWorkersKVEntry(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.WriteWorkersKVEntryParams{
NamespaceID: namespaceID,
Expand All @@ -91,9 +85,6 @@ func resourceCloudflareWorkersKVDelete(ctx context.Context, d *schema.ResourceDa
}

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

tflog.Info(ctx, fmt.Sprintf("Deleting Cloudflare Workers KV with id: %+v", d.Id()))

Expand Down
12 changes: 0 additions & 12 deletions internal/provider/resource_cloudflare_workers_kv_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ func resourceCloudflareWorkersKVNamespaceCreate(ctx context.Context, d *schema.R
client := meta.(*cloudflare.API)

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

req := cloudflare.CreateWorkersKVNamespaceParams{
Title: d.Get("title").(string),
Expand Down Expand Up @@ -61,9 +58,6 @@ func resourceCloudflareWorkersKVNamespaceRead(ctx context.Context, d *schema.Res
namespaceID := d.Id()

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

resp, _, err := client.ListWorkersKVNamespaces(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.ListWorkersKVNamespacesParams{})
if err != nil {
Expand Down Expand Up @@ -92,9 +86,6 @@ func resourceCloudflareWorkersKVNamespaceUpdate(ctx context.Context, d *schema.R
client := meta.(*cloudflare.API)

accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

_, err := client.UpdateWorkersKVNamespace(ctx, cloudflare.AccountIdentifier(accountID), cloudflare.UpdateWorkersKVNamespaceParams{
NamespaceID: d.Id(),
Expand All @@ -110,9 +101,6 @@ func resourceCloudflareWorkersKVNamespaceUpdate(ctx context.Context, d *schema.R
func resourceCloudflareWorkersKVNamespaceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)
if accountID == "" {
accountID = client.AccountID
}

tflog.Info(ctx, fmt.Sprintf("Deleting Cloudflare Workers KV Namespace with id: %+v", d.Id()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func testAccCloudflareWorkersKVNamespaceDestroy(s *terraform.State) error {
}

accountID := rs.Primary.Attributes["account_id"]
if accountID == "" {
accountID = client.AccountID
}

resp, _, err := client.ListWorkersKVNamespaces(context.Background(), cloudflare.AccountIdentifier(accountID), cloudflare.ListWorkersKVNamespacesParams{})
if err == nil {
Expand Down Expand Up @@ -75,9 +72,7 @@ func testAccCheckCloudflareWorkersKVNamespaceExists(title string, namespace *clo
return fmt.Errorf("not found: %s", title)
}
accountID := rs.Primary.Attributes["account_id"]
if accountID == "" {
accountID = client.AccountID
}

resp, _, err := client.ListWorkersKVNamespaces(context.Background(), cloudflare.AccountIdentifier(accountID), cloudflare.ListWorkersKVNamespacesParams{})
if err != nil {
return err
Expand Down
3 changes: 0 additions & 3 deletions internal/provider/resource_cloudflare_workers_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ func testAccCloudflareWorkersKVDestroy(s *terraform.State) error {
key := rs.Primary.Attributes["key"]

accountID := rs.Primary.Attributes["account_id"]
if accountID == "" {
accountID = client.AccountID
}

_, err := client.GetWorkersKV(context.Background(), cloudflare.AccountIdentifier(accountID), cloudflare.GetWorkersKVParams{NamespaceID: namespaceID, Key: key})

Expand Down
16 changes: 0 additions & 16 deletions internal/provider/resource_cloudflare_workers_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ func resourceCloudflareWorkerScriptCreate(ctx context.Context, d *schema.Resourc
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)

if accountID == "" {
accountID = client.AccountID
}

scriptData, err := getScriptData(d, client)
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -170,10 +166,6 @@ func resourceCloudflareWorkerScriptRead(ctx context.Context, d *schema.ResourceD
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)

if accountID == "" {
accountID = client.AccountID
}

scriptData, err := getScriptData(d, client)
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -301,10 +293,6 @@ func resourceCloudflareWorkerScriptUpdate(ctx context.Context, d *schema.Resourc
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)

if accountID == "" {
accountID = client.AccountID
}

scriptData, err := getScriptData(d, client)
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -338,10 +326,6 @@ func resourceCloudflareWorkerScriptDelete(ctx context.Context, d *schema.Resourc
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)

if accountID == "" {
accountID = client.AccountID
}

scriptData, err := getScriptData(d, client)
if err != nil {
return diag.FromErr(err)
Expand Down
7 changes: 1 addition & 6 deletions internal/provider/resource_cloudflare_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ func resourceCloudflareZone() *schema.Resource {

func resourceCloudflareZoneCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*cloudflare.API)
var accountID string
if d.Get("account_id").(string) != "" {
accountID = d.Get("account_id").(string)
} else {
accountID = client.AccountID
}
accountID := d.Get("account_id").(string)
zoneName := d.Get("zone").(string)
jumpstart := d.Get("jump_start").(bool)
zoneType := d.Get("type").(string)
Expand Down