Skip to content

Commit 7e20c4e

Browse files
committed
DOPS-101 Add bootstrap module for terraform project
1 parent ea197a8 commit 7e20c4e

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
.DS_Store
77
.vagrant
88
/env.sh
9-
/terraform/.terraform*
10-
/terraform/terraform.tfstate*
11-
/terraform/tf.plan
9+
/terraform/**/.terraform
10+
/terraform/**/terraform.tfstate*
11+
/terraform/**/tf.plan
1212
__pycache__
1313
build/
1414
tmp/

terraform/bootstrap/.terraform.lock.hcl

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/bootstrap/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Modus Devops Demo Bootstrap
2+
3+
This terraform module is used to bootstrap the backend for the `/terraform` project. It uses [trussworks/bootstrap/aws](https://github.com/trussworks/terraform-aws-bootstrap) module to create all the resources needed to enable terraform backend in AWS.
4+
5+
## How to use
6+
7+
```bash
8+
cd terraform/bootstrap
9+
terraform init
10+
terraform apply
11+
```
12+
13+
This will generate output which looks like this:
14+
15+
```
16+
backend_details = {
17+
"dynamodb_table" = "moduscreate-devops-demo-state-lock"
18+
"logging_bucket" = "moduscreate-devops-demo-tf-state-log-us-east-1"
19+
"state_bucket" = "moduscreate-devops-demo-tf-state-us-east-1"
20+
}
21+
```
22+
23+
It can then be used in the `terraform.backend` config of main project (not the bootstrap project).
24+
25+
```terraform
26+
terraform {
27+
# ... existing config
28+
29+
backend "s3" {
30+
bucket = "moduscreate-devops-demo-tf-state-us-east-1"
31+
key = "terraform-state.tfstate"
32+
dynamodb_table = "moduscreate-devops-demo-state-lock"
33+
region = "us-east-1"
34+
encrypt = "true"
35+
}
36+
}
37+
```
38+
39+
## Inputs
40+
41+
| Name | Description | Default |
42+
|-----------------|------------------------------|-------------------------|
43+
| `aws_region` | Amazon region to use | us-east-1 |
44+
| `account_alias` | Prefix for backend resources | moduscreate-devops-demo |

terraform/bootstrap/main.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4.16"
6+
}
7+
}
8+
9+
required_version = "~> 1.2.0"
10+
}
11+
12+
provider "aws" {
13+
region = var.aws_region
14+
}
15+
16+
module "bootstrap" {
17+
source = "trussworks/bootstrap/aws"
18+
19+
region = var.aws_region
20+
account_alias = var.account_alias
21+
dynamodb_table_name = "${var.account_alias}-state-lock"
22+
}
23+
24+
data "aws_caller_identity" "current" {}
25+
26+
output "account_id" {
27+
value = "${data.aws_caller_identity.current.account_id}"
28+
}
29+
30+
output "arn" {
31+
value = "${data.aws_caller_identity.current.arn}"
32+
}
33+
34+
output "user_id" {
35+
value = "${data.aws_caller_identity.current.user_id}"
36+
}
37+
38+
output "backend_details" {
39+
description = "Details of the S3 bucket and DynamoDB tables created for backend"
40+
value = module.bootstrap
41+
}

terraform/bootstrap/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "aws_region" {
2+
description = "Amazon Region to use"
3+
default = "us-east-1"
4+
}
5+
6+
variable "account_alias" {
7+
description = "Prefix for backend resources"
8+
default = "moduscreate-devops-demo"
9+
}

0 commit comments

Comments
 (0)