(https://www.terraform.io/docs/backends/legacy-0-8.html) terraform init
terraform plan
, , s3.
, - script ${application_name}/${env}/${project}
.
, :
βββ projects
β βββ application-name
β βββ dev
β β βββ bastion
β β βββ db
β β βββ vpc
β β βββ web-cluster
β βββ prod
β β βββ bastion
β β βββ db
β β βββ vpc
β β βββ web-cluster
β βββ backend.config
βββ run-tf.sh
application_name/env/component = (.. dev/vpc) :
backend.tf
:
terraform {
backend "s3" {
}
}
:
β βββ prod
β β βββ vpc
β β β βββ backend.tf
β β β βββ main.tf
β β β βββ outputs.tf
β β β βββ variables.tf
"application_name/" "application_name/env" backend.config, :
bucket = "BUCKET_NAME"
region = "region_name"
lock = true
lock_table = "lock_table_name"
encrypt = true
script application-name
, environment
, component
terraform cmd
.
run -tf.sh script ():
#!/bin/bash
application=$1
envir=$2
component=$3
cmd=$4
tf_backend_config="root_path/$application/$envir/$component/backend.config"
terraform init -backend=true -backend-config="$tf_backend_config" -backend-config="key=tfstate/${application}/${envir}/${component}.json"
terraform get
terraform $cmd
run -tf.sh:
$ run-tf.sh application_name dev vpc plan
$ run-tf.sh application_name prod bastion apply