Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktisme committed Jan 13, 2021
0 parents commit 79ba11e
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check
on: [ push, pull_request ]

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.14.0

- name: Validate Module
env:
AWS_REGION: 'eu-west-1'
run: |
terraform init -backend=false
terraform validate
terraform fmt -check
- name: Validate Examples
env:
AWS_REGION: 'eu-west-1'
run: |
for example in $(find examples -maxdepth 1 -mindepth 1 -type d); do
cd $example
terraform init -backend=false
terraform validate
terraform fmt -check
cd -
done
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.tfvars
*.tfstate*
*.lock.hcl*
.terraform/
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-json
- id: check-merge-conflict
- id: check-yaml
- id: detect-private-key
- id: pretty-format-json
args:
- --autofix
- id: trailing-whitespace

- repo: git://github.com/igorshubovych/markdownlint-cli
rev: v0.26.0
hooks:
- id: markdownlint

- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.45.0
hooks:
- id: terraform_docs
- id: terraform_fmt
11 changes: 11 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# AWS S3 Bootstrap State Module

A Terraform module to create and manage Terraform state on AWS.
Available through the [Terraform registry](https://registry.terraform.io/modules/eriktisme/bootstrap/aws/latest).

## Terraform versions

Terraform 0.13 and above are supported.

## Usage example

- A simple example is contained in the [examples directory](./examples/simple).

## Authors

- [Erik van Dam](https://github.com/eriktisme)

## License

The Apache License, Version 2.0. Please see [License File](LICENSE) for more information.
6 changes: 6 additions & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "bootstrap" {
source = "../../"

project_alias = "simple"
region = "eu-west-1"
}
26 changes: 26 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module "terraform_state_bucket" {
source = "eriktisme/s3-bucket/aws"
version = "0.1.0"

bucket = "${var.project_alias}-${var.bucket_purpose}-${var.region}"

tags = merge(var.tags)
}

resource "aws_dynamodb_table" "terraform_state_lock" {
hash_key = "LockID"
name = var.table_name
read_capacity = 2
write_capacity = 2

server_side_encryption {
enabled = true
}

attribute {
name = "LockID"
type = "S"
}

tags = merge(var.tags)
}
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "dynamodb_table" {
description = "The name of the DynamoDB table created for the Terraform state."
value = aws_dynamodb_table.terraform_state_lock.id
}
27 changes: 27 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "table_name" {
description = "The table name for the Terraform state lock."
default = "terraform-state-lock"
type = string
}

variable "project_alias" {
description = "The AWS account alias."
type = string
}

variable "bucket_purpose" {
description = "The identification of the bucket's purpose."
default = "terraform-state"
type = string
}

variable "region" {
description = "The AWS region the account will be bootstrapped in."
type = string
}

variable "tags" {
description = "A mapping of tags to assign to the table."
type = map(string)
default = {}
}
10 changes: 10 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.13"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.23.0"
}
}
}

0 comments on commit 79ba11e

Please sign in to comment.