Skip to content

Commit

Permalink
Merge pull request #668 from jacobbednarz/dont-treat-an-id-as-name
Browse files Browse the repository at this point in the history
resource/cloudflare_zone: No need to translate the ID to Name back to ID
  • Loading branch information
jacobbednarz authored Apr 29, 2020
2 parents 6e3af44 + 885ae0b commit c36c1dd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cloudflare/resource_cloudflare_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,21 @@ func resourceCloudflareZoneUpdate(d *schema.ResourceData, meta interface{}) erro
}

// In the cases where the zone isn't completely setup yet, we need to
// check the `status` field and should it be pending, use the `Name`
// check the `status` field and should it be pending, use the `LegacyID`
// from `zone.PlanPending` instead to account for paid plans.
if zone.Status == "pending" && zone.PlanPending.Name != "" {
d.Set("plan", zone.PlanPending.Name)
d.Set("plan", zone.PlanPending.LegacyID)
}

if plan, ok := d.GetOk("plan"); ok {
planName := planIDForName(plan.(string))
if err := setRatePlan(client, zoneID, planName, false); err != nil {
if change := d.HasChange("plan"); change {
// If we're upgrading from a free plan, we need to use POST (not PUT) as the
// the subscription needs to be created, not modified despite the resource
// already existing.
existingPlan, newPlan := d.GetChange("plan")
wasFreePlan := existingPlan.(string) == "free"
planID := newPlan.(string)

if err := setRatePlan(client, zoneID, planID, wasFreePlan); err != nil {
return err
}
}
Expand Down

0 comments on commit c36c1dd

Please sign in to comment.