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

resource/cloudflare_access_rule: remove ability to create user level rules #2157

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2157.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
resource/cloudflare_access_rule: require explicit `zone_id` or `account_id` and remove implicit fallback to user level rules
```
4 changes: 2 additions & 2 deletions docs/resources/access_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ resource "cloudflare_access_rule" "office_network" {

### Optional

- `account_id` (String) The account identifier to target for the resource. **Modifying this attribute will force creation of a new resource.**
- `account_id` (String) The account identifier to target for the resource. Must provide only one of `account_id`, `zone_id`. **Modifying this attribute will force creation of a new resource.**
- `notes` (String) A personal note about the rule. Typically used as a reminder or explanation for the rule.
- `zone_id` (String) The zone identifier to target for the resource. **Modifying this attribute will force creation of a new resource.**
- `zone_id` (String) The zone identifier to target for the resource. Must provide only one of `account_id`, `zone_id`. **Modifying this attribute will force creation of a new resource.**

### Read-Only

Expand Down
16 changes: 4 additions & 12 deletions internal/provider/resource_cloudflare_access_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ func resourceCloudflareAccessRuleCreate(ctx context.Context, d *schema.ResourceD

if accountID != "" {
r, err = client.CreateAccountAccessRule(ctx, accountID, newRule)
} else if zoneID != "" {
r, err = client.CreateZoneAccessRule(ctx, zoneID, newRule)
} else {
r, err = client.CreateUserAccessRule(ctx, newRule)
r, err = client.CreateZoneAccessRule(ctx, zoneID, newRule)
}

if err != nil {
Expand All @@ -95,10 +93,8 @@ func resourceCloudflareAccessRuleRead(ctx context.Context, d *schema.ResourceDat

if accountID != "" {
accessRuleResponse, err = client.AccountAccessRule(ctx, accountID, d.Id())
} else if zoneID != "" {
accessRuleResponse, err = client.ZoneAccessRule(ctx, zoneID, d.Id())
} else {
accessRuleResponse, err = client.UserAccessRule(ctx, d.Id())
accessRuleResponse, err = client.ZoneAccessRule(ctx, zoneID, d.Id())
}

tflog.Debug(ctx, fmt.Sprintf("accessRuleResponse: %#v", accessRuleResponse))
Expand Down Expand Up @@ -155,10 +151,8 @@ func resourceCloudflareAccessRuleUpdate(ctx context.Context, d *schema.ResourceD

if accountID != "" {
_, err = client.UpdateAccountAccessRule(ctx, accountID, d.Id(), updatedRule)
} else if zoneID != "" {
_, err = client.UpdateZoneAccessRule(ctx, zoneID, d.Id(), updatedRule)
} else {
_, err = client.UpdateUserAccessRule(ctx, d.Id(), updatedRule)
_, err = client.UpdateZoneAccessRule(ctx, zoneID, d.Id(), updatedRule)
}

if err != nil {
Expand All @@ -179,10 +173,8 @@ func resourceCloudflareAccessRuleDelete(ctx context.Context, d *schema.ResourceD

if accountID != "" {
_, err = client.DeleteAccountAccessRule(ctx, accountID, d.Id())
} else if zoneID != "" {
_, err = client.DeleteZoneAccessRule(ctx, zoneID, d.Id())
} else {
_, err = client.DeleteUserAccessRule(ctx, d.Id())
_, err = client.DeleteZoneAccessRule(ctx, zoneID, d.Id())
}

if err != nil {
Expand Down
22 changes: 12 additions & 10 deletions internal/provider/schema_cloudflare_access_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import (
func resourceCloudflareAccessRuleSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"account_id": {
Description: "The account identifier to target for the resource.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: "The account identifier to target for the resource.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ExactlyOneOf: []string{"account_id", "zone_id"},
},
"zone_id": {
Description: "The zone identifier to target for the resource.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: "The zone identifier to target for the resource.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ExactlyOneOf: []string{"account_id", "zone_id"},
},
"mode": {
Type: schema.TypeString,
Expand Down