Terraform in OCI
1.      
Generate API keys from command
prompt
| 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ pwd 
/c/Users/debaranw/.ssh 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ openssl genrsa -out oci_api_key.pem 2048 
Generating RSA private key, 2048 bit long modulus (2
  primes) 
.....................................+++++ 
.....................................+++++ 
e is 65537 (0x010001) 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ dir 
id_rsa 
  id_rsa.pub  known_hosts  oci_api_key.pem 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ openssl rsa -pubout -in oci_api_key.pem -out
  oci_api_key_public.pem 
writing RSA key 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ dir 
id_rsa 
  id_rsa.pub  known_hosts  oci_api_key.pem  oci_api_key_public.pem 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ ls -lrt 
total 14 
-rw-r--r-- 1 debaranw 197121 1831 Jul  1 09:43 id_rsa 
-rw-r--r-- 1 debaranw 197121  402 Jul 
  1 09:43 id_rsa.pub 
-rw-r--r-- 1 debaranw 197121 1353 Jul 16 11:27 known_hosts 
-rw-r--r-- 1 debaranw 197121 1706 Jul 18 11:01
  oci_api_key.pem 
-rw-r--r-- 1 debaranw 197121  460 Jul 18 11:12 oci_api_key_public.pem 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ cat oci_api_key_public.pem 
-----BEGIN PUBLIC KEY----- 
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlrCoUaj+4oMECD4Gyhet 
j0NmZ1dwMTaKQWEDy0KAUVRbUKJeoB0GH60y7Jh566aswRDXowZBlKvxOUL5XL+t 
pZc18yMhpKWbq5wq9+43ut0IjrLZNl2D1jBqxvOp2oqTO7uPRKoRlywcHtDri0pT 
fSq5Em8dQIrrmcaFKD5PXi/+KRc1KR5kOcxkOxnBTlIiAUPmusmuL5qIosMA5G/M 
EhZPtipgddAVcpunCO9L9NBo1rEUiTv0LAH253MGrw+YQ+2eRYWqMnyWuzGkRyym 
m0sT9FWp8En2lo2HdB+dg440U6AoPCheftzH8gGzDd0Je1b1x12SCkuRj+v1/1i7 
SQIDAQAB 
-----END PUBLIC KEY----- 
debaranw@DEBARANW-IN MINGW64 ~/.ssh 
$ | 
2.      
Download and configure
Terraform
3.      
Set Environment Variable
| 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ export TF_VAR_tenancy_ocid=ocid1.tenancy.oc1..aaaaaaaa5kxrelenhoqbpg7olifnxkm5uefxvtysusm4xgoeqgotnmjasc5q 
export
  TF_VAR_fingerprint=f5:f2:7d:9c:f4:29:75:b8:8d:79:e7:af:fd:c9:ff:2f 
export
  TF_VAR_private_key_path=oci_api_key.pem 
### Region 
export
  TF_VAR_region=eu-frankfurt-1 
### Compartment 
export
  TF_VAR_compartment_ocid=ocid1.compartment.oc1..aaaaaaaaibjd3h7s64dv6sefbg6hvnche7sfnefpnlyifx5g2z6ccf2qdj2q 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ export
  TF_VAR_user_ocid=ocid1.user.oc1..aaaaaaaavdteylrqbpokvwbhjdz62b4d6g6squclzatzr5ukgu422nx2c5ba 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ export
  TF_VAR_fingerprint=f5:f2:7d:9c:f4:29:75:b8:8d:79:e7:af:fd:c9:ff:2f 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ export TF_VAR_private_key_path=oci_api_key.pem 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ ### Region 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ export
  TF_VAR_region=eu-frankfurt-1 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ ### Compartment 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ export
  TF_VAR_compartment_ocid=ocid1.compartment.oc1..aaaaaaaaibjd3h7s64dv6sefbg6hvnche7sfnefpnlyifx5g2z6ccf2qdj2q 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ vi vcn.tf 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
4.      
   | 
5.      
Initialize the terraform
| 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ terraform init 
Initializing
  the backend... 
Initializing
  provider plugins... 
- Checking for
  available provider plugins... 
