Skip to content

Commit 13ba418

Browse files
committed
terraformscaffold v1.2.0 - Bootstrapping migrated into main script
1 parent 61565b9 commit 13ba418

File tree

8 files changed

+331
-379
lines changed

8 files changed

+331
-379
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.0 (09/06/2017)
2+
3+
* Merge bootstrap functionality into the main script
4+
15
## 1.1.4 (16/05/2017)
26

37
* Global and Region scoped variables files

README.md

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ Terraform scaffold consists of a terraform wrapper bash script, a bootstrap scri
88

99
| Thing | Things about the Thing |
1010
|-------|------------------------|
11-
| bin/terraform.sh | The master terraform wrapper script |
12-
| bootstrap/bootstrap.sh | The S3 bucket bootstrapping script |
11+
| bin/terraform.sh | The terraformscaffold script |
12+
| bootstrap/ | The bootstrap terraform code used for creating the terraformscaffold S3 bucket |
1313
| components/ | The location for terraform "components". Terraform code intended to be run directly as a root module. |
1414
| etc/ | The location for environment-specific terraform variables files:<br/>`env_{region}_{environment}.tfvars`<br/>`versions_{region}_{environment}.tfvars` |
1515
| lib/ | Optional useful libraries, such as Jenkins pipeline groovy script |
1616
| modules/ | The optional location for terraform modules called by components |
17+
| src/ | The optional location for source files, e.g. source for lambda functions zipped up into artefacts inside components |
1718

1819
## Concepts & Assumptions
1920

@@ -63,48 +64,38 @@ On invocation, Scaffold checks for a file at _s3://${bucket}/${project}/secrets/
6364

6465
## Usage
6566
### Bootstrapping
66-
Before using Scaffold, a bootstrapping stage is required. Scaffold is responsible for creating and maintaining the S3 buckets it uses to store component state files and even keeps the state file that defines the scaffold bucket in the same bucket. This is done with a script specifically designed to run a basic apply of the bootstrap code to create the bucket, and then configures the created bucket as a remote state location for itself. Once the bucket has been created, it can then be used for any terraform apply for the specific combination of project, region and AWS account.
67+
Before using Scaffold, a bootstrapping stage is required. Scaffold is responsible for creating and maintaining the S3 buckets it uses to store component state files and even keeps the state file that defines the scaffold bucket in the same bucket. This is done with a special bootstrap mode within the script, invoked with the '--bootstrap' parameter. When used with the "apply" action, this will cause the script to create a bootstrap bucket and then configure the bucket as a remote state location for itself. nd upload the tfstate used for managing the bucket to the bucket. Once created, the bucket can then be used for any terraform apply for the specific combination of project, region and AWS account.
6768

68-
It is not recommended to modify the bootstrap code after creation as direct application of modified bootstrap code risks the integrity of the state files stored in the bucket; however this can be mitigated by configuring synchronisation with a master backup bucket external to Scaffold management.
69+
It is not recommended to modify the bootstrap code after creation as it risks the integrity of the state files stored in the bucket that manage other deployments; however this can be mitigated by configuring synchronisation with a master backup bucket external to Scaffold management.
6970

70-
The bootstrap script lives at bootstrap/bootstrap.sh and its usage as of 25/01/2017 is:
71+
Bootstrapping usage:
72+
73+
```bash
74+
bin/bootstrap.sh \
75+
-p/--project `project` \
76+
-b/--bucket-prefix `bucket_prefix` \
77+
-r/--region `region` \
78+
--bootstrap \
79+
-a/--action plan
80+
```
7181

7282
```bash
7383
bootstrap/bootstrap.sh \
7484
-p/--project `project` \
7585
-b/--bucket-prefix `bucket_prefix` \
76-
-r/--region `region`
86+
-r/--region `region` \
87+
--bootstrap \
88+
-a/--action apply
7789
```
7890

7991
Where:
8092
* `project`: the name of the project to have a terraform bootstrap applied
8193
* `bucket_prefix` (optional - use only with caution): Defaults to: `${project}-terraformscaffold"`
8294
* `region` (optional): Defaults to value of the AWS_DEFAULT_REGION environment variable
8395

84-
Aside from the parameter management and other simple bash constructs, the bootstrapping process in the script is three basic steps:
85-
86-
```bash
87-
# Create bootstrap bucket
88-
terraform apply \
89-
-var "project=${project}" \
90-
-var "bucket_name=${bucket}" \
91-
-var "aws_account_id=${aws_account_id}"
92-
93-
# Setup Terraform Remote State
94-
terraform remote config \
95-
-backend=S3 -backend-config="region=${region}" \
96-
-backend-config="bucket=${bucket}" \
97-
-backend-config="key=${project}/${aws_account_id}/${region}/bootstrap/bootstrap.tfstate"
98-
99-
# Push Terraform Remote State to S3
100-
terraform remote push
101-
```
102-
103-
On the to-do list for future development is to make the bootstrap script check for the presence of an existing bucket and state file, and - if found - to configure it as the remote state prior to application. The current implementation assumes that you will only run bootstrap once, or if you run it a second time, you know what you are doing and have prepared the presence of the state file if it is not still present from the initial run.
104-
10596
### Running
10697

107-
The main scaffold invocation script is bin/terraform.sh. Once a state bucket has been bootstrapped, bin/terraform.sh can be run to apply terraform code. Its usage as of 25/01/2017 is:
98+
The terraformscaffold script is invoked as bin/terraform.sh. Once a state bucket has been bootstrapped, bin/terraform.sh can be run to apply terraform code. Its usage as of 25/01/2017 is:
10899

109100
```bash
110101
bin/terraform.sh \

0 commit comments

Comments
 (0)