Created
December 15, 2019 07:22
-
-
Save mago1chi/c3def31075817a1a5886db407b07a661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# variables | |
variable "tenancy_ocid" {} | |
variable "user_ocid" {} | |
variable "fingerprint" {} | |
variable "private_key_path" {} | |
variable "region" {} | |
variable "ssh_public_key" {} | |
variable "autonomous_database_admin_password" {} | |
# compartment | |
resource "oci_identity_compartment" "test_compartment" { | |
#Required | |
compartment_id = "${var.tenancy_ocid}" | |
description = "test compartment" | |
name = "User1Compartment" | |
} | |
# user | |
resource "oci_identity_user" "test_user" { | |
#Required | |
compartment_id = "${var.tenancy_ocid}" | |
description = "test user" | |
name = "user1" | |
} | |
# group | |
resource "oci_identity_group" "test_group" { | |
#Required | |
compartment_id = "${var.tenancy_ocid}" | |
description = "test group" | |
name = "group1" | |
} | |
# mapping of users and groups | |
resource "oci_identity_user_group_membership" "test_user_group_membership" { | |
#Required | |
group_id = "${oci_identity_group.test_group.id}" | |
user_id = "${oci_identity_user.test_user.id}" | |
} | |
# IAM | |
resource "oci_identity_policy" "test_policy" { | |
#Required | |
compartment_id = "${var.tenancy_ocid}" | |
description = "test policy" | |
name = "group1-test-policy" | |
statements = ["Allow group ${oci_identity_group.test_group.name} to manage virtual-network-family in compartment ${oci_identity_compartment.test_compartment.name}", | |
"Allow group ${oci_identity_group.test_group.name} to manage volume-family in compartment ${oci_identity_compartment.test_compartment.name}", | |
"Allow group ${oci_identity_group.test_group.name} to manage instance-family in compartment ${oci_identity_compartment.test_compartment.name}"] | |
} | |
# VCN | |
resource "oci_core_vcn" "test_vcn" { | |
#Required | |
cidr_block = "192.168.10.0/24" | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
#Optional | |
display_name = "test_vcn" | |
dns_label = "testvcn" | |
} | |
# availability domain | |
data "oci_identity_availability_domains" "test_availability_domains" { | |
#Required | |
compartment_id = "${var.tenancy_ocid}" | |
} | |
# security list | |
resource "oci_core_security_list" "test_security_list" { | |
#Required | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
ingress_security_rules { | |
#Required | |
protocol = "6" | |
source = "0.0.0.0/0" | |
#Optional | |
tcp_options { | |
#Optional | |
max = "2222" | |
min = "2222" | |
} | |
} | |
vcn_id = "${oci_core_vcn.test_vcn.id}" | |
#Optional | |
display_name = "test_security_list" | |
} | |
# internet gateway | |
resource "oci_core_internet_gateway" "test_ig" { | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
display_name = "tet_ig" | |
vcn_id = "${oci_core_vcn.test_vcn.id}" | |
} | |
# route table | |
resource "oci_core_route_table" "test_route_table" { | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
vcn_id = "${oci_core_vcn.test_vcn.id}" | |
display_name = "test_route_table" | |
route_rules { | |
destination = "0.0.0.0/0" | |
destination_type = "CIDR_BLOCK" | |
network_entity_id = "${oci_core_internet_gateway.test_ig.id}" | |
} | |
} | |
# subnet | |
resource "oci_core_subnet" "test_subnet" { | |
#Required | |
availability_domain = "${lookup(data.oci_identity_availability_domains.test_availability_domains.availability_domains[0], "name")}" | |
cidr_block = "192.168.10.0/27" | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
security_list_ids = ["${oci_core_security_list.test_security_list.id}"] | |
vcn_id = "${oci_core_vcn.test_vcn.id}" | |
#Optional | |
display_name = "testvcn_subnet1" | |
dns_label = "subnet1" | |
route_table_id = "${oci_core_route_table.test_route_table.id}" | |
} | |
# network security group | |
resource "oci_core_network_security_group" "test_network_security_group" { | |
#Required | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
vcn_id = "${oci_core_vcn.test_vcn.id}" | |
#Optional | |
display_name = "test_nsg" | |
} | |
# nsg security rules | |
resource "oci_core_network_security_group_security_rule" "test_network_security_group_security_rule" { | |
#Required | |
network_security_group_id = "${oci_core_network_security_group.test_network_security_group.id}" | |
direction = "INGRESS" | |
protocol = "6" | |
#Optional | |
description = "test nsg rules" | |
destination = "${oci_core_network_security_group.test_network_security_group.id}" | |
source = "0.0.0.0/0" | |
source_type = "CIDR_BLOCK" | |
tcp_options { | |
#Optional | |
destination_port_range { | |
#Required | |
max = "22" | |
min = "22" | |
} | |
} | |
} | |
# instance | |
resource "oci_core_instance" "test_instance1" { | |
#Required | |
availability_domain = "${lookup(data.oci_identity_availability_domains.test_availability_domains.availability_domains[0], "name")}" | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
shape = "VM.Standard.E2.1.Micro" | |
#Optional | |
create_vnic_details { | |
#Required | |
subnet_id = "${oci_core_subnet.test_subnet.id}" | |
#Optional | |
display_name = "test_instance1_vnic1" | |
hostname_label = "tstinst1" | |
private_ip = "192.168.10.5" | |
nsg_ids = ["${oci_core_network_security_group.test_network_security_group.id}"] | |
} | |
display_name = "test_instance1" | |
metadata { | |
ssh_authorized_keys = "${var.ssh_public_key}" | |
} | |
source_details { | |
#Required | |
source_id = "ocid1.image.oc1.ap-tokyo-1.aaaaaaaa54xb7m4f42vckxkrmtlpys32quyjfldbkhq5zsbmw2r6v5hzgvkq" | |
source_type = "image" | |
#Optional | |
boot_volume_size_in_gbs = "50" | |
} | |
} | |
resource "oci_core_instance" "test_instance2" { | |
#Required | |
availability_domain = "${lookup(data.oci_identity_availability_domains.test_availability_domains.availability_domains[0], "name")}" | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
shape = "VM.Standard.E2.1.Micro" | |
#Optional | |
create_vnic_details { | |
#Required | |
subnet_id = "${oci_core_subnet.test_subnet.id}" | |
#Optional | |
display_name = "test_instance2_vnic1" | |
hostname_label = "tstinst2" | |
private_ip = "192.168.10.6" | |
nsg_ids = ["${oci_core_network_security_group.test_network_security_group.id}"] | |
} | |
display_name = "test_instance2" | |
metadata { | |
ssh_authorized_keys = "${var.ssh_public_key}" | |
} | |
source_details { | |
#Required | |
source_id = "ocid1.image.oc1.ap-tokyo-1.aaaaaaaa54xb7m4f42vckxkrmtlpys32quyjfldbkhq5zsbmw2r6v5hzgvkq" | |
source_type = "image" | |
#Optional | |
boot_volume_size_in_gbs = "50" | |
} | |
} | |
# load balancer | |
resource "oci_load_balancer_load_balancer" "test_load_balancer" { | |
#Required | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
display_name = "test_lb" | |
shape = "10Mbps-Micro" | |
subnet_ids = ["${oci_core_subnet.test_subnet.id}"] | |
#Optional | |
network_security_group_ids = ["${oci_core_network_security_group.test_network_security_group.id}"] | |
} | |
# lb hostname | |
resource "oci_load_balancer_hostname" "test_hostname" { | |
#Required | |
hostname = "tstlb1.com" | |
load_balancer_id = "${oci_load_balancer_load_balancer.test_load_balancer.id}" | |
name = "tstlb1" | |
} | |
# lb backend set | |
resource "oci_load_balancer_backend_set" "test_backend_set" { | |
#Required | |
health_checker { | |
#Required | |
protocol = "TCP" | |
#Optional | |
interval_ms = "1000" | |
port = "22" | |
retries = "5" | |
timeout_in_millis = "1200" | |
} | |
load_balancer_id = "${oci_load_balancer_load_balancer.test_load_balancer.id}" | |
name = "test_backend_set" | |
policy = "LEAST_CONNECTIONS" | |
} | |
# lb backend | |
resource "oci_load_balancer_backend" "test_backend1" { | |
#Required | |
backendset_name = "${oci_load_balancer_backend_set.test_backend_set.name}" | |
ip_address = "${oci_core_instance.test_instance1.private_ip}" | |
load_balancer_id = "${oci_load_balancer_load_balancer.test_load_balancer.id}" | |
port = "22" | |
} | |
resource "oci_load_balancer_backend" "test_backend2" { | |
#Required | |
backendset_name = "${oci_load_balancer_backend_set.test_backend_set.name}" | |
ip_address = "${oci_core_instance.test_instance2.private_ip}" | |
load_balancer_id = "${oci_load_balancer_load_balancer.test_load_balancer.id}" | |
port = "22" | |
} | |
# lb listener | |
resource "oci_load_balancer_listener" "test_listener" { | |
#Required | |
default_backend_set_name = "${oci_load_balancer_backend_set.test_backend_set.name}" | |
load_balancer_id = "${oci_load_balancer_load_balancer.test_load_balancer.id}" | |
name = "test_lb_listener" | |
port = "2222" | |
protocol = "TCP" | |
#Optional | |
connection_configuration { | |
#Required | |
idle_timeout_in_seconds = "600" | |
} | |
} | |
# autonomoud database (OLTP) | |
resource "oci_database_autonomous_database" "test_autonomous_database_oltp" { | |
#Required | |
admin_password = "${var.autonomous_database_admin_password}" | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
cpu_core_count = "1" | |
data_storage_size_in_tbs = "1" | |
db_name = "OLTP" | |
#Optional | |
db_workload = "OLTP" | |
display_name = "OLTP" | |
is_free_tier = "true" | |
whitelisted_ips = ["${oci_core_vcn.test_vcn.id}"] | |
} | |
# autonomoud database (DWH) | |
resource "oci_database_autonomous_database" "test_autonomous_database_dw" { | |
#Required | |
admin_password = "${var.autonomous_database_admin_password}" | |
compartment_id = "${oci_identity_compartment.test_compartment.id}" | |
cpu_core_count = "1" | |
data_storage_size_in_tbs = "1" | |
db_name = "DW" | |
#Optional | |
db_workload = "DW" | |
display_name = "DW" | |
is_free_tier = "true" | |
whitelisted_ips = ["${oci_core_vcn.test_vcn.id}"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment