Skip to content

Commit

Permalink
SM fixes (IBM-Cloud#5045)
Browse files Browse the repository at this point in the history
* SC addition

* SC addition

* SC addition

* update function updated

* SC unit tests added

* SC unit tests added

* d

* tests fixes

* tests fixes

* update sdk

* .secrets.baseline update

* .secrets.baseline update

* .secrets.baseline update

* Update sm_service_credentials_secret_metadata.html.markdown

* bugs fixes

* bugs fixes

* bugs fixes

* docs bugs fixes

* preferred_chain added for public cert lets encrypt configuration

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

---------

Co-authored-by: Yonathan-Yellin <[email protected]>
Co-authored-by: Avi Ribchinsky <[email protected]>
Co-authored-by: Tatyana <[email protected]>
Co-authored-by: Idan Adar <[email protected]>
  • Loading branch information
5 people authored Jan 21, 2024
1 parent d03d3a9 commit 22e47a6
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 38 deletions.
44 changes: 22 additions & 22 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "go.mod|go.sum|.*.map|^.secrets.baseline$",
"lines": null
},
"generated_at": "2024-01-17T17:15:00Z",
"generated_at": "2024-01-17T13:22:37Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -760,23 +760,23 @@
"hashed_secret": "731438016c5ab94431f61820f35e3ae5f8ad6004",
"is_secret": false,
"is_verified": false,
"line_number": 434,
"line_number": 432,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "12da2e35d6b50c902c014f1ab9e3032650368df7",
"is_secret": false,
"is_verified": false,
"line_number": 440,
"line_number": 438,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "813274ccae5b6b509379ab56982d862f7b5969b6",
"is_secret": false,
"is_verified": false,
"line_number": 1175,
"line_number": 1161,
"type": "Base64 High Entropy String",
"verified_result": null
}
Expand Down Expand Up @@ -2964,7 +2964,7 @@
"hashed_secret": "92f08f2d9a0dc3f0d4cb3796435a48508cf59ecd",
"is_secret": false,
"is_verified": false,
"line_number": 1107,
"line_number": 1115,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -2992,7 +2992,7 @@
"hashed_secret": "92f08f2d9a0dc3f0d4cb3796435a48508cf59ecd",
"is_secret": false,
"is_verified": false,
"line_number": 509,
"line_number": 513,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3526,23 +3526,23 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 198,
"line_number": 197,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "108b310facc1a193833fc2971fd83081f775ea0c",
"is_secret": false,
"is_verified": false,
"line_number": 389,
"line_number": 388,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 392,
"line_number": 391,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -3562,23 +3562,23 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 109,
"line_number": 108,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 430,
"line_number": 429,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "9beb31de125498074813c6f31c0e4df3e54a5489",
"is_secret": false,
"is_verified": false,
"line_number": 646,
"line_number": 645,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3606,15 +3606,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 297,
"line_number": 296,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 538,
"line_number": 537,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3660,15 +3660,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 397,
"line_number": 396,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 637,
"line_number": 636,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -3688,15 +3688,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 39,
"line_number": 44,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 144,
"line_number": 152,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -3788,15 +3788,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 190,
"line_number": 189,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 443,
"line_number": 442,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -3806,15 +3806,15 @@
"hashed_secret": "3046d9f6cfaaeea6eed9bb7a4ab010fe49b0cfd4",
"is_secret": false,
"is_verified": false,
"line_number": 124,
"line_number": 123,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "b732fb611fd46a38e8667f9972e0cde777fbe37f",
"is_secret": false,
"is_verified": false,
"line_number": 356,
"line_number": 354,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func ResourceIbmSmArbitrarySecret() *schema.Resource {
"version_custom_metadata": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "The secret version metadata that a user can customize.",
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -422,7 +421,7 @@ func resourceIbmSmArbitrarySecretUpdate(context context.Context, d *schema.Resou
// Apply change to version_custom_metadata in current version
secretVersionMetadataPatchModel := new(secretsmanagerv2.SecretVersionMetadataPatch)
secretVersionMetadataPatchModel.VersionCustomMetadata = d.Get("version_custom_metadata").(map[string]interface{})
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataPatchModel.AsPatch()
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataAsPatchFunction(secretVersionMetadataPatchModel)

updateSecretVersionOptions := &secretsmanagerv2.UpdateSecretVersionMetadataOptions{}
updateSecretVersionOptions.SetSecretID(secretId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func ResourceIbmSmIamCredentialsSecret() *schema.Resource {
"version_custom_metadata": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: "The secret version metadata that a user can customize.",
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -408,6 +407,24 @@ func resourceIbmSmIamCredentialsSecretRead(context context.Context, d *schema.Re
return diag.FromErr(fmt.Errorf("Error setting signing_algorithm: %s", err))
}

// Call get version metadata API to get the current version_custom_metadata
getVersionMetdataOptions := &secretsmanagerv2.GetSecretVersionMetadataOptions{}
getVersionMetdataOptions.SetSecretID(secretId)
getVersionMetdataOptions.SetID("current")

versionMetadataIntf, response, err := secretsManagerClient.GetSecretVersionMetadataWithContext(context, getVersionMetdataOptions)
if err != nil {
log.Printf("[DEBUG] GetSecretVersionMetadataWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetSecretVersionMetadataWithContext failed %s\n%s", err, response))
}

versionMetadata := versionMetadataIntf.(*secretsmanagerv2.IAMCredentialsSecretVersionMetadata)
if versionMetadata.VersionCustomMetadata != nil {
if err = d.Set("version_custom_metadata", versionMetadata.VersionCustomMetadata); err != nil {
return diag.FromErr(fmt.Errorf("Error setting version_custom_metadata: %s", err))
}
}

return nil
}

Expand Down Expand Up @@ -475,6 +492,27 @@ func resourceIbmSmIamCredentialsSecretUpdate(context context.Context, d *schema.
}
}

if d.HasChange("version_custom_metadata") {
// Apply change to version_custom_metadata in current version
secretVersionMetadataPatchModel := new(secretsmanagerv2.SecretVersionMetadataPatch)
secretVersionMetadataPatchModel.VersionCustomMetadata = d.Get("version_custom_metadata").(map[string]interface{})
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataAsPatchFunction(secretVersionMetadataPatchModel)

updateSecretVersionOptions := &secretsmanagerv2.UpdateSecretVersionMetadataOptions{}
updateSecretVersionOptions.SetSecretID(secretId)
updateSecretVersionOptions.SetID("current")
updateSecretVersionOptions.SetSecretVersionMetadataPatch(secretVersionMetadataPatchModelAsPatch)
_, response, err := secretsManagerClient.UpdateSecretVersionMetadataWithContext(context, updateSecretVersionOptions)
if err != nil {
if hasChange {
// Call the read function to update the Terraform state with the change already applied to the metadata
resourceIbmSmIamCredentialsSecretRead(context, d, meta)
}
log.Printf("[DEBUG] UpdateSecretVersionMetadataWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("UpdateSecretVersionMetadataWithContext failed %s\n%s", err, response))
}
}

return resourceIbmSmIamCredentialsSecretRead(context, d, meta)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func ResourceIbmSmImportedCertificate() *schema.Resource {
"version_custom_metadata": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "The secret version metadata that a user can customize.",
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -537,7 +536,7 @@ func resourceIbmSmImportedCertificateUpdate(context context.Context, d *schema.R
// Apply change to version_custom_metadata in current version
secretVersionMetadataPatchModel := new(secretsmanagerv2.SecretVersionMetadataPatch)
secretVersionMetadataPatchModel.VersionCustomMetadata = d.Get("version_custom_metadata").(map[string]interface{})
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataPatchModel.AsPatch()
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataAsPatchFunction(secretVersionMetadataPatchModel)

updateSecretVersionOptions := &secretsmanagerv2.UpdateSecretVersionMetadataOptions{}
updateSecretVersionOptions.SetSecretID(secretId)
Expand Down
3 changes: 1 addition & 2 deletions ibm/service/secretsmanager/resource_ibm_sm_kv_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func ResourceIbmSmKvSecret() *schema.Resource {
"version_custom_metadata": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "The secret version metadata that a user can customize.",
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -396,7 +395,7 @@ func resourceIbmSmKvSecretUpdate(context context.Context, d *schema.ResourceData
// Apply change to version_custom_metadata in current version
secretVersionMetadataPatchModel := new(secretsmanagerv2.SecretVersionMetadataPatch)
secretVersionMetadataPatchModel.VersionCustomMetadata = d.Get("version_custom_metadata").(map[string]interface{})
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataPatchModel.AsPatch()
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataAsPatchFunction(secretVersionMetadataPatchModel)

updateSecretVersionOptions := &secretsmanagerv2.UpdateSecretVersionMetadataOptions{}
updateSecretVersionOptions.SetSecretID(secretId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func ResourceIbmSmPrivateCertificate() *schema.Resource {
},
"version_custom_metadata": &schema.Schema{
Type: schema.TypeMap,
ForceNew: true,
Optional: true,
Description: "The secret version metadata that a user can customize.",
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -545,6 +544,24 @@ func resourceIbmSmPrivateCertificateRead(context context.Context, d *schema.Reso
return diag.FromErr(fmt.Errorf("Error setting ca_chain: %s", err))
}
}

// Call get version metadata API to get the current version_custom_metadata
getVersionMetdataOptions := &secretsmanagerv2.GetSecretVersionMetadataOptions{}
getVersionMetdataOptions.SetSecretID(secretId)
getVersionMetdataOptions.SetID("current")

versionMetadataIntf, response, err := secretsManagerClient.GetSecretVersionMetadataWithContext(context, getVersionMetdataOptions)
if err != nil {
log.Printf("[DEBUG] GetSecretVersionMetadataWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetSecretVersionMetadataWithContext failed %s\n%s", err, response))
}

versionMetadata := versionMetadataIntf.(*secretsmanagerv2.PrivateCertificateVersionMetadata)
if versionMetadata.VersionCustomMetadata != nil {
if err = d.Set("version_custom_metadata", versionMetadata.VersionCustomMetadata); err != nil {
return diag.FromErr(fmt.Errorf("Error setting version_custom_metadata: %s", err))
}
}
return nil
}

Expand Down Expand Up @@ -608,6 +625,27 @@ func resourceIbmSmPrivateCertificateUpdate(context context.Context, d *schema.Re
}
}

if d.HasChange("version_custom_metadata") {
// Apply change to version_custom_metadata in current version
secretVersionMetadataPatchModel := new(secretsmanagerv2.SecretVersionMetadataPatch)
secretVersionMetadataPatchModel.VersionCustomMetadata = d.Get("version_custom_metadata").(map[string]interface{})
secretVersionMetadataPatchModelAsPatch, _ := secretVersionMetadataAsPatchFunction(secretVersionMetadataPatchModel)

updateSecretVersionOptions := &secretsmanagerv2.UpdateSecretVersionMetadataOptions{}
updateSecretVersionOptions.SetSecretID(secretId)
updateSecretVersionOptions.SetID("current")
updateSecretVersionOptions.SetSecretVersionMetadataPatch(secretVersionMetadataPatchModelAsPatch)
_, response, err := secretsManagerClient.UpdateSecretVersionMetadataWithContext(context, updateSecretVersionOptions)
if err != nil {
if hasChange {
// Call the read function to update the Terraform state with the change already applied to the metadata
resourceIbmSmPrivateCertificateRead(context, d, meta)
}
log.Printf("[DEBUG] UpdateSecretVersionMetadataWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("UpdateSecretVersionMetadataWithContext failed %s\n%s", err, response))
}
}

return resourceIbmSmPrivateCertificateRead(context, d, meta)
}

Expand Down
Loading

0 comments on commit 22e47a6

Please sign in to comment.