-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updated the naming of VSIs provisioned by this module. If upgra…
…ding from a previous version be aware that your VSI will be renamed non-disruptively. For example a VSI named `my-vsi-1` will now be renamed to `my-vsi-001` (terraform-ibm-modules#536)
- Loading branch information
1 parent
52400ba
commit 2ee0f7c
Showing
18 changed files
with
302 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Complete Example using a placement group, attaching a load balancer, and adding additional data volumes | ||
|
||
It will provision the following: | ||
|
||
- 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 new placement group. | ||
- A VSI in each subnet placed in the placement group. | ||
- A new Application Load Balancer to balance traffic between all virtual servers that are created by this example. |
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,125 @@ | ||
############################################################################## | ||
# 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.0.6" | ||
# 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 | ||
} | ||
|
||
############################################################################## | ||
# Key Protect All Inclusive | ||
############################################################################## | ||
|
||
module "key_protect_all_inclusive" { | ||
source = "terraform-ibm-modules/key-protect-all-inclusive/ibm" | ||
version = "4.2.0" | ||
resource_group_id = module.resource_group.resource_group_id | ||
region = var.region | ||
key_protect_instance_name = "${var.prefix}-kp" | ||
resource_tags = var.resource_tags | ||
key_map = { "slz-vsi" = ["${var.prefix}-vsi"] } | ||
} | ||
|
||
############################################################################## | ||
# 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.5.0" | ||
resource_group_id = module.resource_group.resource_group_id | ||
region = var.region | ||
prefix = var.prefix | ||
tags = var.resource_tags | ||
name = "${var.prefix}-vpc" | ||
} | ||
|
||
############################################################################# | ||
# Placement group | ||
############################################################################# | ||
|
||
resource "ibm_is_placement_group" "placement_group" { | ||
name = "${var.prefix}-host-spread" | ||
resource_group = module.resource_group.resource_group_id | ||
strategy = "host_spread" | ||
tags = var.resource_tags | ||
} | ||
|
||
############################################################################# | ||
# 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 | ||
placement_group_id = ibm_is_placement_group.placement_group.id | ||
machine_type = "cx2-2x4" | ||
user_data = null | ||
boot_volume_encryption_key = module.key_protect_all_inclusive.keys["slz-vsi.${var.prefix}-vsi"].crn | ||
kms_encryption_enabled = true | ||
existing_kms_instance_guid = module.key_protect_all_inclusive.key_protect_guid | ||
vsi_per_subnet = 1 | ||
ssh_key_ids = [local.ssh_key_id] | ||
# Add 1 additional data volume to each VSI | ||
block_storage_volumes = [ | ||
{ | ||
name = var.prefix | ||
profile = "10iops-tier" | ||
}] | ||
load_balancers = [ | ||
{ | ||
name = "${var.prefix}-lb" | ||
type = "public" | ||
listener_port = 9080 | ||
listener_protocol = "http" | ||
connection_limit = 100 | ||
algorithm = "round_robin" | ||
protocol = "http" | ||
health_delay = 60 | ||
health_retries = 5 | ||
health_timeout = 30 | ||
health_type = "http" | ||
pool_member_port = 8080 | ||
} | ||
] | ||
} |
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,47 @@ | ||
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 all resources in this example" | ||
type = string | ||
default = "us-south" | ||
} | ||
|
||
variable "prefix" { | ||
description = "The prefix that you would like to append to your resources" | ||
type = string | ||
default = "slz-vsi-com" | ||
} | ||
|
||
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 = "r006-1366d3e6-bf5b-49a0-b69a-8efd93cc225f" | ||
} | ||
|
||
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 | ||
} |
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" | ||
required_providers { | ||
ibm = { | ||
source = "IBM-Cloud/ibm" | ||
version = ">= 1.54.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
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.