Back Home

Terraform uses configuration files that are named

A terraform project can consist of - defined variables e.g. that may be environment specific

variable "aws_access_key" {
  default     = "ACCESS_KEY_HERE"
  description = "the user aws access key"
variable "aws_secret_key" {
  default     = "SECRET_KEY_HERE"
  description = "the user aws secret key"
variable "region" {
  default = "us-east-2"
variable "ami_id_mule" {
  default     = "ami-f63b1193"
  description = "the id ami mule runtime 390"
provider "aws" {
  access_key = "${var.aws_access_key}"
  secret_key = "${var.aws_secret_key}"
  region     = "${var.region}"
resource "aws_instance" "mule-standalone" {
  ami           = "${var.ami_id_mule}"
  instance_type = "t2.small"
  key_name      = "mchuecosKey"
  user_data     = "${file("")}"

This example has

  yum update -y
  wget -O
  sudo yum install -y unzip
  sudo mule-standalone-3.9.0/bin/mule start

To run this project we

terraform init

this will download any required plugins, in this case provider “aws”



In this example we used a script “file” to provision the applications. There are a number of out of the box provisioners

  • file Provisioner
  • habitat Provisioner
  • local-exec Provisioner - run a command on the source local machine
 provisioner "local-exec" {
    command = "echo ${self.private_ip} > file.txt"

by default this is executed when the resources are created we can configure when these actions are executed by adding :

  • when = “destroy”
provisioner "local-exec" {
    when    = "destroy"
    command = "echo 'Destroy-time provisioner'"

Failure Actions

By default terraform will stop on errors. We can configure this with on_failure configuration:

provisioner "local-exec" {
    command    = "echo ${self.private_ip} > file.txt"
    on_failure = "continue"
  • remote-exec Provisioner

Terraform and Java - the Maven plugin

terraform_notes.txt · Last modified: 2019/11/25 03:46 by root
RSS - 200 © CrosswireDigitialMedia Ltd