Skip to content

Commit

Permalink
resource/access_group: pass group conditions via `TransformAccessGrou…
Browse files Browse the repository at this point in the history
…pForSchema`

Off the back of #917, this is another fix to ensure the state is able to be
compared against the remote API to correctly identify drift.

To be a good citizen, I've also swapped these `d.Set` calls to handle error
checking to prevent silent failures from slipping through.

Fixes #891
  • Loading branch information
jacobbednarz committed Jan 22, 2021
1 parent 69ccf5c commit 2f74712
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cloudflare/resource_cloudflare_access_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func resourceCloudflareAccessGroupRead(d *schema.ResourceData, meta interface{})
} else {
accessGroup, err = client.ZoneLevelAccessGroup(identifier.Value, d.Id())
}

if err != nil {
if strings.Contains(err.Error(), "HTTP status 404") {
log.Printf("[INFO] Access Group %s no longer exists", d.Id())
Expand All @@ -248,9 +249,18 @@ func resourceCloudflareAccessGroupRead(d *schema.ResourceData, meta interface{})
}

d.Set("name", accessGroup.Name)
d.Set("require", accessGroup.Require)
d.Set("exclude", accessGroup.Exclude)
d.Set("include", accessGroup.Include)

if err := d.Set("require", TransformAccessGroupForSchema(accessGroup.Require)); err != nil {
return fmt.Errorf("failed to set require attribute: %s", err)
}

if err := d.Set("exclude", TransformAccessGroupForSchema(accessGroup.Exclude)); err != nil {
return fmt.Errorf("failed to set exclude attribute: %s", err)
}

if err := d.Set("include", TransformAccessGroupForSchema(accessGroup.Include)); err != nil {
return fmt.Errorf("failed to set include attribute: %s", err)
}

return nil
}
Expand Down

0 comments on commit 2f74712

Please sign in to comment.