The Personal Blog of Todd Sharp

IaC in the Cloud: Integrating Terraform and Resource Manager into your CI/CD Pipeline - Building Natively

Posted By: Todd Sharp on 3/19/2021 12:00 GMT
Tagged: Cloud, Cloud, Cloud Native, Cloud Native

Welcome to the final post in this series about using Terraform to manage infrastructure in the Oracle Cloud. In the last post, we looked at how to use the OCI CLI in our GitHub Actions pipeline to execute our Terraform scripts via creating stacks and jobs with Resource Manager. In this post, we’ll simplify the concept and make it a bit more portable by using native Terraform in our GitHub Actions pipeline. You’ll lose a bit of the power and flexibility of Resource Manager, but if you’re just looking to simply build and maintain your infrastructure, this solution is perfectly great for you!

If you've missed the previous posts in this series, here is a list to catch up:

Building Infrastructure From Your Pipeline

Just like in our last post, we’ll need some secret values so that we can execute our Terraform scripts from our CI/CD pipeline. Set some secrets for the following values from your tenancy. 

Running With Terraform

Using the OCI CLI to build our Terraform scripts via Resource Manager is nice, but if you remember from our last post, it wasn’t exactly a quick process since we had to install the CLI and all of the Terraform script execution happened in our cloud tenancy instead of on the pipeline/build server. Let’s see if we can improve the build times (and reduce a bit of the build script complexity) by executing our scripts natively in the pipeline. 

We’ll start by defining our pipeline as we did before in a file called build.yaml

Note: Like before, we’ll use the same GitHub project, but again branched:

We’ve defined our environment variables again, but this time we prefixed them with TF_VAR_ which, if you remember back to an earlier post in this series, is a special prefix that Terraform will pick up on and set our script variables accordingly. Next, checkout the code and configure the Hashicorp "setup-terraform" plugin which will install Terraform in our build environment.

That’s all the config we need. Now we can run our scripts directly via the Terraform CLI as we did earlier in this series when we ran them manually on our own machine. Add steps to initialize Terraform and validate our script(s):

Then run terraform plan and terraform apply.

Check in and push the build and once again the pipeline will be executed automatically. 

But this time, we get a much faster execution - from 3 minutes 17 seconds down to 13 total seconds. 


In this post, we looked at executing our Terraform scripts to build our infrastructure in our CI/CD pipeline using the native Terraform CLI. 

Series Summary

In this series, we have focused on Infrastructure as Code. From the very basic intro to Terraform for developers, to integrating our solution into our CI/CD pipeline we have dug deep into every aspect of automating our infrastructure and hopefully you have learned the basics and benefits of using using this solution in your cloud native applications. As always, please feel free to provide me your feedback and check me out on Twitter.

Photo by Pete Gontier on Unsplash

Related Posts

Running Database Queries With REST via a Database Tools Connection (IE: The Super Easy Way)

Running Database Queries With REST via a Database Tools Connection (IE: The Super Easy Way)

I recently blogged about a brand-new service in the Oracle Cloud - Database Tools. It's a safe, secure way to store your database credentials in the...

Easy and Secure Oracle Database Connections With Database Tools

Easy and Secure Oracle Database Connections With Database Tools

There's a brand new tool in town, and it's ready to make your life a whole lot easier if you work with Oracle DB in the cloud. It's called "Database Tools...

Securely Connecting to Autonomous DB Without a Wallet (Using TLS)

Securely Connecting to Autonomous DB Without a Wallet (Using TLS)

I talk to a lot of developers in my job as a Developer Advocate. Sometimes they've been using the products in the Oracle Cloud for a long time, and sometimes...

Note: Comments are currently closed on this blog. Disqus is simply too bloated to justify its use with the low volume of comments on this blog. Please visit my contact page if you have something to say!