Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: additional load balancer config #536

Merged
merged 19 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
44812f0
feat: additional load balancer config
rajatagarwal-ibm Sep 19, 2023
6ceaad6
Merge branch 'main' into configurable-lb
rajatagarwal-ibm Sep 19, 2023
ce59df4
feat: additional load balancer config
rajatagarwal-ibm Sep 19, 2023
7119061
feat: additional load balancer config
rajatagarwal-ibm Sep 19, 2023
caf1024
Merge branch 'configurable-lb' of github.com:terraform-ibm-modules/te…
rajatagarwal-ibm Sep 19, 2023
de77958
feat: additional load balancer config
rajatagarwal-ibm Sep 19, 2023
213234e
feat: additional load balancer config
rajatagarwal-ibm Sep 20, 2023
eb7f165
Merge branch 'main' into configurable-lb
rajatagarwal-ibm Sep 20, 2023
92f5dfb
feat: additional load balancer config
rajatagarwal-ibm Sep 25, 2023
a2de13c
feat: additional load balancer config
rajatagarwal-ibm Sep 25, 2023
88a2dd1
Merge branch 'main' into configurable-lb
rajatagarwal-ibm Sep 25, 2023
bb505e1
feat: additional load balancer config
rajatagarwal-ibm Sep 25, 2023
a8fc2c1
Merge branch 'configurable-lb' of github.com:terraform-ibm-modules/te…
rajatagarwal-ibm Sep 25, 2023
645a242
feat: additional load balancer config
rajatagarwal-ibm Sep 25, 2023
aa77bb3
feat: additional load balancer config
rajatagarwal-ibm Sep 25, 2023
b818d04
feat: additional load balancer config
rajatagarwal-ibm Sep 25, 2023
4536a2e
feat: additional load balancer config
rajatagarwal-ibm Sep 26, 2023
95c2bbb
feat: additional load balancer config
rajatagarwal-ibm Sep 26, 2023
0b5fa55
Merge branch 'main' into configurable-lb
rajatagarwal-ibm Sep 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ You need the following permissions to run this module.
## Examples

- [ End to end basic example](examples/basic)
- [ Complete Example](examples/complete)
- [ Financial Services Cloud profile example](examples/fscloud)
<!-- END EXAMPLES HOOK -->