Registry
  service unreachable. 
This may
  indicate a network issue, or an issue with the requested Terraform Registry. 
Error: registry service is unreachable, check
  https://status.hashicorp.com/ for status updates 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ terraform init 
Initializing
  the backend... 
Initializing
  provider plugins... 
- Checking for
  available provider plugins... 
- Downloading plugin
  for provider "oci" (terraform-providers/oci) 3.34.0... 
Terraform
  has been successfully initialized! 
You may
  now begin working with Terraform. Try running "terraform plan" to
  see 
any
  changes that are required for your infrastructure. All Terraform commands 
should
  now work. 
If you
  ever set or change modules or backend configuration for Terraform, 
rerun
  this command to reinitialize your working directory. If you forget, other 
commands
  will detect it and remind you to do so if necessary. 
debaranw@DEBARANW-IN
  MINGW64 /c/terraform/test 
$ | 
6.      
Check the environment variable
and run terraform plan
| 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test 
$ env|grep TF 
TF_VAR_compartment_ocid=ocid1.compartment.oc1..aaaaaaaaibjd3h7s64dv6sefbg6hvnche7sfnefpnlyifx5g2z6ccf2qdj2q 
TF_VAR_region=eu-frankfurt-1 
LANG=en_US.UTF-8 
TF_VAR_private_key_path=/c/Users/debaranw/.ssh/oci_api_key.pem 
TF_VAR_tenancy_ocid=ocid1.tenancy.oc1..aaaaaaaa5kxrelenhoqbpg7olifnxkm5uefxvtysusm4xgoeqgotnmjasc5q 
TF_VAR_user_ocid=ocid1.user.oc1..aaaaaaaavdteylrqbpokvwbhjdz62b4d6g6squclzatzr5ukgu422nx2c5ba 
TF_VAR_fingerprint=f5:f2:7d:9c:f4:29:75:b8:8d:79:e7:af:fd:c9:ff:2f 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test 
$ terraform plan 
Refreshing Terraform state in-memory prior to plan... 
The refreshed state will be used to calculate this plan,
  but will not be 
persisted to local or remote state storage. 
------------------------------------------------------------------------ 
An execution plan has been generated and is shown below. 
Resource actions are indicated with the following symbols: 
  + create 
Terraform will perform the following actions: 
  # oci_core_virtual_network.simple-vcn will be created 
  + resource "oci_core_virtual_network"
  "simple-vcn" { 
      + cidr_block               = "10.9.0.0/16" 
      + compartment_id           = "ocid1.compartment.oc1..aaaaaaaaibjd3h7s64dv6sefbg6hvnche7sfnefpnlyifx5g2z6ccf2qdj2q" 
      + default_dhcp_options_id  = (known after apply) 
      + default_route_table_id   = (known after apply) 
      + default_security_list_id = (known after apply) 
      + defined_tags             = (known after apply) 
      + display_name             = "simple-vcn" 
      + dns_label                = "testvcn1" 
      + freeform_tags            = (known after apply) 
      + id                       = (known after apply) 
      + state                    = (known after apply) 
      + time_created             = (known after apply) 
      + vcn_domain_name          = (known after apply) 
    } 
Plan: 1 to
  add, 0 to change, 0 to destroy. 
------------------------------------------------------------------------ 
Note: You didn't specify an "-out" parameter to
  save this plan, so Terraform 
can't guarantee that exactly these actions will be
  performed if 
"terraform apply" is subsequently run. 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test 
$ | 
| 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test 
$ terraform apply 
An execution plan has been generated and is shown below. 
Resource actions are indicated with the following symbols: 
  + create 
Terraform will perform the following actions: 
  # oci_core_virtual_network.simple-vcn will be created 
  + resource "oci_core_virtual_network"
  "simple-vcn" { 
      + cidr_block               = "10.9.0.0/16" 
      + compartment_id           =
  "ocid1.compartment.oc1..aaaaaaaaibjd3h7s64dv6sefbg6hvnche7sfnefpnlyifx5g2z6ccf2qdj2q" 
      + default_dhcp_options_id  = (known after apply) 
      + default_route_table_id   = (known after apply) 
      + default_security_list_id = (known after apply) 
      + defined_tags             = (known after apply) 
      + display_name             = "simple-vcn" 
      + dns_label                = "testvcn1" 
      + freeform_tags            = (known after apply) 
      + id                       = (known after apply) 
      + state                    = (known after apply) 
      + time_created             = (known after apply) 
      + vcn_domain_name          = (known after apply) 
    } 
