-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support added to create or restore VSI volumes to existing stor…
…age snapshots. The following new input variables have been added for this feature:<br>- `snapshot_consistency_group_id`<br>- `boot_volume_snapshot_id`<br>- `block_storage_volumes.snapshot_id` (new property in existing map)<br>- `manage_reserved_ips` (use to assign same reserved VSI instance IP address if recreating)<br>- `use_static_boot_volume_name` (use to keep boot volume names tied to VSI hostnames, instead of random generated name) (#685)
- Loading branch information
1 parent
75b1f87
commit 666f518
Showing
21 changed files
with
472 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Basic example using a Snapshot Consistency Group for volumes | ||
|
||
An end-to-end basic example that will provision the following, using previously created snapshots for storage volumes: | ||
|
||
- A new resource group if one is not passed in. | ||
- A new public SSH key if one is not passed in. | ||
- A new VPC with 3 subnets | ||
- A VSI in each subnet | ||
- Two additional block storage attached to each VSI | ||
- Reserved and Floating IPs managed by Terraform for each VSI | ||
- Boot volume and additional storage volumes will be based on snapshots from consistency group, if ID is supplied |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
############################################################################## | ||
# Locals | ||
############################################################################## | ||
|
||
locals { | ||
ssh_key_id = var.ssh_key != null ? data.ibm_is_ssh_key.existing_ssh_key[0].id : resource.ibm_is_ssh_key.ssh_key[0].id | ||
} | ||
|
||
############################################################################## | ||
# Resource Group | ||
############################################################################## | ||
|
||
module "resource_group" { | ||
source = "terraform-ibm-modules/resource-group/ibm" | ||
version = "1.1.5" | ||
# if an existing resource group is not set (null) create a new one using prefix | ||
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null | ||
existing_resource_group_name = var.resource_group | ||
} | ||
|
||
############################################################################## | ||
# Create new SSH key | ||
############################################################################## | ||
|
||
resource "tls_private_key" "tls_key" { | ||
count = var.ssh_key != null ? 0 : 1 | ||
algorithm = "RSA" | ||
rsa_bits = 4096 | ||
} | ||
|
||
resource "ibm_is_ssh_key" "ssh_key" { | ||
count = var.ssh_key != null ? 0 : 1 | ||
name = "${var.prefix}-ssh-key" | ||
public_key = resource.tls_private_key.tls_key[0].public_key_openssh | ||
} | ||
|
||
data "ibm_is_ssh_key" "existing_ssh_key" { | ||
count = var.ssh_key != null ? 1 : 0 | ||
name = var.ssh_key | ||
} | ||
|
||
############################################################################# | ||
# Provision VPC | ||
############################################################################# | ||
|
||
module "slz_vpc" { | ||
source = "terraform-ibm-modules/landing-zone-vpc/ibm" | ||
version = "7.18.1" | ||
resource_group_id = module.resource_group.resource_group_id | ||
region = var.region | ||
prefix = var.prefix | ||
tags = var.resource_tags | ||
name = "vpc" | ||
} | ||
|
||
############################################################################# | ||
# Provision VSI | ||
############################################################################# | ||
|
||
module "slz_vsi" { | ||
source = "../../" | ||
resource_group_id = module.resource_group.resource_group_id | ||
image_id = var.image_id | ||
create_security_group = false | ||
tags = var.resource_tags | ||
access_tags = var.access_tags | ||
subnets = module.slz_vpc.subnet_zone_list | ||
vpc_id = module.slz_vpc.vpc_id | ||
prefix = var.prefix | ||
machine_type = var.machine_type | ||
vsi_per_subnet = 1 | ||
ssh_key_ids = [local.ssh_key_id] | ||
user_data = null | ||
manage_reserved_ips = true | ||
enable_floating_ip = true | ||
use_static_boot_volume_name = true | ||
block_storage_volumes = [ | ||
{ | ||
name = "vsi-block-1" | ||
profile = "general-purpose" | ||
# snapshot_id = <you can also specify a specific snapshot ID if requried> | ||
}, | ||
{ | ||
name = "vsi-block-2" | ||
profile = "general-purpose" | ||
# snapshot_id = <you can also specify a specific snapshot ID if requried> | ||
}] | ||
# if specifying a group ID, snapshot IDs will be automatically determined from group using system labels | ||
snapshot_consistency_group_id = var.snapshot_consistency_group_id | ||
# boot_volume_snapshot_id = <you can also specify a specific snapshot ID if requried> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
output "slz_vpc" { | ||
value = module.slz_vpc | ||
description = "VPC module values" | ||
} | ||
|
||
output "slz_vsi" { | ||
value = module.slz_vsi | ||
description = "VSI module values" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
provider "ibm" { | ||
ibmcloud_api_key = var.ibmcloud_api_key | ||
region = var.region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
variable "ibmcloud_api_key" { | ||
description = "APIkey that's associated with the account to provision resources to" | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "resource_group" { | ||
type = string | ||
description = "An existing resource group name to use for this example, if unset a new resource group will be created" | ||
default = null | ||
} | ||
|
||
variable "region" { | ||
description = "The region to which to deploy the VPC" | ||
type = string | ||
default = "us-east" | ||
} | ||
|
||
variable "prefix" { | ||
description = "The prefix that you would like to append to your resources" | ||
type = string | ||
default = "slz-vsi" | ||
} | ||
|
||
variable "resource_tags" { | ||
description = "List of Tags for the resource created" | ||
type = list(string) | ||
default = null | ||
} | ||
|
||
variable "access_tags" { | ||
type = list(string) | ||
description = "A list of access tags to apply to the VSI resources created by the module." | ||
default = [] | ||
} | ||
|
||
variable "image_id" { | ||
description = "Image ID used for VSI. Run 'ibmcloud is images' to find available images. Be aware that region is important for the image since the id's are different in each region." | ||
type = string | ||
default = "r014-2a39e91e-e899-4ac4-b309-57e107a7819f" # NOTE: this ID is for us-east region, Redhat 8.10 minimal | ||
} | ||
|
||
variable "machine_type" { | ||
description = "VSI machine type" | ||
type = string | ||
default = "cx2-2x4" | ||
} | ||
|
||
variable "ssh_key" { | ||
type = string | ||
description = "An existing ssh key name to use for this example, if unset a new ssh key will be created" | ||
default = null | ||
} | ||
|
||
variable "snapshot_consistency_group_id" { | ||
type = string | ||
description = "An existing Snapshot Consistency Group Id, used to automatically determine volume snapshots for deployment" | ||
default = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_version = ">= 1.3.0, <1.7.0" | ||
required_providers { | ||
ibm = { | ||
source = "IBM-Cloud/ibm" | ||
version = "= 1.65.0" | ||
} | ||
tls = { | ||
source = "hashicorp/tls" | ||
version = ">= 4.0.4" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.