Skip to content

Commit

Permalink
Merge pull request #1861 from nickysemenza/nicky/fix-aop-switch-stmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Sep 1, 2022
2 parents 3d0674f + 868891b commit eaacdf1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/1861.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_authenticated_origin_pulls: fix improper handling of enabled=false
```
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,36 @@ func resourceCloudflareAuthenticatedOriginPullsCreate(ctx context.Context, d *sc
aopCert := d.Get("authenticated_origin_pulls_certificate").(string)

var checksum string
switch isEnabled, ok := d.GetOk("enabled"); ok {
isEnabled := false
if enabledVal, ok := d.GetOk("enabled"); ok {
// if enabled is not the zero val, use that
isEnabled = enabledVal.(bool)
}
switch {
case hostname != "" && aopCert != "":
// Per Hostname AOP
conf := []cloudflare.PerHostnameAuthenticatedOriginPullsConfig{{
CertID: aopCert,
Hostname: hostname,
Enabled: isEnabled.(bool),
Enabled: isEnabled,
}}
_, err := client.EditPerHostnameAuthenticatedOriginPullsConfig(ctx, zoneID, conf)
if err != nil {
return diag.FromErr(fmt.Errorf("error creating Per-Hostname Authenticated Origin Pulls resource on zone %q: %w", zoneID, err))
return diag.FromErr(fmt.Errorf("error creating Per-Hostname Authenticated Origin Pulls resource on zone %q for hostname %s: %w", zoneID, hostname, err))
}
checksum = stringChecksum(fmt.Sprintf("PerHostnameAOP/%s/%s/%s", zoneID, hostname, aopCert))

case aopCert != "":
// Per Zone AOP
_, err := client.SetPerZoneAuthenticatedOriginPullsStatus(ctx, zoneID, isEnabled.(bool))
_, err := client.SetPerZoneAuthenticatedOriginPullsStatus(ctx, zoneID, isEnabled)
if err != nil {
return diag.FromErr(fmt.Errorf("error creating Per-Zone Authenticated Origin Pulls resource on zone %q: %w", zoneID, err))
}
checksum = stringChecksum(fmt.Sprintf("PerZoneAOP/%s/%s", zoneID, aopCert))

default:
// Global AOP
_, err := client.SetAuthenticatedOriginPullsStatus(ctx, zoneID, isEnabled.(bool))
_, err := client.SetAuthenticatedOriginPullsStatus(ctx, zoneID, isEnabled)
if err != nil {
return diag.FromErr(fmt.Errorf("error creating Global Authenticated Origin Pulls resource on zone %q: %w", zoneID, err))
}
Expand Down

0 comments on commit eaacdf1

Please sign in to comment.