Skip to content

Commit 2a9cb0e

Browse files
wsiewhkantare
authored andcommitted
resilence 409 and update docs to include force_delete flag and force_delete=true in examples
1 parent dbf1256 commit 2a9cb0e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ibm/service/kms/resource_ibm_kms_key_rings.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ func resourceIBMKmsKeyRingDelete(d *schema.ResourceData, meta interface{}) error
153153
err = kpAPI.DeleteKeyRing(context.Background(), id[0], kp.WithForce(force_delete))
154154
if err != nil {
155155
kpError := err.(*kp.Error)
156-
if kpError.StatusCode == 404 {
156+
// Key ring deletion used to occur by silencing the 409 failed deletion and allowing instance deletion to clean it up
157+
// Will be deprecated in the future in favor of force_delete flag
158+
if kpError.StatusCode == 404 || kpError.StatusCode == 409 {
157159
return nil
158160
} else {
159161
return fmt.Errorf(" failed to Destroy key ring with error: %s", err)

website/docs/r/kms_key_rings.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ resource "ibm_resource_instance" "kms_instance" {
2323
resource "ibm_kms_key_rings" "key_ring" {
2424
instance_id = ibm_resource_instance.kms_instance.guid
2525
key_ring_id = "key-ring-id"
26+
force_delete = true
2627
}
2728
resource "ibm_kms_key" "key" {
2829
instance_id = ibm_resource_instance.kp_instance.guid
@@ -35,7 +36,7 @@ resource "ibm_kms_key" "key" {
3536

3637
Sample example of deleting a key ring where all keys inside have key state equals to 5 (destroyed). Keys are moved to the default key ring.
3738

38-
```
39+
```terraform
3940
resource "ibm_kms_key_rings" "key_ring" {
4041
instance_id = ibm_resource_instance.kms_instance.guid
4142
key_ring_id = "key-ring-id"
@@ -49,6 +50,7 @@ Review the argument references that you can specify for your resource.
4950
- `endpoint_type` - (Optional, Forces new resource, String) The type of the public endpoint, or private endpoint to be used for creating keys.
5051
- `instance_id` - (Required, Forces new resource, String) The hs-crypto or key protect instance GUID.
5152
- `key_ring_id` - (Required, Forces new resource, String) The ID that identifies the key ring. Each ID is unique within the given instance and is not reserved across the key protect service. **Constraints** `2 ≤ length ≤ 100`. Value must match regular expression of `^[a-zA-Z0-9-]*$`.
53+
- `force_delete` - (Optional, Bool) If set to **true**, allows force deletion of a key ring. Terraform users are recommended to have this set to **true**. All keys in the key ring are required to be deleted (in state **5**) before this action can be performed. If the key ring to be deleted contains keys, they will be moved to the **default** key ring which requires the **kms.secrets.patch** IAM action.
5254

5355
## Attribute reference
5456
In addition to all argument reference list, you can access the following attribute reference after your resource is created.

0 commit comments

Comments
 (0)