In your $HOME directory, create a directory called tf-simple-infrastructure and change to that directory.
Copy
mkdir tf-simple-infrastructure
Copy
cd tf-simple-infrastructure
Copy the Terraform scripts from the tf-provider directory.
Copy
cp ../tf-provider/*.tf .
Note
Don't copy the state files (terraform.tfstate or terraform.tfstate.backup). These files contain the state of resources for their current directory. After you run the scripts in this new directory, you get a new state file.
Rename the outputs.tf file to outputs1.tf.
Copy
mv outputs.tf outputs1.tf
Copy the Terraform scripts from the tf-compartment directory.
Copy
cp ../tf-compartment/*.tf .
Note
Because you only need one provider file per directory, no harm is done when the copy command replaces one provider.tf file with another.
Rename the outputs.tf file to outputs2.tf.
Copy
mv outputs.tf outputs2.tf
Copy the Terraform scripts from the tf-compute directory.
Copy
cp ../tf-compute/*.tf .
Rename the outputs.tf file to outputs3.tf.
Copy
mv outputs.tf outputs3.tf
Copy the Terraform scripts from the tf-vcn directory.
The availability-domains.tf and compartment.tf files both point to the <tenancy-ocid>. For example, the compartment.tf file points to the tenancy as its parent compartment and then creates a compartment underneath it. Don't edit the compartment_id in these two files.
Except for availability-domains.tf and compartment.tf files, in the remaining files that result from your grep command, replace compartment_id = "<compartment-ocid>" with:
In the tutorial Create a Compute Instance, you hard-coded the public subnet that hosts the compute instance. Now, update the compute.tf file to reference the public-subnet-OCID from the public-subnet.tf file.
Find how subnet OCID is referenced in the outputs.tf file.
Copy
grep -R subnet outputs.tf
Example output:
...
# Outputs for private subnet
output "private-subnet-name" {
value = oci_core_subnet.vcn-private-subnet.display_name
output "private-subnet-OCID" {
value = oci_core_subnet.vcn-private-subnet.id
# Outputs for public subnet
output "public-subnet-name" {
value = oci_core_subnet.vcn-public-subnet.display_name
output "public-subnet-OCID" {
value = oci_core_subnet.vcn-public-subnet.id
Copy the value for the public subnet OCID into your notepad:
Initialize a working directory in the tf-simple-infrastructure directory.
Copy
terraform init
Create an execution plan and review the changes that Terraform plans to make to your account:
Copy
terraform plan
Example output:
....
Terraform will perform the following actions:
# oci_core_instance.ubuntu_instance will be created
....
Plan: 14 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ all-availability-domains-in-your-tenancy = [
....
Create your simple infrastructure with
Terraform:
Copy
terraform apply
When
prompted for confirmation, enter yes, for your resources to
be created.
Congratulations! You have successfully created a simple infrastructure using Terraform, in
your Oracle Cloud Infrastructure account.
Now that you know how to use data sources, resources and modules, go ahead and add new objects from Oracle Cloud Infrastructure Provider to your simple infrastructure.
To explore more information about development with Oracle products, check out these
sites: