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

Synchronize transaction operations in cert_key resource #982

Merged
merged 1 commit into from
Jun 5, 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
41 changes: 23 additions & 18 deletions bigip/resource_bigip_ssl_key_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ func resourceBigipSSLKeyCertCreate(ctx context.Context, d *schema.ResourceData,
Passphrase: passphrase,
}

t, err := client.StartTransaction()
if err != nil {
return diag.FromErr(fmt.Errorf("error while starting transaction: %v", err))
}
err = client.AddKey(&keyCfg)
if err != nil {
return diag.FromErr(fmt.Errorf("error while adding the ssl key: %v", err))
}

cert := &bigip.Certificate{
Name: certName,
Partition: partition,
Expand All @@ -132,6 +123,16 @@ func resourceBigipSSLKeyCertCreate(ctx context.Context, d *schema.ResourceData,
cert.IssuerCert = val.(string)
}

mutex.Lock()
t, err := client.StartTransaction()
if err != nil {
return diag.FromErr(fmt.Errorf("error while starting transaction: %v", err))
}
err = client.AddKey(&keyCfg)
if err != nil {
return diag.FromErr(fmt.Errorf("error while adding the ssl key: %v", err))
}

err = client.UploadCertificate(certPath, cert)
if err != nil {
return diag.FromErr(fmt.Errorf("error while uploading the ssl cert: %v", err))
Expand All @@ -140,6 +141,7 @@ func resourceBigipSSLKeyCertCreate(ctx context.Context, d *schema.ResourceData,
if err != nil {
return diag.FromErr(fmt.Errorf("error while ending transaction: %d", err))
}
mutex.Unlock()

if val, ok := d.GetOk("cert_ocsp"); ok {
certValidState := &bigip.CertValidatorState{Name: val.(string)}
Expand Down Expand Up @@ -218,15 +220,6 @@ func resourceBigipSSLKeyCertUpdate(ctx context.Context, d *schema.ResourceData,

keyFullPath := fmt.Sprintf("/%s/%s", partition, keyName)

t, err := client.StartTransaction()
if err != nil {
return diag.FromErr(fmt.Errorf("error while trying to start transaction: %s", err))
}
err = client.ModifyKey(keyFullPath, &keyCfg)
if err != nil {
return diag.FromErr(fmt.Errorf("error while trying to modify the ssl key (%s): %s", keyFullPath, err))
}

cert := &bigip.Certificate{
Name: certName,
Partition: partition,
Expand All @@ -237,6 +230,17 @@ func resourceBigipSSLKeyCertUpdate(ctx context.Context, d *schema.ResourceData,
if val, ok := d.GetOk("issuer_cert"); ok {
cert.IssuerCert = val.(string)
}

mutex.Lock()
t, err := client.StartTransaction()
if err != nil {
return diag.FromErr(fmt.Errorf("error while trying to start transaction: %s", err))
}
err = client.ModifyKey(keyFullPath, &keyCfg)
if err != nil {
return diag.FromErr(fmt.Errorf("error while trying to modify the ssl key (%s): %s", keyFullPath, err))
}

if val, ok := d.GetOk("cert_ocsp"); ok {
certValidState := &bigip.CertValidatorState{Name: val.(string)}
certValidRef := &bigip.CertValidatorReference{}
Expand All @@ -252,6 +256,7 @@ func resourceBigipSSLKeyCertUpdate(ctx context.Context, d *schema.ResourceData,
if err != nil {
return diag.FromErr(fmt.Errorf("error while trying to end transaction: %s", err))
}
mutex.Unlock()

return resourceBigipSSLKeyCertRead(ctx, d, meta)
}
Expand Down