-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.tf
91 lines (80 loc) · 3.36 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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.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
}
##############################################################################
# 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.19.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>
}