Git Product home page Git Product logo

go-tfdr's Introduction

Terraform

Terraform Workspace State CLI

Build Test Release Downloads Latest Commit Go Report

Synopsis

Go cli to copy terraform state file from one terraform cloud workspace to another or to delete terraform state of specified resources from a workspace. This cli can be used in a disaster recovery scenario where new infrastructure needs to be set up for select resources in a template. For example, if some infrastructure is set up in AWS using a terraform template and a region failure occurs, this cli can be used while setting up new infrastructure in a new region.

Usage

tfdr [command]

Usage Docs

Example Disaster Recovery Steps

Here is an exmple of how this cli could be used in a disaster recovery scenario. The following steps assumes there is already a terraform cloud workspace (test1) with a terraform template for setting up infrastructure

Steps

  1. Create a new terraform workspace (test2) for the disaster recovery infrastructure
  2. Create a json file (filters.json) with the list of resources whose state we need to copy over from one workspace to another
  3. Run the following command to copy state from the original workspace to the new workspace
    tfdr state copy -f filters.json -o test1 -n test2
    
  4. Plan and apply the new workspace
  5. Run the following command to delete state of the copied over resources from the original workspace
    tfdr state delete -f filters.json -w test1
    

Example filters.json file

  • global_resource_types contains any resource types you would like to be moved to the new workspace regardless of resource or module name. In the example below, this list was populated with global AWS resources. While copying infrastructure from one AWS region to another, global AWS resources that do not have any region should not be re-created. This property allows us to copy the state of those global AWS resources when setting up a disaster recovery infrastructure.
  • filters contains a list of specific resources in the terrafrom template to copy state of.
    • filter_properties contains information about the resource whose state we want to copy.
    • new_properties can contain any properties in the state we would like to replace for that resource. Currently the cli allows updating the name of the copied over resource or any instance attributes in the state of the copied over resource.
{
    "global_resource_types": [
        "aws_cloudfront_distribution",
        "aws_cloudfront_origin_access_identity",
        "aws_iam_access_key",
        "aws_iam_policy_document",
        "aws_iam_policy",
        "aws_iam_role_policy_attachment",
        "aws_iam_role_policy",
        "aws_iam_role",
        "aws_iam_user_policy",
        "aws_iam_user",
        "aws_route53_record"
    ],
    "filters": [
        {
            "filter_properties": {
                "module": "module.test_module_1",
                "type": "type_1",
                "name": "orig_name_1"
            },
            "new_properties": {
                "name": "new_name_1",
                "attributes": {
                    "attr1": "new_value_1",
                    "attr2": ""
                }
            }
        },
        {
            "filter_properties": {
                "module": "module.test_module_2",
                "type": "type_2",
                "name": "orig_name_2"
            },
            "new_properties": {
                "name": "new_name_2"
            }
        },
        {
            "filter_properties": {
                "module": "module.test_module_3",
                "type": "type_3",
                "name": "orig_name_3"
            },
            "new_properties": {
                "name": "new_name_3",
                "attributes": {
                    "attr1": "new_value_3",
                    "attr2": "new_value_3b"
                }
            }
        }
    ]
}

go-tfdr's People

Contributors

mukta-puri avatar tyler-branch-protector[bot] avatar

Watchers

 avatar

go-tfdr's Issues

Enable branch protection

Branch protection should be enabled for this repository. I can set that up for you. It looks like this repository does not have an admin-level team configured. Add a comment with the following text to add a team and apply branch protection:

/admin-teams my-team
/protect

If this repository is not meant to have branch protection (not recommended), comment with /ignore and I'll close the issue and stop bothering you.

If you will be configuring branch protection yourself you can ignore this issue. I'll close it the next time I check this repository.

See this for a full list of commands.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.