Skip to content

Commit

Permalink
Synchronize transaction operations in cert_key resource
Browse files Browse the repository at this point in the history
  • Loading branch information
urohit011 committed May 17, 2024
1 parent 747566e commit 4afc0b0
Showing 1 changed file with 23 additions and 18 deletions.
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

0 comments on commit 4afc0b0

Please sign in to comment.