Skip to content

Commit

Permalink
fix(tls_subscription): ensure configuration_id is current value (not …
Browse files Browse the repository at this point in the history
…initial) (#824)

Fixes: #787
  • Loading branch information
virgofx committed Apr 9, 2024
1 parent af30139 commit 0e020c2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions fastly/resource_fastly_tls_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,37 @@ func resourceFastlyTLSSubscriptionRead(_ context.Context, d *schema.ResourceData
if err != nil {
return diag.FromErr(err)
}

// NOTE: The configuration_id should change depending on scenario.
// For example, prior to a subscription renewal the ID is the same.
// Once a subscription is renewed, we need to search for the latest ID.
// The following API endpoint is used to search for the latest ID.
// https://www.fastly.com/documentation/reference/api/tls/custom-certs/domains/#list-tls-domains
err = d.Set("configuration_id", subscription.Configuration.ID)
if err != nil {
return diag.FromErr(err)
}
var tlsDomains []*gofastly.TLSDomain
tlsDomains, err = conn.ListTLSDomains(&gofastly.ListTLSDomainsInput{
FilterTLSCertificateID: certificateID,
Include: "tls_activations",
Sort: "tls_activations.created_at",
})
for _, tlsDomain := range tlsDomains {
// Activations may be empty (omitempty)
if tlsDomain.Activations == nil {
break
}
activations := len(tlsDomain.Activations)
if activations > 0 {
err = d.Set("configuration_id", tlsDomain.Activations[0].Configuration.ID)
if err != nil {
return diag.FromErr(err)
}
break
}
}

err = d.Set("created_at", subscription.CreatedAt.Format(time.RFC3339))
if err != nil {
return diag.FromErr(err)
Expand Down

0 comments on commit 0e020c2

Please sign in to comment.