Giter VIP home page Giter VIP logo

go-tools-tfc-backup's Introduction

GO Tools: terraform-cloud-backup

This tool saves the last Terraform state in S3. These are the resources needed: terraform-cloud-backup

Author

Mariano Sanfilippo

Usage

You can build this lambda on your own and upload it to S3, or you can fork this repo and set up the GitHub Secrets to having the complete workflow.

Automated Build

  • Fork this repository
  • Setup the following GitHub Secrets
    • FUNCTION_NAME
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    • AWS_REGION
    • TF_TOKEN (Terraform Cloud token)
    • BUCKET (Bucket to save the Terraform states.)
    • BUCKET_BUILDS

Manual Build

  GOOS=linux GOARCH=amd64 CGO_ENABLED=0 
  go mod tidy 
  go build -ldflags="-s -w" -a -installsuffix cgo -o main main.go
  zip main.zip main

go-tools-tfc-backup

Index

func DownloadBody(url string) (string, error)
func GetLastStateVersion(workspaceId string) (*tfe.StateVersion, error)

func Handler

func Handler(ctx context.Context, event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
func SaveLastState(payload Payload) (string, error)
func StatusModified(payload Payload) bool
func UploadToS3(key string, body string) error

type Payload

type Payload struct {
    PayloadVersion              int       `json:"payload_version"`
    NotificationConfigurationID string    `json:"notification_configuration_id"`
    RunURL                      string    `json:"run_url"`
    RunID                       string    `json:"run_id"`
    RunMessage                  string    `json:"run_message"`
    RunCreatedAt                time.Time `json:"run_created_at"`
    RunCreatedBy                string    `json:"run_created_by"`
    WorkspaceID                 string    `json:"workspace_id"`
    WorkspaceName               string    `json:"workspace_name"`
    OrganizationName            string    `json:"organization_name"`
    Notifications               []struct {
        Message      string    `json:"message"`
        Trigger      string    `json:"trigger"`
        RunStatus    string    `json:"run_status"`
        RunUpdatedAt time.Time `json:"run_updated_at"`
        RunUpdatedBy string    `json:"run_updated_by"`
    }   `json:"notifications"`
}

Generated by gomarkdoc

go-tools-tfc-backup's People

Contributors

mnsanfilippo avatar

Watchers

 avatar  avatar

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.