-
Notifications
You must be signed in to change notification settings - Fork 35
/
vpc.tf
99 lines (82 loc) · 3.4 KB
/
vpc.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
92
93
94
95
96
97
98
99
#####################################################
# IBM Cloud Satellite - IBM Example
# Copyright 2021 IBM
#####################################################
data "ibm_resource_group" "resource_group" {
name = var.resource_group
}
data "ibm_is_image" "rhel7" {
name = "ibm-redhat-7-9-minimal-amd64-3"
}
resource "ibm_is_vpc" "satellite_vpc" {
name = "${var.is_prefix}-vpc"
resource_group = data.ibm_resource_group.resource_group.id
}
resource "ibm_is_subnet" "satellite_subnet" {
count = 3
name = "${var.is_prefix}-subnet-${count.index}"
vpc = ibm_is_vpc.satellite_vpc.id
total_ipv4_address_count = 256
zone = "${var.region}-${count.index + 1}"
resource_group = data.ibm_resource_group.resource_group.id
}
module "default_sg_rules" {
source = "terraform-ibm-modules/vpc/ibm//modules/security-group"
version = "1.0.0"
create_security_group = false
security_group = ibm_is_vpc.satellite_vpc.default_security_group
resource_group_id = data.ibm_resource_group.resource_group.id
security_group_rules = local.sg_rules
}
resource "tls_private_key" "example" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "ibm_is_ssh_key" "satellite_ssh" {
depends_on = [module.satellite-location]
name = "${var.is_prefix}-ssh"
resource_group = data.ibm_resource_group.resource_group.id
public_key = var.public_key != null ? var.public_key : tls_private_key.example.public_key_openssh
}
resource "ibm_is_instance" "satellite_instance" {
count = var.host_count
depends_on = [module.satellite-location.satellite_location]
name = "${var.is_prefix}-location-${count.index}"
vpc = ibm_is_vpc.satellite_vpc.id
zone = element(local.location_zones, count.index)
image = data.ibm_is_image.rhel7.id
profile = var.location_profile
keys = [ibm_is_ssh_key.satellite_ssh.id]
resource_group = data.ibm_resource_group.resource_group.id
user_data = module.satellite-location.host_script
primary_network_interface {
subnet = element(local.subnet_ids, count.index)
}
}
resource "ibm_is_instance" "satellite_cluster_instance" {
count = var.addl_host_count
depends_on = [module.satellite-location.satellite_location]
name = "${var.is_prefix}-cluster-${count.index}"
vpc = ibm_is_vpc.satellite_vpc.id
zone = element(local.location_zones, count.index)
image = data.ibm_is_image.rhel7.id
profile = var.cluster_profile
keys = [ibm_is_ssh_key.satellite_ssh.id]
resource_group = data.ibm_resource_group.resource_group.id
user_data = module.satellite-location.host_script
primary_network_interface {
subnet = element(local.subnet_ids, count.index)
}
}
resource "ibm_is_floating_ip" "satellite_ip" {
count = var.host_count
name = "${var.is_prefix}-fip-${count.index}"
target = ibm_is_instance.satellite_instance[count.index].primary_network_interface[0].id
resource_group = data.ibm_resource_group.resource_group.id
}
resource "ibm_is_floating_ip" "satellite_cluster_ip" {
count = var.addl_host_count
name = "${var.is_prefix}-cluster-fip-${count.index}"
target = ibm_is_instance.satellite_cluster_instance[count.index].primary_network_interface[0].id
resource_group = data.ibm_resource_group.resource_group.id
}