From 444426dcc49c7a17f9509371bc4f739a9d294da7 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 16:07:24 +0900 Subject: [PATCH 01/10] TEMP: terraform from local --- terraform/main.tf | 12 ++++++------ terraform/oci.tf | 3 ++- terraform/variable.tf | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 55a2445..6852505 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -1,9 +1,9 @@ terraform { - backend "remote" { - organization = "sksat" + #backend "remote" { + # organization = "sksat" - workspaces { - name = "yohanesu-infra" - } - } + # workspaces { + # name = "yohanesu-infra" + # } + #} } diff --git a/terraform/oci.tf b/terraform/oci.tf index f63dfb8..7745ffe 100644 --- a/terraform/oci.tf +++ b/terraform/oci.tf @@ -12,5 +12,6 @@ provider "oci" { tenancy_ocid = var.OCID_TENANCY user_ocid = var.OCID_USER fingerprint = var.OCID_FINGERPRINT - private_key = var.OCID_PRIVATE_KEY + #private_key = var.OCID_PRIVATE_KEY + private_key_path = var.OCID_PRIVATE_KEY_PATH } diff --git a/terraform/variable.tf b/terraform/variable.tf index 3fc9d35..4985aae 100644 --- a/terraform/variable.tf +++ b/terraform/variable.tf @@ -1,7 +1,8 @@ variable "OCID_TENANCY" {} variable "OCID_USER" {} variable "OCID_FINGERPRINT" {} -variable "OCID_PRIVATE_KEY" {} +#variable "OCID_PRIVATE_KEY" {} +variable "OCID_PRIVATE_KEY_PATH" {} variable "OCID_COMPARTMENT" {} variable "OCID_SUBNET" {} variable "OCID_SOURCE" {} From bd964935285de20d6694f6471d853352c859bb13 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 16:20:04 +0900 Subject: [PATCH 02/10] fix: use original VCN & subnet --- terraform/instance.tf | 2 +- terraform/network.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/instance.tf b/terraform/instance.tf index 4c653bb..15e9aa8 100644 --- a/terraform/instance.tf +++ b/terraform/instance.tf @@ -23,7 +23,7 @@ resource "oci_core_instance" "generated_oci_core_instance" { create_vnic_details { assign_private_dns_record = "true" assign_public_ip = "true" - subnet_id = oci_core_subnet.ubuntu_subnet.id + subnet_id = var.OCID_SUBNET } display_name = "ubuntu-01" instance_options { diff --git a/terraform/network.tf b/terraform/network.tf index 34d69c9..6857b76 100644 --- a/terraform/network.tf +++ b/terraform/network.tf @@ -1,7 +1,7 @@ resource "oci_core_subnet" "ubuntu_subnet" { compartment_id = var.OCID_COMPARTMENT - vcn_id = oci_core_vcn.ubuntu_vcn.id + vcn_id = var.OCID_VCN cidr_block = "10.0.0.0/24" ipv6cidr_block = "" From aab1915c4954351c8349039c1d77756da2068284 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 16:29:48 +0900 Subject: [PATCH 03/10] set source image directly --- terraform/instance.tf | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/terraform/instance.tf b/terraform/instance.tf index 15e9aa8..04774e1 100644 --- a/terraform/instance.tf +++ b/terraform/instance.tf @@ -39,9 +39,12 @@ resource "oci_core_instance" "generated_oci_core_instance" { ocpus = "1" } source_details { - boot_volume_size_in_gbs = "50" - source_id = var.OCID_SOURCE source_type = "image" + boot_volume_size_in_gbs = "50" + + # Ubuntu 20.04 + # https://docs.oracle.com/en-us/iaas/images/image/51111a15-54e5-4af7-adb9-cea542248147/ + source_id = "ocid1.image.oc1.ap-tokyo-1.aaaaaaaaxmfmyofygv4bmv533zrkpt5suie2cl5s5ajfx4f3dqv23c3vccpa" } } From 6bc5332d67de5bc1175365c6f7ce517af92a13b2 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 16:37:07 +0900 Subject: [PATCH 04/10] f --- terraform/instance.tf | 46 +++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/terraform/instance.tf b/terraform/instance.tf index 04774e1..a38fc5c 100644 --- a/terraform/instance.tf +++ b/terraform/instance.tf @@ -1,50 +1,62 @@ resource "oci_core_instance" "generated_oci_core_instance" { + compartment_id = var.OCID_COMPARTMENT + availability_domain = "dhYs:AP-TOKYO-1-AD-1" + fault_domain = "FAULT-DOMAIN-2" + + display_name = "ubuntu-01" + shape = "VM.Standard.A1.Flex" + + shape_config { + memory_in_gbs = "6" + ocpus = "1" + } + + source_details { + source_type = "image" + boot_volume_size_in_gbs = "50" + + # Ubuntu 20.04 + # https://docs.oracle.com/en-us/iaas/images/image/51111a15-54e5-4af7-adb9-cea542248147/ + source_id = "ocid1.image.oc1.ap-tokyo-1.aaaaaaaaxmfmyofygv4bmv533zrkpt5suie2cl5s5ajfx4f3dqv23c3vccpa" + } + agent_config { is_management_disabled = "false" is_monitoring_disabled = "false" + plugins_config { desired_state = "DISABLED" name = "Vulnerability Scanning" } + plugins_config { desired_state = "ENABLED" name = "Compute Instance Monitoring" } + plugins_config { desired_state = "DISABLED" name = "Bastion" } } + availability_config { recovery_action = "RESTORE_INSTANCE" } - availability_domain = "dhYs:AP-TOKYO-1-AD-1" - compartment_id = var.OCID_COMPARTMENT + create_vnic_details { assign_private_dns_record = "true" assign_public_ip = "true" subnet_id = var.OCID_SUBNET } - display_name = "ubuntu-01" + instance_options { are_legacy_imds_endpoints_disabled = "false" } + is_pv_encryption_in_transit_enabled = "true" + metadata = { "ssh_authorized_keys" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAs3X141dqN0IgcRzUo/0j1XVmy5/BcDD8RrXwygxdaX sksat@yohanesu" } - shape = "VM.Standard.A1.Flex" - shape_config { - memory_in_gbs = "6" - ocpus = "1" - } - source_details { - source_type = "image" - boot_volume_size_in_gbs = "50" - - # Ubuntu 20.04 - # https://docs.oracle.com/en-us/iaas/images/image/51111a15-54e5-4af7-adb9-cea542248147/ - source_id = "ocid1.image.oc1.ap-tokyo-1.aaaaaaaaxmfmyofygv4bmv533zrkpt5suie2cl5s5ajfx4f3dqv23c3vccpa" - } } - From e2192333b4717cf0357fbed9dff55ebfeb60429c Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 16:39:32 +0900 Subject: [PATCH 05/10] f1 --- terraform/network.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/network.tf b/terraform/network.tf index 6857b76..34d69c9 100644 --- a/terraform/network.tf +++ b/terraform/network.tf @@ -1,7 +1,7 @@ resource "oci_core_subnet" "ubuntu_subnet" { compartment_id = var.OCID_COMPARTMENT - vcn_id = var.OCID_VCN + vcn_id = oci_core_vcn.ubuntu_vcn.id cidr_block = "10.0.0.0/24" ipv6cidr_block = "" From 44b81e3806873d26a9fb48a4f9c9b627894dd781 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 17:26:10 +0900 Subject: [PATCH 06/10] fix network --- terraform/network.tf | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/terraform/network.tf b/terraform/network.tf index 34d69c9..8d18006 100644 --- a/terraform/network.tf +++ b/terraform/network.tf @@ -1,11 +1,26 @@ +resource "oci_core_vcn" "ubuntu_vcn" { + compartment_id = var.OCID_COMPARTMENT + + display_name = "ubuntu VCN" + dns_label = "defaultvcn" + is_ipv6enabled = false + + cidr_blocks = [ + "10.0.0.0/16" + ] +} + resource "oci_core_subnet" "ubuntu_subnet" { compartment_id = var.OCID_COMPARTMENT - vcn_id = oci_core_vcn.ubuntu_vcn.id - cidr_block = "10.0.0.0/24" - ipv6cidr_block = "" + display_name = "ubuntu subnet" + dns_label = "defaultsubnet24" + + vcn_id = oci_core_vcn.ubuntu_vcn.id + cidr_block = "10.0.0.0/24" + #ipv6cidr_block = "" + route_table_id = oci_core_vcn.ubuntu_vcn.default_route_table_id - dns_label = "subnet08240556" prohibit_internet_ingress = false prohibit_public_ip_on_vnic = false @@ -16,13 +31,18 @@ resource "oci_core_subnet" "ubuntu_subnet" { ] } -resource "oci_core_vcn" "ubuntu_vcn" { +resource "oci_core_internet_gateway" "default_oci_core_internet_gateway" { compartment_id = var.OCID_COMPARTMENT + display_name = "Internet Gateway Default OCI core vcn" + enabled = "true" + vcn_id = oci_core_vcn.ubuntu_vcn.id +} - dns_label = "vcn08240556" - is_ipv6enabled = false - - cidr_blocks = [ - "10.0.0.0/16" - ] +resource "oci_core_default_route_table" "default_oci_core_default_route_table" { + route_rules { + destination = "0.0.0.0/0" + destination_type = "CIDR_BLOCK" + network_entity_id = oci_core_internet_gateway.default_oci_core_internet_gateway.id + } + manage_default_resource_id = oci_core_vcn.ubuntu_vcn.default_route_table_id } From c9d62f3e8dcf0a97e5d9daaaf71ffe5c05d578d4 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 17:57:18 +0900 Subject: [PATCH 07/10] add x86 instance --- terraform/instance.tf | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/terraform/instance.tf b/terraform/instance.tf index a38fc5c..fc84c2c 100644 --- a/terraform/instance.tf +++ b/terraform/instance.tf @@ -60,3 +60,66 @@ resource "oci_core_instance" "generated_oci_core_instance" { "ssh_authorized_keys" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAs3X141dqN0IgcRzUo/0j1XVmy5/BcDD8RrXwygxdaX sksat@yohanesu" } } + +resource "oci_core_instance" "x86_test_instance" { + compartment_id = var.OCID_COMPARTMENT + availability_domain = "dhYs:AP-TOKYO-1-AD-1" + fault_domain = "FAULT-DOMAIN-2" + + display_name = "x86-ubuntu-01" + shape = "VM.Standard.E2.1.Micro" + + shape_config { + memory_in_gbs = "1" + ocpus = "1" + } + + source_details { + source_type = "image" + boot_volume_size_in_gbs = "50" + + # Ubuntu 20.04 Minimal + # https://docs.oracle.com/en-us/iaas/images/image/cc6e4086-515b-4254-99ea-171acc5e7460/ + source_id = "ocid1.image.oc1.ap-tokyo-1.aaaaaaaato55by5l2yabyitrv62utowyisopehtvqbjrui6vympbi5b57k7q" + } + + agent_config { + is_management_disabled = "false" + is_monitoring_disabled = "false" + + plugins_config { + desired_state = "DISABLED" + name = "Vulnerability Scanning" + } + + plugins_config { + desired_state = "ENABLED" + name = "Compute Instance Monitoring" + } + + plugins_config { + desired_state = "DISABLED" + name = "Bastion" + } + } + + availability_config { + recovery_action = "RESTORE_INSTANCE" + } + + create_vnic_details { + assign_private_dns_record = "true" + assign_public_ip = "true" + subnet_id = var.OCID_SUBNET + } + + instance_options { + are_legacy_imds_endpoints_disabled = "false" + } + + is_pv_encryption_in_transit_enabled = "true" + + metadata = { + "ssh_authorized_keys" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAs3X141dqN0IgcRzUo/0j1XVmy5/BcDD8RrXwygxdaX sksat@yohanesu" + } +} From 4e56fae23db5d4728c90453abe81959c1eae0ee9 Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 18:13:50 +0900 Subject: [PATCH 08/10] set defined subnet --- terraform/instance.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/instance.tf b/terraform/instance.tf index fc84c2c..0c396d3 100644 --- a/terraform/instance.tf +++ b/terraform/instance.tf @@ -47,7 +47,7 @@ resource "oci_core_instance" "generated_oci_core_instance" { create_vnic_details { assign_private_dns_record = "true" assign_public_ip = "true" - subnet_id = var.OCID_SUBNET + subnet_id = oci_core_subnet.ubuntu_subnet.id } instance_options { @@ -110,7 +110,7 @@ resource "oci_core_instance" "x86_test_instance" { create_vnic_details { assign_private_dns_record = "true" assign_public_ip = "true" - subnet_id = var.OCID_SUBNET + subnet_id = oci_core_subnet.ubuntu_subnet.id } instance_options { From c5e2e2a24bf8d7ed4827aa9521586c6a2aa6d85e Mon Sep 17 00:00:00 2001 From: sksat Date: Sun, 12 Dec 2021 18:17:18 +0900 Subject: [PATCH 09/10] set name --- terraform/instance.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/instance.tf b/terraform/instance.tf index 0c396d3..7250b9f 100644 --- a/terraform/instance.tf +++ b/terraform/instance.tf @@ -1,9 +1,9 @@ -resource "oci_core_instance" "generated_oci_core_instance" { +resource "oci_core_instance" "a1flex_instance01" { compartment_id = var.OCID_COMPARTMENT availability_domain = "dhYs:AP-TOKYO-1-AD-1" fault_domain = "FAULT-DOMAIN-2" - display_name = "ubuntu-01" + display_name = "arm-ubuntu-01" shape = "VM.Standard.A1.Flex" shape_config { From 48bb93b6bf2860b78f3cc16f786b62215f28cb9a Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 18 Dec 2021 22:46:33 +0900 Subject: [PATCH 10/10] Revert "TEMP: terraform from local" This reverts commit 444426dcc49c7a17f9509371bc4f739a9d294da7. --- terraform/main.tf | 12 ++++++------ terraform/oci.tf | 3 +-- terraform/variable.tf | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 6852505..55a2445 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -1,9 +1,9 @@ terraform { - #backend "remote" { - # organization = "sksat" + backend "remote" { + organization = "sksat" - # workspaces { - # name = "yohanesu-infra" - # } - #} + workspaces { + name = "yohanesu-infra" + } + } } diff --git a/terraform/oci.tf b/terraform/oci.tf index 7745ffe..f63dfb8 100644 --- a/terraform/oci.tf +++ b/terraform/oci.tf @@ -12,6 +12,5 @@ provider "oci" { tenancy_ocid = var.OCID_TENANCY user_ocid = var.OCID_USER fingerprint = var.OCID_FINGERPRINT - #private_key = var.OCID_PRIVATE_KEY - private_key_path = var.OCID_PRIVATE_KEY_PATH + private_key = var.OCID_PRIVATE_KEY } diff --git a/terraform/variable.tf b/terraform/variable.tf index 4985aae..3fc9d35 100644 --- a/terraform/variable.tf +++ b/terraform/variable.tf @@ -1,8 +1,7 @@ variable "OCID_TENANCY" {} variable "OCID_USER" {} variable "OCID_FINGERPRINT" {} -#variable "OCID_PRIVATE_KEY" {} -variable "OCID_PRIVATE_KEY_PATH" {} +variable "OCID_PRIVATE_KEY" {} variable "OCID_COMPARTMENT" {} variable "OCID_SUBNET" {} variable "OCID_SOURCE" {}