Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tls_subscription): ensure configuration_id is current value (not initial) #824

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Integralist marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading