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_mutual_authentication): update activation after mtls creation #829

Merged
merged 13 commits into from
Apr 15, 2024
Merged
Changes from 1 commit
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
35 changes: 26 additions & 9 deletions fastly/resource_fastly_tls_mutual_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func resourceFastlyTLSMutualAuthentication() *schema.Resource {
"activation_id": {
Type: schema.TypeString,
Description: "The ID of your TLS Activation object",
Required: true,
Optional: true,
},
"cert_bundle": {
Type: schema.TypeString,
Expand Down Expand Up @@ -101,14 +101,16 @@ func resourceFastlyTLSMutualAuthenticationCreate(ctx context.Context, d *schema.

d.SetId(mTLS.ID)

inputUpdate := &gofastly.UpdateTLSActivationInput{
ID: d.Get("activation_id").(string),
MutualAuthentication: &gofastly.TLSMutualAuthentication{ID: mTLS.ID},
}
log.Printf("[DEBUG] CREATE: Update TLS Activation input: %#v", inputUpdate)
_, err = conn.UpdateTLSActivation(inputUpdate)
if err != nil {
return diag.FromErr(err)
if v, ok := d.GetOk("activation_id"); ok {
inputUpdate := &gofastly.UpdateTLSActivationInput{
ID: v.(string),
MutualAuthentication: &gofastly.TLSMutualAuthentication{ID: mTLS.ID},
}
log.Printf("[DEBUG] CREATE: Update TLS Activation input: %#v", inputUpdate)
_, err = conn.UpdateTLSActivation(inputUpdate)
if err != nil {
return diag.FromErr(err)
}
}

return resourceFastlyTLSMutualAuthenticationRead(ctx, d, meta)
Expand Down Expand Up @@ -218,6 +220,21 @@ func resourceFastlyTLSMutualAuthenticationUpdate(_ context.Context, d *schema.Re
func resourceFastlyTLSMutualAuthenticationDelete(_ context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
conn := meta.(*APIClient).conn

// IMPORTANT: You can't delete mTLS with active domains.
Integralist marked this conversation as resolved.
Show resolved Hide resolved
// You must first disable the active domains.
// To do that, you can set "" for the mTLS ID.
if d.Get("activation_id").(string) != "" {
input := &gofastly.UpdateTLSActivationInput{
ID: d.Get("activation_id").(string),
MutualAuthentication: &gofastly.TLSMutualAuthentication{ID: ""},
}
log.Printf("[DEBUG] DELETE: TLS Activation input: %#v", input)
_, err := conn.UpdateTLSActivation(input)
if err != nil {
return diag.FromErr(err)
}
}

input := &gofastly.DeleteTLSMutualAuthenticationInput{
ID: d.Id(),
}
Expand Down
Loading