Friday, 19 February 2021

Introduction to Terraform with ACI – Part 3

Cisco Developer, Cisco ACI, Cisco DevNet, Cisco Network Automation, Cisco Terraform, Cisco Preparation, Cisco Exam Prep

If you haven’t already seen the previous Introduction to Terraform posts, please have a read through. This “Part 3” will provide an explanation of the various configuration files you’ll see in the Terraform demo.

Introduction to Terraform

Terraform and ACI

Code Example

https://github.com/conmurphy/terraform-aci-testing/tree/master/terraform

Configuration Files

You could split out the Terraform backend config from the ACI config however in this demo it has been consolidated. 

Cisco Developer, Cisco ACI, Cisco DevNet, Cisco Network Automation, Cisco Terraform, Cisco Preparation, Cisco Exam Prep

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“).

Cisco Developer, Cisco ACI, Cisco DevNet, Cisco Network Automation, Cisco Terraform, Cisco Preparation, Cisco Exam Prep

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 would be passed through the command line arguments when running the “terraform init” command. See the following for more detail on the various options to set these arguments.


Cisco Developer, Cisco ACI, Cisco DevNet, Cisco Network Automation, Cisco Terraform, Cisco Preparation, Cisco Exam Prep

terraform.tfvars

Cisco Developer, Cisco ACI, Cisco DevNet, Cisco Network Automation, Cisco Terraform, Cisco Preparation, Cisco Exam Prep

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

Cisco Developer, Cisco ACI, Cisco DevNet, Cisco Network Automation, Cisco Terraform, Cisco Preparation, Cisco Exam Prep

versions.tf

Cisco Developer, Cisco ACI, Cisco DevNet, Cisco Network Automation, Cisco Terraform, Cisco Preparation, Cisco Exam Prep

Source: cisco.com

Related Posts

0 comments:

Post a comment