Expand Down Expand Up @@ -155,7 +156,7 @@ No modules.
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect Crypto Services instance in which the key specified in var.boot\_volume\_encryption\_key is coming from. | `string` | `null` | no |
| <a name="input_image_id"></a> [image\_id](#input\_image\_id) | Image ID used for VSI. Run 'ibmcloud is images' to find available images in a region | `string` | n/a | yes |
| <a name="input_kms_encryption_enabled"></a> [kms\_encryption\_enabled](#input\_kms\_encryption\_enabled) | Set this to true to control the encryption keys used to encrypt the data that for the block storage volumes for VPC. If set to false, the data is encrypted by using randomly generated keys. For more info on encrypting block storage volumes, see https://cloud.ibm.com/docs/vpc?topic=vpc-creating-instances-byok | `bool` | `false` | no |
| <a name="input_load_balancers"></a> [load\_balancers](#input\_load\_balancers) | Load balancers to add to VSI | <pre>list(<br> object({<br> name = string<br> type = string<br> listener_port = number<br> listener_protocol = string<br> connection_limit = number<br> algorithm = string<br> protocol = string<br> health_delay = number<br> health_retries = number<br> health_timeout = number<br> health_type = string<br> pool_member_port = string<br> security_group = optional(<br> object({<br> name = string<br> rules = list(<br> object({<br> name = string<br> direction = string<br> source = string<br> tcp = optional(<br> object({<br> port_max = number<br> port_min = number<br> })<br> )<br> udp = optional(<br> object({<br> port_max = number<br> port_min = number<br> })<br> )<br> icmp = optional(<br> object({<br> type = number<br> code = number<br> })<br> )<br> })<br> )<br> })<br> )<br> })<br> )</pre> | `[]` | no |
| <a name="input_load_balancers"></a> [load\_balancers](#input\_load\_balancers) | Load balancers to add to VSI | <pre>list(<br> object({<br> name = string<br> type = string<br> listener_port = number<br> listener_protocol = string<br> connection_limit = number<br> algorithm = string<br> protocol = string<br> health_delay = number<br> health_retries = number<br> health_timeout = number<br> health_type = string<br> pool_member_port = string<br> profile = optional(string)<br> dns = optional(<br> object({<br> instance_crn = string<br> zone_id = string<br> })<br> )<br> security_group = optional(<br> object({<br> name = string<br> rules = list(<br> object({<br> name = string<br> direction = string<br> source = string<br> tcp = optional(<br> object({<br> port_max = number<br> port_min = number<br> })<br> )<br> udp = optional(<br> object({<br> port_max = number<br> port_min = number<br> })<br> )<br> icmp = optional(<br> object({<br> type = number<br> code = number<br> })<br> )<br> })<br> )<br> })<br> )<br> })<br> )</pre> | `[]` | no |
| <a name="input_machine_type"></a> [machine\_type](#input\_machine\_type) | VSI machine type. Run 'ibmcloud is instance-profiles' to get a list of regional profiles | `string` | n/a | yes |
| <a name="input_placement_group_id"></a> [placement\_group\_id](#input\_placement\_group\_id) | Unique Identifier of the Placement Group for restricting the placement of the instance, default behaviour is placement on any host | `string` | `null` | no |
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The IBM Cloud platform API key needed to deploy IAM enabled resources | `string` | n/a | yes |
Expand Down
10 changes: 10 additions & 0 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Complete Example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete Example using a placement group, attaching a load balancer, and adding additional data volumes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rajatagarwal-ibm The title was not updated here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah its below - it needs to be in title so its exposed in main readme


An end-to-end basic example that 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placed in the placement group

- A new Application Load Balancer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new Application Load Balancer to balance traffic between all virtual servers that are created by this example

109 changes: 109 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
##############################################################################
# Locals
##############################################################################

locals {
resource_group_id = var.resource_group != null ? data.ibm_resource_group.existing_resource_group[0].id : ibm_resource_group.resource_group[0].id
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
# (if var.resource_group is null, create a new RG using var.prefix)
##############################################################################

resource "ibm_resource_group" "resource_group" {
count = var.resource_group != null ? 0 : 1
name = "${var.prefix}-rg"
quota_id = null
}

data "ibm_resource_group" "existing_resource_group" {
count = var.resource_group != null ? 1 : 0
name = var.resource_group
}
rajatagarwal-ibm marked this conversation as resolved.
Show resolved Hide resolved

##############################################################################
# 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 = local.resource_group_id
region = var.region
prefix = var.prefix
tags = var.resource_tags
name = var.vpc_name
}

#############################################################################
# Placement group
#############################################################################

resource "ibm_is_placement_group" "placement_group" {
name = "${var.prefix}-host-spread"
resource_group = local.resource_group_id
strategy = "host_spread"
tags = var.resource_tags
}

#############################################################################
# Provision VSI
#############################################################################

module "slz_vsi" {
source = "../../"
resource_group_id = local.resource_group_id
image_id = var.image_id
create_security_group = var.create_security_group
security_group = var.security_group
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 = var.machine_type
user_data = var.user_data
boot_volume_encryption_key = var.boot_volume_encryption_key
vsi_per_subnet = var.vsi_per_subnet
ssh_key_ids = [local.ssh_key_id]
ocofaigh marked this conversation as resolved.
Show resolved Hide resolved
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
}
]
}
9 changes: 9 additions & 0 deletions examples/complete/outputs.tf
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"
}
4 changes: 4 additions & 0 deletions examples/complete/provider.tf
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
}
116 changes: 116 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploy the VPC -> 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 = "rajat-vsi"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use your name in the prefix :)

}

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 "machine_type" {
description = "VSI machine type"
type = string
default = "cx2-2x4"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just pass this in directly to in the example main.tf - no need to expose as a variable in the example


variable "create_security_group" {
description = "Create security group for VSI"
type = string
default = false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just pass this in directly to in the example main.tf - no need to expose as a variable in the example


variable "security_group" {
description = "Security group created for VSI"
type = object({
name = string
rules = list(
object({
name = string
direction = string
source = string
tcp = optional(
object({
port_max = number
port_min = number
})
)
udp = optional(
object({
port_max = number
port_min = number
})
)
icmp = optional(
object({
type = number
code = number
})
)
})
)
})
default = null
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove this from the example if we are not passing any value for it


variable "user_data" {
description = "User data to initialize VSI deployment"
type = string
default = null
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove this from the example if we are not passing any value for it


variable "boot_volume_encryption_key" {
description = "CRN of boot volume encryption key"
type = string
default = null
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this


variable "vsi_per_subnet" {
description = "Number of VSI instances for each subnet"
type = number
default = 1
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just pass this in directly to in the example main.tf - no need to expose as a variable in the example


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 "vpc_name" {
type = string
description = "Name for VPC"
default = "vpc"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this from here - use the prefix variable for vpc name

13 changes: 13 additions & 0 deletions examples/complete/version.tf
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"
}
}
}
2 changes: 1 addition & 1 deletion examples/fscloud/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "region" {
variable "prefix" {
description = "The prefix that you would like to append to your resources"
type = string
default = "rajat-fs-vsi"
default = "slz-fs-vsi"
}

variable "resource_tags" {
Expand Down
1 change: 1 addition & 0 deletions load_balancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resource "ibm_is_lb" "lb" {
name = "${var.prefix}-${each.value.name}-lb"
subnets = var.subnets[*].id
type = each.value.type
profile = each.value.profile
security_groups = each.value.security_group == null ? null : [ibm_is_security_group.security_group[each.value.security_group.name].id]
resource_group = var.resource_group_id
tags = var.tags
Expand Down
18 changes: 9 additions & 9 deletions module-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
},
"load_balancers": {
"name": "load_balancers",
"type": "list(\n object({\n name = string\n type = string\n listener_port = number\n listener_protocol = string\n connection_limit = number\n algorithm = string\n protocol = string\n health_delay = number\n health_retries = number\n health_timeout = number\n health_type = string\n pool_member_port = string\n security_group = optional(\n object({\n name = string\n rules = list(\n object({\n name = string\n direction = string\n source = string\n tcp = optional(\n object({\n port_max = number\n port_min = number\n })\n )\n udp = optional(\n object({\n port_max = number\n port_min = number\n })\n )\n icmp = optional(\n object({\n type = number\n code = number\n })\n )\n })\n )\n })\n )\n })\n )",
"type": "list(\n object({\n name = string\n type = string\n listener_port = number\n listener_protocol = string\n connection_limit = number\n algorithm = string\n protocol = string\n health_delay = number\n health_retries = number\n health_timeout = number\n health_type = string\n pool_member_port = string\n profile = optional(string)\n dns = optional(\n object({\n instance_crn = string\n zone_id = string\n })\n )\n security_group = optional(\n object({\n name = string\n rules = list(\n object({\n name = string\n direction = string\n source = string\n tcp = optional(\n object({\n port_max = number\n port_min = number\n })\n )\n udp = optional(\n object({\n port_max = number\n port_min = number\n })\n )\n icmp = optional(\n object({\n type = number\n code = number\n })\n )\n })\n )\n })\n )\n })\n )",
"description": "Load balancers to add to VSI",
"default": [],
"pos": {
Expand Down Expand Up @@ -199,7 +199,7 @@
"default": false,
"pos": {
"filename": "variables.tf",
"line": 398
"line": 405
}
},
"secondary_floating_ips": {
Expand All @@ -212,7 +212,7 @@
],
"pos": {
"filename": "variables.tf",
"line": 387
"line": 394
}
},
"secondary_security_groups": {
Expand All @@ -222,7 +222,7 @@
"default": [],
"pos": {
"filename": "variables.tf",
"line": 366
"line": 373
}
},
"secondary_subnets": {
Expand All @@ -232,7 +232,7 @@
"default": [],
"pos": {
"filename": "variables.tf",
"line": 347
"line": 354
}
},
"secondary_use_vsi_security_group": {
Expand All @@ -242,7 +242,7 @@
"default": false,
"pos": {
"filename": "variables.tf",
"line": 360
"line": 367
}
},
"security_group": {
Expand Down Expand Up @@ -540,7 +540,7 @@
},
"pos": {
"filename": "load_balancer.tf",
"line": 81
"line": 82
}
},
"ibm_is_lb_pool.pool": {
Expand All @@ -555,7 +555,7 @@
},
"pos": {
"filename": "load_balancer.tf",
"line": 30
"line": 31
}
},
"ibm_is_lb_pool_member.pool_members": {
Expand All @@ -567,7 +567,7 @@
},
"pos": {
"filename": "load_balancer.tf",
"line": 65
"line": 66
}
},
"ibm_is_security_group.security_group": {
Expand Down
Loading