If you work with Terraform, you are quite familiar with the situation when a lot of resources have already been deployed manually. What options do we have in such a case? The first one is to use the native Terraform Resource Discovery and create the state file, which can be imported to your enterprise configuration. But if you plan to use Resource Manager in OCI, you can use the new Resource Manager Discovery feature. It creates a stack discovering your resources in a compartment.
Let’s see how it works. In my Ashburn region, I have a regional network with private and public subnets, three compute instances, and a MySQL database. All the resources were deployed manually from the console or command line without using OCI Resource Manager.
Now I am going to the Resource manager page and push the button “Create Stack”.
When you do that, you have four options, and the last one is to create a stack from the existing configuration using already deployed resources.
You can choose whether you want all services in the compartment or only a specific subset of resources. It would be nice to choose based on the compartment and tags, but it is not an option for now. Also, please be aware the sub-compartments are not going to be included.
Then you push next, next again and finally, after pushing the “Create” button, you are going to get running Oracle Resource Manager stack with all your selected resources in the compartment. That can be an excellent first step in adopting Infrastructure as Code (IaC) approach in your environment.
For those who are just started with Terraform and Resource Manager, it can be a good training material and syntax template. You can download the zip file with the terraform configuration, modify it, zip it back, and edit the stack by pushing the “Edit Stack” button to upload the new configuration.
If you have a look inside the zip file, you will see normal terraform files that could be used as a basis for your future Resource Manager deployment. The zip file contains a dedicated “*.tf” file for each group of resources. I don’t have most of them, and as a result, many “tf” files are empty.
otochkin$ ll total 328 -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 analytics.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 apigateway.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 auto_scaling.tf -rw-rw-r--@ 1 otochkin staff 462B 12 Aug 2020 availability_domain.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 bds.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 containerengine.tf -rw-rw-r--@ 1 otochkin staff 18K 12 Aug 2020 core.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 data_safe.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 database.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 datacatalog.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 dataflow.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 dataintegration.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 datascience.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 dns.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 email_compartment.tf -rw-rw-r--@ 1 otochkin staff 999B 12 Aug 2020 events.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 file_storage.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 functions.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 health_checks.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 integration.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 kms.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 load_balancer.tf -rw-rw-r--@ 1 otochkin staff 1.8K 12 Aug 2020 marketplace.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 monitoring.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 mysql.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 nosql.tf -rw-rw-r--@ 1 otochkin staff 1.5K 12 Aug 2020 object_storage.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 oce.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 ocvp.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 oda.tf -rw-rw-r--@ 1 otochkin staff 648B 12 Aug 2020 ons.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 osmanagement.tf -rw-rw-r--@ 1 otochkin staff 38B 12 Aug 2020 provider.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 streaming.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 tagging.tf -rw-rw-r--@ 1 otochkin staff 596B 12 Aug 2020 vars.tf -rw-rw-r--@ 1 otochkin staff 63B 12 Aug 2020 waas.tf otochkin$ cat apigateway.tf ## This configuration was generated by terraform-provider-oci
Most of the resources are concentrated in the “core.tf” file where we can see all compute instances and other resources, including network and database.
otochkin$ cat core.tf ## This configuration was generated by terraform-provider-oci resource oci_core_instance export_app-forms-01 { agent_config { is_management_disabled = "false" is_monitoring_disabled = "false" } availability_domain = data.oci_identity_availability_domain.export_gwmA-US-ASHBURN-AD-1.name compartment_id = var.compartment_ocid create_vnic_details { assign_public_ip = "true" defined_tags = { ...
I think the new feature is one of the key improvements that help administrators adopt the automated deployment and management framework. The next blog is about using version control for your terraform in the Oracle cloud. Stay tuned.