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)

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

// The configuration ID returned by the API is the initial TLS configuration when first
// activated. Instead, this value should represent the current TLS configuration id which
// can be found via the following API call.
// https://api.fastly.com/tls/domains?filter[tls_certificates.id]={cert-id}&include=tls_activations
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",
})
for _, tlsDomain := range tlsDomains {
// Activations may be empty (omitempty)
if tlsDomain.Activations == nil {
break
}
len := len(tlsDomain.Activations)
if len > 0 {
err = d.Set("configuration_id", tlsDomain.Activations[len-1].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 a1e4936

Please sign in to comment.