Created
October 30, 2020 21:04
-
-
Save nitrocode/65ef493ced71cef0a15f9c6c605c3042 to your computer and use it in GitHub Desktop.
Create the most awesome s3 backend.tf file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # provide the s3 bucket as the first param | |
| export s3Bucket=${1:-bananananananana} | |
| # get repo name | |
| export repoName=$(git config --get remote.origin.url | cut -d '/' -f2 | cut -d '.' -f1) | |
| # get current directory | |
| export repoDir=$(git rev-parse --show-prefix | rev | cut -c 2- | rev) | |
| # create backend | |
| cat <<EOF > backend.tf | |
| terraform { | |
| required_version = ">=0.12" | |
| backend "s3" { | |
| encrypt = true | |
| bucket = "$s3Bucket" | |
| dynamodb_table = "TerraformLock" | |
| region = "us-west-2" | |
| key = "$repoName/$repoDir/terraform.tfstate" | |
| } | |
| } | |
| EOF | |
| # see the newly created file just to be safe | |
| cat backend.tf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment