Java教程

[DevOps] Terraform Remote State Management

本文主要是介绍[DevOps] Terraform Remote State Management,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Demo Code

In order to maintain your tfstate file properly, you MUST have versioning enabled on your S3 bucket.

Here is the code I used to create the backend.tf file. You'll need to update it with the name of your S3 bucket and the path to your terraform.tfstate file.

terraform {
    backend "s3" {
        bucket = "<Name of your S3 bucket>"
        key = "<Path To Your terraform.tfstate file>" 
        region = "us-east-1"
    }
}

Here is the code for terraform.tf used to create the S3 backend. You can model yours off my example, or be creative and create your own- just make sure you destroy any infrastructure you create!

provider "aws" {
  access_key = "<Your Access Key>"
  secret_key = "<Your Secret Key>"
  region = "us-east-1"
}

resource "aws_instance" "Backend" {
  count = "2"
  ami = "ami-0323c3dd2da7fb37d"
  instance_type = "t2.micro"
}

Save your backend.tf file with your terraform.tf (or main.tf file) in a working directory under your Terraform root directory. 

 

这篇关于[DevOps] Terraform Remote State Management的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!