Plan: 1 to
  add, 0 to change, 0 to destroy. 
Do you want to perform these actions? 
  Terraform will
  perform the actions described above. 
  Only 'yes' will be
  accepted to approve. 
  Enter a value:
  yes 
oci_core_virtual_network.simple-vcn: Creating... 
oci_core_virtual_network.simple-vcn: Creation complete
  after 2s [id=ocid1.vcn.oc1.eu-frankfurt-1.aaaaaaaaok6ypiurwudbpaqkqeujntabvljxouysm6xackt275si52ucqpvq] 
Apply complete! Resources: 1 added, 0
  changed, 0 destroyed. 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test 
$ 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test | 
|  | 
| 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test 
$ terraform destroy 
oci_core_virtual_network.simple-vcn: Refreshing state...
  [id=ocid1.vcn.oc1.eu-frankfurt-1.aaaaaaaaok6ypiurwudbpaqkqeujntabvljxouysm6xackt275si52ucqpvq] 
An execution plan has been generated and is shown below. 
Resource actions are indicated with the following symbols: 
  - destroy 
Terraform will perform the following actions: 
  #
  oci_core_virtual_network.simple-vcn will be destroyed 
  - resource "oci_core_virtual_network"
  "simple-vcn" { 
      - cidr_block               = "10.9.0.0/16" -> null 
      - compartment_id           =
  "ocid1.compartment.oc1..aaaaaaaaibjd3h7s64dv6sefbg6hvnche7sfnefpnlyifx5g2z6ccf2qdj2q"
  -> null 
      - default_dhcp_options_id  =
  "ocid1.dhcpoptions.oc1.eu-frankfurt-1.aaaaaaaaopepr6mcsm5ynnsr4qugfimz2w5l5laqaa5xh3jzs6fhbfs4r6ga"
  -> null 
      - default_route_table_id   =
  "ocid1.routetable.oc1.eu-frankfurt-1.aaaaaaaaq43ws44iotwcdsu6b46mjibmzcvcgyalk5qtfo4eknqsbeqjhtrq"
  -> null 
      - default_security_list_id =
  "ocid1.securitylist.oc1.eu-frankfurt-1.aaaaaaaax3zatlgrkmrqtsh7no674hxmm6u7tj3rwgmw5hyfp6zsu7gdjdkq"
  -> null 
      - defined_tags             = {} ->
  null 
      - display_name             = "simple-vcn" -> null 
      - dns_label                = "testvcn1" -> null 
      - freeform_tags            = {} ->
  null 
      - id                       =
  "ocid1.vcn.oc1.eu-frankfurt-1.aaaaaaaaok6ypiurwudbpaqkqeujntabvljxouysm6xackt275si52ucqpvq"
  -> null 
      - state                    = "AVAILABLE" -> null 
      - time_created             = "2019-07-18 06:35:56.175
  +0000 UTC" -> null 
      - vcn_domain_name          =
  "testvcn1.oraclevcn.com" -> null 
    } 
Plan: 0 to
  add, 0 to change, 1 to destroy. 
Do you really want to destroy all resources? 
  Terraform will
  destroy all your managed infrastructure, as shown above. 
  There is no undo.
  Only 'yes' will be accepted to confirm. 
  Enter a value:
  yes 
oci_core_virtual_network.simple-vcn: Destroying...
  [id=ocid1.vcn.oc1.eu-frankfurt-1.aaaaaaaaok6ypiurwudbpaqkqeujntabvljxouysm6xackt275si52ucqpvq] 
oci_core_virtual_network.simple-vcn: Destruction complete
  after 1s 
Destroy complete! Resources: 1 destroyed. 
debaranw@DEBARANW-IN MINGW64 /c/terraform/test 
$ | 
 
No comments:
Post a Comment