This repository was archived by the owner on Apr 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.tf
More file actions
144 lines (117 loc) · 4.25 KB
/
main.tf
File metadata and controls
144 lines (117 loc) · 4.25 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
terraform {
required_version = ">= 1.3.7"
required_providers {
oci = {
version = ">= 4.104.0"
}
tls = {
source = "hashicorp/tls"
version = "4.0.4"
}
}
backend "s3" {
bucket = "tfstate"
key = "free/terraform.tfstate"
shared_credentials_file = "credentials"
skip_region_validation = true
skip_credentials_validation = true
skip_metadata_api_check = true
force_path_style = true
}
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs
provider "oci" {
user_ocid = var.user
fingerprint = var.fingerprint
tenancy_ocid = var.tenancy
region = var.region
private_key_path = var.key_file
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/identity_compartment
resource "oci_identity_compartment" "free_compartment" {
compartment_id = var.tenancy
description = "Oracle Cloud Free Tier compartment"
name = "free"
enable_delete = true
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_vcn
resource "oci_core_vcn" "free_vcn" {
cidr_block = "10.1.0.0/16"
compartment_id = oci_identity_compartment.free_compartment.id
display_name = "freeVCN"
dns_label = "freevcn"
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_subnet
resource "oci_core_subnet" "free_subnet" {
cidr_block = "10.1.20.0/24"
display_name = "freeSubnet"
dns_label = "freesubnet"
security_list_ids = [oci_core_security_list.free_security_list.id]
compartment_id = oci_identity_compartment.free_compartment.id
vcn_id = oci_core_vcn.free_vcn.id
route_table_id = oci_core_route_table.free_route_table.id
dhcp_options_id = oci_core_vcn.free_vcn.default_dhcp_options_id
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_internet_gateway
resource "oci_core_internet_gateway" "free_internet_gateway" {
compartment_id = oci_identity_compartment.free_compartment.id
display_name = "freeIG"
vcn_id = oci_core_vcn.free_vcn.id
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_route_table
resource "oci_core_route_table" "free_route_table" {
compartment_id = oci_identity_compartment.free_compartment.id
vcn_id = oci_core_vcn.free_vcn.id
display_name = "freeRouteTable"
route_rules {
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
network_entity_id = oci_core_internet_gateway.free_internet_gateway.id
}
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_security_list
resource "oci_core_security_list" "free_security_list" {
compartment_id = oci_identity_compartment.free_compartment.id
vcn_id = oci_core_vcn.free_vcn.id
display_name = "freeSecurityList"
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"
}
}
}
resource "tls_private_key" "instance_ssh_key" {
count = var.instance_public_key_path != "" ? 1 : 0
algorithm = "ED25519"
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_instance
resource "oci_core_instance" "free_instance" {
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[2].name
compartment_id = oci_identity_compartment.free_compartment.id
shape = var.instance_shape
display_name = "freeInstance"
shape_config {
memory_in_gbs = var.instance_memory
ocpus = var.instance_ocpus
}
source_details {
source_id = data.oci_core_images.instance_images.images[0].id
source_type = "image"
boot_volume_size_in_gbs = var.instance_boot_volume_size
}
create_vnic_details {
assign_public_ip = true
subnet_id = oci_core_subnet.free_subnet.id
display_name = var.instance_hostname
}
metadata = {
ssh_authorized_keys = (var.instance_public_key_path != "") ? file("${var.instance_public_key_path}") : tls_private_key.instance_ssh_key[1].public_key_openssh
}
}