Back Home

Terraform uses configuration files that are named

A terraform project can consist of - defined variables e.g. variables.tf 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("mule_install.sh")}"
}

This example has

  #!/bin/bash
  yum update -y
  wget -O mule-standalone-3.9.0.zip https://repository-master.mulesoft.org/nexus/content/repositories/releases/org/mule/distributions/mule-standalone/3.9.0/mule-standalone-3.9.0.zip
  sudo yum install -y unzip
  unzip mule-standalone-3.9.0.zip 
  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”

Providers

Provisioner

In this example we used a script “file” to provision the applications. There are a number of out of the box provisioners https://www.terraform.io/docs/provisioners/index.html

  • 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