Skip to content

Azure Devops with Terraform and Cisco ACI

Estimated time to read: 5 minutes

  • Originally Written: October, 2020

The following posts will guide you through the steps to build the environment.

Now that you've set the pipeline up and everything is working correctly, in this final part we'll look at the configuration files in the Github repo and explain what it all means.

Info

The following was used for the base of the pipeline configuration, with some changes made for this demo.

https://github.com/samanax/InfraProvisioning

Info

The demo is configured as an example and not necessarily ready for a production environment.

Code Example

https://github.com/conmurphy/intro-to-terraform-and-aci

Configuration Files

As you saw when setting up the demo, there are two sets of files within the Github repo​​​​​​​

  • Terraform configuration files – these contain the necessary details to configure ACI using Terraform.
  • Azure Pipeline configuration files – these are the files to run the pipeline, including the steps and jobs​​​​​​​

Terraform Configuration Files

You'll find all the configuration files for Terraform within the first terraform folder in the repo. You could split out the Terraform backend config from the ACI config however in this demo it has been consolidated.

config-app.tf

The name myWebsite in this example refers to the Terraform instance name of the aci_application_profile resource.

The Application Profile name that will be configured in ACI is my_website.

When referencing one Terraform resource from another, use the Terraform instance name (i.e. myWebsite).

config.tf

Only the key (name of the Terraform state file) has been statically configured in the S3 backend configuration. The bucket, region, access key, and secret key will all be passed through the command line arguments when running the "terraform init" command in the pipeline scripts.

terraform.tfvars

variables.tf

We need to define the variables that Terraform will use in the configuration. Here are the options to provide values for these variables:

  • Provide a default value in the variable definition below
  • Configure the terraform.tfvars file with default values as previously shown
  • Provide the variable values as part of the command line input

terraform apply –var ’tenant_name=tenant-01’

  • Use environmental variables starting with TF_VAR

export TF_VAR_tenant_name=tenant-01

  • Provide no default value in which case Terraform will prompt for an input when a plan or apply command runs

versions.tf

Azure Pipeline Configuration Files

You'll find all the configuration files for the Azure Pipeline within the root directory (azure-pipelines.yml), as well as in the pipelines folder in the repo.

azure-pipelines.yml

If you haven't used Azure Pipelines before, make sure to read through the documentation. Here is an overview snippet from the docs.

A pipeline is one or more stages that describe a CI/CD process. Stages are the major divisions in a pipeline. A stage is one or more jobs, which are units of work assignable to the same machine. A job is a linear series of steps. Steps can be tasks, scripts, or references to external templates. This hierarchy is reflected in the structure of a YAML file like:

Pipeline
  Stage A
      - Job 1
          - Step 1.1
          - Step 1.2
          - ...
      - Job 2
          - Step 2.1
          - Step 2.2
          - ...
  Stage B
...

You can export reusable sections of your pipeline to a separate file. These separate files are known as templates

https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema

The azure-pipelines.yml file is the entry point for the pipeline. It contains two stages, planning and applying, with each stage containing a job. Templates (plan.yml and apply.yml) are used to separate the steps into separate files.

Variables that we created in the pipeline setup are also passed to the files.

Reference: Conditions

plan.yml

apply.yml

Comments