Skip to content

Commit c5558b3

Browse files
Atul Adityaravinitp
authored andcommitted
Added - Support for KMS key Rotation for Block/Boot Volume Backups
1 parent 94226cc commit c5558b3

File tree

7 files changed

+55
-9
lines changed

7 files changed

+55
-9
lines changed

examples/storage/block/volume_backup/volume_backup.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ variable "volume_backup_type" {
5757
default = "FULL"
5858
}
5959

60+
variable "kms_key_ocid" {
61+
62+
}
63+
6064
provider "oci" {
6165
tenancy_ocid = var.tenancy_ocid
6266
user_ocid = var.user_ocid
@@ -81,6 +85,17 @@ resource "oci_core_volume_backup" "test_volume_backup" {
8185
type = var.volume_backup_type
8286
}
8387

88+
resource "oci_core_volume_backup" "test_volume_backup_kms_key_id" {
89+
#Required
90+
volume_id = oci_core_volume.test_volume.id
91+
92+
#Optional
93+
display_name = var.volume_backup_display_name
94+
freeform_tags = var.volume_backup_freeform_tags
95+
type = var.volume_backup_type
96+
kms_key_id = var.kms_key_ocid
97+
}
98+
8499
resource "oci_core_volume_backup" "test_volume_backup_cross_region_sourced" {
85100
#Required
86101
source_details {

internal/integrationtest/core_boot_volume_backup_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
5454
"type": acctest.Representation{RepType: acctest.Optional, Create: `INCREMENTAL`},
5555
}
56+
5657
bootVolumeBackupId, bootVolumeId, instanceId string
5758
CoreBootVolumeBackupResourceDependencies = BootVolumeOptionalResource
5859
)
@@ -118,6 +119,7 @@ func TestCoreBootVolumeBackupResource_basic(t *testing.T) {
118119
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
119120
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
120121
resource.TestCheckResourceAttrSet(resourceName, "id"),
122+
resource.TestCheckResourceAttrSet(resourceName, "kms_key_id"),
121123
resource.TestCheckResourceAttrSet(resourceName, "state"),
122124
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
123125
resource.TestCheckResourceAttr(resourceName, "type", "INCREMENTAL"),
@@ -147,6 +149,7 @@ func TestCoreBootVolumeBackupResource_basic(t *testing.T) {
147149
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
148150
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
149151
resource.TestCheckResourceAttrSet(resourceName, "id"),
152+
resource.TestCheckResourceAttrSet(resourceName, "kms_key_id"),
150153
resource.TestCheckResourceAttrSet(resourceName, "state"),
151154
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
152155
resource.TestCheckResourceAttr(resourceName, "type", "INCREMENTAL"),
@@ -202,7 +205,6 @@ func TestCoreBootVolumeBackupResource_basic(t *testing.T) {
202205
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
203206
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
204207
resource.TestCheckResourceAttrSet(singularDatasourceName, "image_id"),
205-
resource.TestCheckResourceAttrSet(singularDatasourceName, "kms_key_id"),
206208
resource.TestCheckResourceAttrSet(singularDatasourceName, "size_in_gbs"),
207209
resource.TestCheckResourceAttrSet(singularDatasourceName, "source_type"),
208210
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),

internal/integrationtest/core_volume_backup_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var (
5656
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
5757
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
5858
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
59+
"kms_key_id": acctest.Representation{RepType: acctest.Optional, Create: `${lookup(data.oci_kms_keys.test_keys_dependency.keys[0], "id")}`},
5960
"type": acctest.Representation{RepType: acctest.Optional, Create: `FULL`},
6061
}
6162
CoreVolumeBackupWithSourceDetailsRepresentation = map[string]interface{}{
@@ -124,6 +125,7 @@ func TestCoreVolumeBackupResource_basic(t *testing.T) {
124125
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
125126
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
126127
resource.TestCheckResourceAttrSet(resourceName, "id"),
128+
resource.TestCheckResourceAttrSet(resourceName, "kms_key_id"),
127129
resource.TestCheckResourceAttrSet(resourceName, "state"),
128130
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
129131
resource.TestCheckResourceAttr(resourceName, "type", "FULL"),
@@ -153,6 +155,7 @@ func TestCoreVolumeBackupResource_basic(t *testing.T) {
153155
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
154156
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
155157
resource.TestCheckResourceAttrSet(resourceName, "id"),
158+
resource.TestCheckResourceAttrSet(resourceName, "kms_key_id"),
156159
resource.TestCheckResourceAttrSet(resourceName, "state"),
157160
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
158161
resource.TestCheckResourceAttr(resourceName, "type", "FULL"),

internal/service/core/core_boot_volume_backup_resource.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ func CoreBootVolumeBackupResource() *schema.Resource {
9292
Computed: true,
9393
Elem: schema.TypeString,
9494
},
95+
"kms_key_id": {
96+
Type: schema.TypeString,
97+
Optional: true,
98+
Computed: true,
99+
},
95100
"type": {
96101
Type: schema.TypeString,
97102
Optional: true,
@@ -108,10 +113,6 @@ func CoreBootVolumeBackupResource() *schema.Resource {
108113
Type: schema.TypeString,
109114
Computed: true,
110115
},
111-
"kms_key_id": {
112-
Type: schema.TypeString,
113-
Computed: true,
114-
},
115116
"size_in_gbs": {
116117
Type: schema.TypeString,
117118
Computed: true,
@@ -299,6 +300,11 @@ func (s *CoreBootVolumeBackupResourceCrud) createBootVolumeBackup() error {
299300
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
300301
}
301302

303+
if kmsKeyId, ok := s.D.GetOkExists("kms_key_id"); ok {
304+
tmp := kmsKeyId.(string)
305+
request.KmsKeyId = &tmp
306+
}
307+
302308
if type_, ok := s.D.GetOkExists("type"); ok {
303309
request.Type = oci_core.CreateBootVolumeBackupDetailsTypeEnum(type_.(string))
304310
}
@@ -435,6 +441,11 @@ func (s *CoreBootVolumeBackupResourceCrud) Update() error {
435441
return nil
436442
}
437443

444+
if kmsKeyId, ok := s.D.GetOkExists("kms_key_id"); ok {
445+
tmp := kmsKeyId.(string)
446+
request.KmsKeyId = &tmp
447+
}
448+
438449
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "core")
439450

440451
response, err := s.Client.UpdateBootVolumeBackup(context.Background(), request)

internal/service/core/core_volume_backup_resource.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ func CoreVolumeBackupResource() *schema.Resource {
9191
Computed: true,
9292
Elem: schema.TypeString,
9393
},
94+
"kms_key_id": {
95+
Type: schema.TypeString,
96+
Optional: true,
97+
Computed: true,
98+
},
9499
"type": {
95100
Type: schema.TypeString,
96101
Optional: true,
@@ -103,10 +108,6 @@ func CoreVolumeBackupResource() *schema.Resource {
103108
Type: schema.TypeString,
104109
Computed: true,
105110
},
106-
"kms_key_id": {
107-
Type: schema.TypeString,
108-
Computed: true,
109-
},
110111
"size_in_gbs": {
111112
Type: schema.TypeString,
112113
Computed: true,
@@ -357,6 +358,11 @@ func (s *CoreVolumeBackupResourceCrud) CreateVolumeBackup() error {
357358
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
358359
}
359360

361+
if kmsKeyId, ok := s.D.GetOkExists("kms_key_id"); ok {
362+
tmp := kmsKeyId.(string)
363+
request.KmsKeyId = &tmp
364+
}
365+
360366
if type_, ok := s.D.GetOkExists("type"); ok {
361367
request.Type = oci_core.CreateVolumeBackupDetailsTypeEnum(type_.(string))
362368
}
@@ -423,6 +429,11 @@ func (s *CoreVolumeBackupResourceCrud) Update() error {
423429
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
424430
}
425431

432+
if kmsKeyId, ok := s.D.GetOkExists("kms_key_id"); ok {
433+
tmp := kmsKeyId.(string)
434+
request.KmsKeyId = &tmp
435+
}
436+
426437
tmp := s.D.Id()
427438
request.VolumeBackupId = &tmp
428439

website/docs/r/core_boot_volume_backup.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ resource "oci_core_boot_volume_backup" "test_boot_volume_backup" {
2929
defined_tags = {"Operations.CostCenter"= "42"}
3030
display_name = var.boot_volume_backup_display_name
3131
freeform_tags = {"Department"= "Finance"}
32+
kms_key_id = oci_kms_key.test_key.id
3233
type = var.boot_volume_backup_type
3334
}
3435
```
@@ -42,6 +43,7 @@ The following arguments are supported:
4243
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
4344
* `display_name` - (Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
4445
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
46+
* `kms_key_id` - (Optional) (Updatable) The OCID of the Vault service key which is the master encryption key for the volume backup. For more information about the Vault service and encryption keys, see [Overview of Vault service](https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm) and [Using Keys](https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Tasks/usingkeys.htm).
4547
* `type` - (Optional) The type of backup to create. If omitted, defaults to incremental. Supported values are 'FULL' or 'INCREMENTAL'.
4648
* `source_details` - (Optional) Details of the volume backup source in the cloud. Cannot be defined if `boot_volume_id` is defined.
4749
* `kms_key_id` - (Optional) The OCID of the KMS key in the destination region which will be the master encryption key for the copied volume backup.

website/docs/r/core_volume_backup.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ resource "oci_core_volume_backup" "test_volume_backup" {
2929
defined_tags = {"Operations.CostCenter"= "42"}
3030
display_name = var.volume_backup_display_name
3131
freeform_tags = {"Department"= "Finance"}
32+
kms_key_id = oci_kms_key.test_key.id
3233
type = var.volume_backup_type
3334
}
3435
```
@@ -41,6 +42,7 @@ The following arguments are supported:
4142
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
4243
* `display_name` - (Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
4344
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
45+
* `kms_key_id` - (Optional) (Updatable) The OCID of the Vault service key which is the master encryption key for the volume backup. For more information about the Vault service and encryption keys, see [Overview of Vault service](https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm) and [Using Keys](https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Tasks/usingkeys.htm).
4446
* `type` - (Optional) The type of backup to create. If omitted, defaults to INCREMENTAL. Supported values are 'FULL' or 'INCREMENTAL'.
4547
* `volume_id` - (Optional) The OCID of the volume that needs to be backed up.**Note: To create the resource either `volume_id` or `source_details` is required to be set.
4648
* `source_details` - (Optional) Details of the volume backup source in the cloud.

0 commit comments

Comments
 (0)