Skip to content

Commit 6653f7b

Browse files
authored
feat(storage): add support for boot volume backup policy (#75)
* feat(storage): add support for boot volume backup policy Fix: #64
1 parent 5b0c5c4 commit 6653f7b

18 files changed

+137
-51
lines changed

CHANGELOG.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Given a version number MAJOR.MINOR.PATCH:
1414
* MINOR version when adding functionality in a backwards compatible manner,
1515
* PATCH version when making backwards compatible bug fixes.
1616
17-
== 2.2.0 - unreleased
17+
== 2.2.0 - 2021-09-27
1818

1919
=== Deprecated
2020

@@ -27,7 +27,7 @@ Given a version number MAJOR.MINOR.PATCH:
2727
* Add "module watermark" freeform tags: module defined and user defined freeform tags are merged on the final resource
2828
* Add support to provide the `ssh_authorized_keys` argument as a string or as a file (Fix #67 #70)
2929
* Add support for reserved Public IP on instance first VNIC (fix #55)
30-
* [ ] Define a backup policy for boot volume and additional block volumes (fix #64)
30+
* Add support for backup policy on boot volume (fix #64)
3131
* Add new outputs for each provisioned resources: "all_attributes" outputs have full provider coverage and are auto-updating.
3232

3333
=== Documentation

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
This module provides an easy way to launch compute instances with advanced settings and good practices embedded.
44

5-
On top of the compute instance capabilities, this module can also provision and attach additional Block Volumes to the instances.
5+
On top of the compute instance capabilities, this module can also:
6+
7+
- provision and attach additional Block Volumes to the instances,
8+
- assign a reserved public IP, instead of using Ephemeral,
9+
- assign a backup policy for boot volumes
610

711
**Please Note:**
812

@@ -46,8 +50,8 @@ module "instance" {
4650
instance_display_name = var.instance_display_name
4751
source_ocid = var.source_ocid
4852
subnet_ocids = var.subnet_ocids
49-
assign_public_ip = var.assign_public_ip
50-
ssh_authorized_keys = var.ssh_authorized_keys_file
53+
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
54+
ssh_public_keys = var.ssh_public_keys
5155
block_storage_sizes_in_gbs = [50]
5256
shape = var.shape
5357
}

docs/instance_ssh_keys.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module "instance" {
5151
5252
variable "my_public_ssh_key" {
5353
type = string
54-
default = "<ssh public key>"
54+
default = "<ssh public key>"
5555
}
5656
----
5757

docs/terraformoptions.adoc

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// BEGIN_TF_DOCS
2+
13
== Requirements
24

35
[cols="a,a",options="header,autowidth"]
@@ -6,19 +8,13 @@
68
|[[requirement_terraform]] <<requirement_terraform,terraform>> |>= 0.12
79
|[[requirement_oci]] <<requirement_oci,oci>> |>= 3.27
810
|===
9-
1011
== Providers
1112

1213
[cols="a,a",options="header,autowidth"]
1314
|===
1415
|Name |Version
1516
|[[provider_oci]] <<provider_oci,oci>> |4.17.0
1617
|===
17-
18-
== Modules
19-
20-
No modules.
21-
2218
== Resources
2319

2420
[cols="a,a",options="header,autowidth"]
@@ -28,14 +24,15 @@ No modules.
2824
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_public_ip[oci_core_public_ip.public_ip] |resource
2925
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume[oci_core_volume.volume] |resource
3026
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume_attachment[oci_core_volume_attachment.volume_attachment] |resource
27+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_volume_backup_policy_assignment[oci_core_volume_backup_policy_assignment.boot_volume_backup_policy] |resource
3128
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_instance_credentials[oci_core_instance_credentials.credential] |data source
3229
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_private_ips[oci_core_private_ips.private_ips] |data source
3330
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_shapes[oci_core_shapes.ad1] |data source
3431
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_subnet[oci_core_subnet.instance_subnet] |data source
3532
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_vnic_attachments[oci_core_vnic_attachments.vnic_attachment] |data source
33+
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_volume_backup_policies[oci_core_volume_backup_policies.default_backup_policies] |data source
3634
|https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_availability_domains[oci_identity_availability_domains.ad] |data source
3735
|===
38-
3936
== Inputs
4037

4138
[cols="a,a,a,a,a",options="header,autowidth"]
@@ -65,6 +62,12 @@ No modules.
6562
|`[]`
6663
|no
6764

65+
|[[input_boot_volume_backup_policy]] <<input_boot_volume_backup_policy,boot_volume_backup_policy>>
66+
|Choose between default backup policies : gold, silver, bronze. Use disabled to affect no backup policy on the Boot Volume.
67+
|`string`
68+
|`"disabled"`
69+
|no
70+
6871
|[[input_boot_volume_size_in_gbs]] <<input_boot_volume_size_in_gbs,boot_volume_size_in_gbs>>
6972
|The size of the boot volume in GBs.
7073
|`number`
@@ -228,7 +231,6 @@ No modules.
228231
|no
229232

230233
|===
231-
232234
== Outputs
233235

234236
[cols="a,a",options="header,autowidth"]
@@ -246,4 +248,6 @@ No modules.
246248
|[[output_vnic_attachment_all_attributes]] <<output_vnic_attachment_all_attributes,vnic_attachment_all_attributes>> |all attributes of created vnic attachments
247249
|[[output_volume_all_attributes]] <<output_volume_all_attributes,volume_all_attributes>> |all attributes of created volumes
248250
|[[output_volume_attachment_all_attributes]] <<output_volume_attachment_all_attributes,volume_attachment_all_attributes>> |all attributes of created volumes attachments
249-
|===
251+
|===
252+
253+
// END_TF_DOCS

examples/instances_fixed_shape/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module "instance_nonflex" {
3737
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
3838
subnet_ocids = var.subnet_ocids
3939
# storage parameters
40+
boot_volume_backup_policy = var.boot_volume_backup_policy
4041
block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs
4142
}
4243

@@ -68,6 +69,7 @@ module "instance_nonflex_custom" {
6869
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
6970
subnet_ocids = var.subnet_ocids
7071
# storage parameters
72+
boot_volume_backup_policy = var.boot_volume_backup_policy
7173
block_storage_sizes_in_gbs = [] # no block volume will be created
7274
}
7375

examples/instances_fixed_shape/terraform.tfvars.example

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ ssh_public_keys = <<EOT
3333
<ssh_public_key_3>
3434
EOT
3535

36+
# storage parameters
37+
38+
boot_volume_backup_policy = "<the backup policy name>" # gold, silver, bronze, disabled
39+
3640
# networking parameters
3741

3842
subnet_ocids = ["<a list of the subnet OCIDs which to create the VNICs in>"]

examples/instances_fixed_shape/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ variable "subnet_ocids" {
131131

132132
# storage parameters
133133

134+
variable "boot_volume_backup_policy" {
135+
description = "Choose between default backup policies : gold, silver, bronze. Use disabled to affect no backup policy on the Boot Volume."
136+
type = string
137+
default = "disabled"
138+
}
139+
134140
variable "block_storage_sizes_in_gbs" {
135141
description = "Sizes of volumes to create and attach to each instance."
136142
type = list(string)

examples/instances_flex_shape/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module "instance_flex" {
4040
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
4141
subnet_ocids = var.subnet_ocids
4242
# storage parameters
43+
boot_volume_backup_policy = var.boot_volume_backup_policy
4344
block_storage_sizes_in_gbs = var.block_storage_sizes_in_gbs
4445
}
4546

@@ -70,6 +71,7 @@ output "instance_flex" {
7071
# public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
7172
# subnet_ocids = var.subnet_ocids
7273
# # storage parameters
74+
# boot_volume_backup_policy = "silver"
7375
# block_storage_sizes_in_gbs = [] # no block volume will be created
7476
# }
7577

examples/instances_flex_shape/terraform.tfvars.example

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ ssh_public_keys = <<EOT
3333
<ssh_public_key_3>
3434
EOT
3535

36+
# storage parameters
37+
38+
boot_volume_backup_policy = "<the backup policy name>" # gold, silver, bronze, disabled
39+
3640
# networking parameters
3741

3842
subnet_ocids = ["<a list of the subnet OCIDs which to create the VNICs in>"]

examples/instances_flex_shape/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ variable "subnet_ocids" {
132132

133133
# storage parameters
134134

135+
variable "boot_volume_backup_policy" {
136+
description = "Choose between default backup policies : gold, silver, bronze. Use disabled to affect no backup policy on the Boot Volume."
137+
type = string
138+
default = "disabled"
139+
}
140+
135141
variable "block_storage_sizes_in_gbs" {
136142
description = "Sizes of volumes to create and attach to each instance."
137143
type = list(string)

examples/instances_reserved_public_ip/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Creating Compute Instances using Flex shape
1+
# Creating Compute Instances with a reserved public IP
22

33
This example illustrates how to use this module to creates compute instances with a reserved public IP.
44

examples/instances_reserved_public_ip/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ module "instance_reserved_ip" {
3434
instance_flex_memory_in_gbs = 1 # only used if shape is Flex type
3535
instance_flex_ocpus = 1 # only used if shape is Flex type
3636
# operating system parameters
37-
ssh_authorized_keys = var.ssh_authorized_keys
37+
ssh_public_keys = var.ssh_public_keys
3838
# networking parameters
3939
public_ip = var.public_ip # NONE, RESERVED or EPHEMERAL
4040
subnet_ocids = var.subnet_ocids
4141
# storage parameters
42+
boot_volume_backup_policy = var.boot_volume_backup_policy
4243
block_storage_sizes_in_gbs = [] # no block volume will be created
4344
preserve_boot_volume = false
4445
}

examples/instances_reserved_public_ip/terraform.tfvars.example

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ source_ocid = "<The OCID of an image or a boot volume>"
2727

2828
# operating system parameters
2929

30-
ssh_authorized_keys = "<path to the instance's public key>"
30+
ssh_public_keys = <<EOT
31+
<ssh_public_key_1>
32+
<ssh_public_key_2>
33+
<ssh_public_key_3>
34+
EOT
35+
36+
# storage parameters
37+
38+
boot_volume_backup_policy = "<the backup policy name>" # gold, silver, bronze, disabled
3139

3240
# networking parameters
3341

examples/instances_reserved_public_ip/variables.tf

+9-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ variable "source_type" {
104104

105105
# operating system parameters
106106

107-
variable "ssh_authorized_keys" {
108-
description = "Public SSH keys path to be included in the ~/.ssh/authorized_keys file for the default user on the instance."
107+
variable "ssh_public_keys" {
108+
description = "Public SSH keys to be included in the ~/.ssh/authorized_keys file for the default user on the instance. To provide multiple keys, see docs/instance_ssh_keys.adoc."
109109
type = string
110+
default = null
110111
}
111112

112113
# networking parameters
@@ -124,6 +125,12 @@ variable "subnet_ocids" {
124125

125126
# storage parameters
126127

128+
variable "boot_volume_backup_policy" {
129+
description = "Choose between default backup policies : gold, silver, bronze. Use disabled to affect no backup policy on the Boot Volume."
130+
type = string
131+
default = "disabled"
132+
}
133+
127134
variable "block_storage_sizes_in_gbs" {
128135
description = "Sizes of volumes to create and attach to each instance."
129136
type = list(string)

main.tf

+10-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
23

34
terraform {
45
required_version = ">= 0.12" // terraform version below 0.12 is not tested/supported with this module
@@ -9,16 +10,23 @@ terraform {
910
}
1011
}
1112

12-
// Get all the Availability Domains for the region
13+
// Get all the Availability Domains for the region and default backup policies
1314
data "oci_identity_availability_domains" "ad" {
1415
compartment_id = var.compartment_ocid
1516
}
1617

18+
data "oci_core_volume_backup_policies" "default_backup_policies" {}
19+
1720
locals {
1821
ADs = [
1922
// Iterate through data.oci_identity_availability_domains.ad and create a list containing AD names
2023
for i in data.oci_identity_availability_domains.ad.availability_domains : i.name
2124
]
25+
backup_policies = {
26+
// Iterate through data.oci_core_volume_backup_policies.default_backup_policies and create a map containing name & ocid
27+
// This is used to specify a backup policy id by name
28+
for i in data.oci_core_volume_backup_policies.default_backup_policies.volume_backup_policies : i.display_name => i.id
29+
}
2230
}
2331

2432
####################
@@ -116,33 +124,6 @@ data "oci_core_instance_credentials" "credential" {
116124
instance_id = oci_core_instance.instance[count.index].id
117125
}
118126

119-
#########
120-
# Volume
121-
#########
122-
resource "oci_core_volume" "volume" {
123-
count = var.instance_count * length(var.block_storage_sizes_in_gbs)
124-
availability_domain = oci_core_instance.instance[count.index % var.instance_count].availability_domain
125-
compartment_id = var.compartment_ocid
126-
display_name = "${oci_core_instance.instance[count.index % var.instance_count].display_name}_volume${floor(count.index / var.instance_count)}"
127-
size_in_gbs = element(
128-
var.block_storage_sizes_in_gbs,
129-
floor(count.index / var.instance_count),
130-
)
131-
freeform_tags = local.merged_freeform_tags
132-
defined_tags = var.defined_tags
133-
}
134-
135-
####################
136-
# Volume Attachment
137-
####################
138-
resource "oci_core_volume_attachment" "volume_attachment" {
139-
count = var.instance_count * length(var.block_storage_sizes_in_gbs)
140-
attachment_type = var.attachment_type
141-
instance_id = oci_core_instance.instance[count.index % var.instance_count].id
142-
volume_id = oci_core_volume.volume[count.index].id
143-
use_chap = var.use_chap
144-
}
145-
146127
####################
147128
# Networking
148129
####################

outputs.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
23

34
locals {
45
instances_details = [

variables.tf

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2021 Oracle Corporation and/or affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
23

34
# general oci parameters
45

@@ -205,6 +206,17 @@ variable "block_storage_sizes_in_gbs" {
205206
# default = true
206207
# }
207208

209+
variable "boot_volume_backup_policy" {
210+
description = "Choose between default backup policies : gold, silver, bronze. Use disabled to affect no backup policy on the Boot Volume."
211+
type = string
212+
default = "disabled"
213+
214+
validation {
215+
condition = contains(["gold", "silver", "bronze", "disabled"], var.boot_volume_backup_policy)
216+
error_message = "Accepted values are gold, silver, bronze or disabled (case sensitive)."
217+
}
218+
}
219+
208220
variable "boot_volume_size_in_gbs" {
209221
description = "The size of the boot volume in GBs."
210222
type = number

0 commit comments

Comments
 (0)