This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from rhythmictech/terraform-v0.13.x
Terraform v0.13.x
- Loading branch information
Showing
10 changed files
with
175 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.12.24 | ||
0.13.6 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../Makefile |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/env bash -e | ||
|
||
# | ||
# this script is used for bootstraping a new project in your AWS account | ||
# | ||
|
||
new_folder=$1 | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
# authoritative backend file | ||
backend_file="account/backend.auto.tfvars" | ||
|
||
# remote state variables | ||
tfstate_bucket="" | ||
region="us-east-1" | ||
dynamodb_table="tf-locktable" | ||
|
||
|
||
function usage() { | ||
cat <<EOF | ||
Usage: bin/new-project.sh FOLDER_NAME | ||
Creates new folder with common files for another cloud component defined in terraform. | ||
EOF | ||
} | ||
|
||
function check_for_errors() { | ||
if [ -z $new_folder ]; then | ||
echo "ERROR: no new folder specified" | ||
usage | ||
exit 1 | ||
fi | ||
if [ -d $new_folder ]; then | ||
echo "ERROR: $new_folder already exits" | ||
usage | ||
exit 1 | ||
fi | ||
} | ||
|
||
function get_backend_variables() { | ||
echo "Getting backend variables from $backend_file" | ||
while read line; do | ||
key=$(echo $line | sed -E 's/([a-zAZ_]*)([ =]*)(.*)/\1/') | ||
value=$(echo $line | sed -E 's/([a-zAZ_]*)([ =]*)(.*)/\3/') | ||
case $key in | ||
bucket) | ||
tfstate_bucket=$value | ||
;; | ||
region) | ||
region=$value | ||
;; | ||
dynamodb_table) | ||
dynamodb_table=$value | ||
;; | ||
*) | ||
;; | ||
esac | ||
|
||
done <$backend_file | ||
} | ||
|
||
function create_new_folder() { | ||
echo "creating new folder, $new_folder" | ||
mkdir $new_folder | ||
|
||
cd $new_folder | ||
|
||
echo "symlinking common files" | ||
ln -s ../common/* . | ||
echo "done creating new folder" | ||
} | ||
|
||
function create_backend_file() { | ||
new_backend="backend.auto.tfvars" | ||
touch $new_backend | ||
echo "bucket = $tfstate_bucket" >> $new_backend | ||
echo "key = \"$new_folder.tfstate\"" >> $new_backend | ||
echo "dynamodb_table = $dynamodb_table" >> $new_backend | ||
echo "region = $region" >> $new_backend | ||
} | ||
|
||
function create_readme() { | ||
echo "# $new_folder" > README.md | ||
cat <<EOT >> README.md | ||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
## Outputs | ||
| Name | Description | | ||
|------|-------------| | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
EOT | ||
|
||
} | ||
|
||
function create_terraform_files() { | ||
create_readme | ||
|
||
echo "include ../Makefile" > Makefile | ||
|
||
touch main.tf | ||
touch variables.tf | ||
touch outputs.tf | ||
|
||
create_backend_file | ||
} | ||
|
||
function main() { | ||
check_for_errors | ||
get_backend_variables | ||
create_new_folder | ||
create_terraform_files | ||
|
||
echo 'done' | ||
} | ||
|
||
main "$@" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash -e | ||
|
||
# | ||
# this script is used for bootstraping the project base infrastructure | ||
# | ||
|
||
# create base infra | ||
echo "Initializing tfstate" | ||
cd account/setup | ||
terraform init | ||
terraform apply -auto-approve | ||
cd ../.. | ||
|
||
# migrate local state to the remote with the s3 bucket and dynamodb table | ||
echo "Migrating tfstate to bucket" | ||
cd account | ||
cp setup/terraform.tfstate . | ||
terraform init -backend-config=backend.auto.tfvars | ||
rm terraform.tfstate | ||
cd .. |
This file contains 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
This file contains 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
This file contains 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