-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
120 lines (101 loc) · 3.13 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
// Licensed under the Mozilla Public License v2.0
# Get a list of Availability Domains
data "oci_identity_availability_domain" "ad" {
compartment_id = var.tenancy_ocid
ad_number = var.ad_region_mapping[var.region]
}
resource "oci_core_virtual_network" "tcb_vcn" {
cidr_block = "10.1.0.0/16"
compartment_id = var.compartment_ocid
display_name = "tcbVCN"
dns_label = "tcbvcn"
}
resource "oci_core_subnet" "tcb_subnet" {
cidr_block = "10.1.20.0/24"
display_name = "tcbSubnet"
dns_label = "tcbsubnet"
security_list_ids = [oci_core_security_list.tcb_security_list.id]
compartment_id = var.compartment_ocid
vcn_id = oci_core_virtual_network.tcb_vcn.id
route_table_id = oci_core_route_table.tcb_route_table.id
dhcp_options_id = oci_core_virtual_network.tcb_vcn.default_dhcp_options_id
}
resource "oci_core_internet_gateway" "tcb_internet_gateway" {
compartment_id = var.compartment_ocid
display_name = "tcbIG"
vcn_id = oci_core_virtual_network.tcb_vcn.id
}
resource "oci_core_route_table" "tcb_route_table" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_virtual_network.tcb_vcn.id
display_name = "tcbRouteTable"
route_rules {
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
network_entity_id = oci_core_internet_gateway.tcb_internet_gateway.id
}
}
resource "oci_core_security_list" "tcb_security_list" {
compartment_id = var.compartment_ocid
vcn_id = oci_core_virtual_network.tcb_vcn.id
display_name = "tcbSecurityList"
egress_security_rules {
protocol = "6"
destination = "0.0.0.0/0"
}
ingress_security_rules {
protocol = "6"
source = "0.0.0.0/0"
tcp_options {
max = "22"
min = "22"
}
}
ingress_security_rules {
protocol = "6"
source = "0.0.0.0/0"
tcp_options {
max = "80"
min = "80"
}
}
}
resource "oci_core_instance" "webserver1" {
availability_domain = data.oci_identity_availability_domain.ad.name
compartment_id = var.compartment_ocid
display_name = "webserver1"
shape = "VM.Standard.E2.1.Micro"
create_vnic_details {
subnet_id = oci_core_subnet.tcb_subnet.id
display_name = "primaryvnic"
assign_public_ip = true
hostname_label = "webserver1"
}
source_details {
source_type = "image"
source_id = var.images[var.region]
}
metadata = {
ssh_authorized_keys = var.ssh_public_key
}
}
resource "oci_core_instance" "webserver2" {
availability_domain = data.oci_identity_availability_domain.ad.name
compartment_id = var.compartment_ocid
display_name = "webserver2"
shape = "VM.Standard.E2.1.Micro"
create_vnic_details {
subnet_id = oci_core_subnet.tcb_subnet.id
display_name = "primaryvnic"
assign_public_ip = true
hostname_label = "webserver2"
}
source_details {
source_type = "image"
source_id = var.images[var.region]
}
metadata = {
ssh_authorized_keys = var.ssh_public_key
}
}