Migrating from a remote state to a server in Terraform 0.9

I downloaded terraform 0.9 and tried to follow the migration guide to transition from remote-statetobackend

But that does not work. I replaced:

data "terraform_remote_state" "state" {
  backend = "s3"
  config {
    bucket = "terraform-state-${var.environment}"
    key = "network/terraform.tfstate"
    region = "${var.aws_region}"
  }
}

from

terraform {
  backend "s3" {
    bucket = "terraform-backend"
    key = "network/terraform.tfstate"
    region = "us-west-2"
  }
}

but when I run terraforminit in one of my environment folders, I get:

Failure Warning: This environment is configured to use an outdated remote state. The remote state has changed significantly in Terraform 0.9. Update the remote state configuration to use the new backend, Settings. Currently, Terraform will continue to use the existing Settings. Deprecated remote state support will be removed in Terraform 0.11.

You can find the update guide here:

https://www.terraform.io/docs/backends/legacy-0-8.html

, . , S3 Bucket ? ?

+6
2

(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
+6

terraform . , tf .

trraform remote backend, .

. github . , . https://github.com/hashicorp/terraform/issues/12792

0

Source: https://habr.com/ru/post/1015873/


All Articles