Skip to content

Commit 14104e5

Browse files
authored
Sgproj 1415 (#5)
* Added Readme and gitignore. * Renames acm_domain_name to acm_certificate_name to reflect the actual function of the variable. * Updates the documentation. * Updates the documentation. * Formats the file. * Corrected variable names to be used effectively. * Applies the new template to the repo. * Renames files to match requirement of the new template. * New Readme generated. * Updates acm_domain_name description. * Update the example to show the complete steps to take to instantiate the module. * Updates ReadMe.
1 parent c3abea5 commit 14104e5

14 files changed

+304
-27
lines changed

.config/.terraform-docs.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: ""
2+
3+
formatter: markdown table
4+
5+
name: terraform-aws-acm-certificate-creation
6+
7+
content: |-
8+
# terraform-aws-acm-certificate-creation
9+
10+
GitHub: [StratusGrid/terraform-aws-terraform-aws-acm-certificate-creation](https://github.com/StratusGrid/terraform-aws-acm-certificate-creation)
11+
12+
This module is used to create a certificate using Route53 DNS validation. It requires a hosted zone to which the IAM
13+
principal creating the resource has access.
14+
15+
## Examples
16+
17+
```hcl
18+
{{ include "examples/example1.tfnot" }}
19+
```
20+
---
21+
22+
{{ .Requirements }}
23+
24+
{{ .Resources }}
25+
26+
{{ .Inputs }}
27+
28+
{{ .Outputs }}
29+
30+
---
31+
32+
Note, manual changes to the README will be overwritten when the documentation is updated. To update the documentation, run `terraform-docs -c .config/.terraform-docs.yml`
33+
34+
sections:
35+
show:
36+
- requirements
37+
- resources
38+
- inputs
39+
- outputs
40+
41+
sort:
42+
enabled: true
43+
by: name
44+
45+
output:
46+
file: README.md
47+
mode: replace

.config/terrascan.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#See docs here: https://runterrascan.io/docs/_print/#command-to-specify-config-file, most of the links are broken sadly :(
2+
severity:
3+
level: high
4+
rules:
5+
skip-rules: # To bypass submodules you need to skip rules here, otherwise it will fail the build
6+
# - AC_AWS_021
7+
# - AC_AWS_0214
8+
# - AC_AWS_0215
9+
# - AC_AWS_0207
10+
# - AC_AWS_0483

.github/sync-repo-settings.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ squashMergeAllowed: true
33
mergeCommitAllowed: false
44
deleteBranchOnMerge: true
55
branchProtectionRules:
6-
- pattern: main
7-
dismissesStaleReviews: true
8-
requiredApprovingReviewCount: 1
9-
requiresCodeOwnerReviews: true
10-
requiresStrictStatusChecks: true
6+
- pattern: main
7+
dismissesStaleReviews: true
8+
requiredApprovingReviewCount: 1
9+
requiresCodeOwnerReviews: true
10+
requiresStrictStatusChecks: true

.github/workflows/pre-commit.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Pre-Commit
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
getBaseVersion:
8+
name: Module max TF version
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
- name: Terraform min/max versions
14+
id: minMax
15+
uses: clowdhaus/[email protected]
16+
outputs:
17+
minVersion: ${{ steps.minMax.outputs.minVersion }}
18+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
19+
20+
preCommitMinVersion:
21+
name: Min TF pre-commit
22+
runs-on: ubuntu-latest
23+
needs: getBaseVersion
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
version:
28+
- ${{ needs.getBaseVersion.outputs.minVersion }}
29+
steps:
30+
- uses: actions/setup-go@v2
31+
with:
32+
go-version: "^1.16.6"
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
- name: Install Python
36+
uses: actions/setup-python@v2
37+
- name: Install Terraform v${{ matrix.version }}
38+
uses: hashicorp/setup-terraform@v1
39+
with:
40+
terraform_version: ${{ matrix.version }}
41+
- name: Install pre-commit dependencies
42+
run: |
43+
pip install pre-commit
44+
brew install tflint
45+
brew install terrascan
46+
brew install tfsec
47+
brew install terraform-docs
48+
- name: Inits
49+
run: |
50+
tflint --init
51+
- name: Execute pre-commit
52+
# Run all pre-commit checks on min version supported
53+
if: ${{ matrix.version == needs.getBaseVersion.outputs.minVersion }}
54+
run: pre-commit run --color=always --show-diff-on-failure --all-files

.gitignore

+35-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,41 @@
55
*.tfstate
66
*.tfstate.*
77

8-
# .tfvars files
9-
*.tfvars
8+
# Lock File
9+
.terraform.lock.**
1010

11-
# TF Plans
12-
**/plans
11+
#TF Hash Lock File - Module Specific
12+
.terraform.lock.hcl
1313

14-
# Certs
15-
*.pem
14+
# Mac Stuff
15+
.DS_Store
1616

17-
.idea
18-
.DS_Store
17+
# InfraCost
18+
**/.infracost/*
19+
20+
# Crash log files
21+
crash.log
22+
23+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
24+
# .tfvars files are managed as part of configuration and so should be included in
25+
# version control.
26+
#
27+
# example.tfvars
28+
29+
# Ignore override files as they are usually used to override resources locally and so
30+
# are not checked in
31+
override.tf
32+
override.tf.json
33+
*_override.tf
34+
*_override.tf.json
35+
36+
# Include override files you do wish to add to version control using negated pattern
37+
#
38+
# !example_override.tf
39+
40+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
41+
# example: *tfplan*
42+
43+
# IntelliJ
44+
.idea/workspace.xml
45+
.idea

.pre-commit-config.yaml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
repos:
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.68.1 # v.1.63.0 and above require bash 5 from brew
4+
hooks:
5+
- id: terraform_fmt
6+
- id: terraform_validate
7+
- id: terraform_docs # Update our output, if updates it will force a failure which is good
8+
args:
9+
- "--args=-c .config/.terraform-docs.yml"
10+
- id: terraform_docs # Verify out output is up to date, sometimes the update fails
11+
always_run: true
12+
args:
13+
- "--args=--output-check=true"
14+
- id: terrascan
15+
args:
16+
- "--args=-c .config/terrascan.yaml"
17+
- "--args=--non-recursive"
18+
- "--args=-i terraform" #If we don't specify this it came back with Docker failures and produces a non zero exit code
19+
- id: terraform_tflint
20+
args:
21+
- "--args=--only=terraform_deprecated_interpolation"
22+
- "--args=--only=terraform_deprecated_index"
23+
- "--args=--only=terraform_unused_declarations"
24+
- "--args=--only=terraform_comment_syntax"
25+
- "--args=--only=terraform_documented_outputs"
26+
- "--args=--only=terraform_documented_variables"
27+
- "--args=--only=terraform_typed_variables"
28+
- "--args=--only=terraform_module_pinned_source"
29+
- "--args=--only=terraform_naming_convention"
30+
#- '--args=--only=terraform_required_version' # This is bugged with the new Terraform provider syntax
31+
- "--args=--only=terraform_required_providers"
32+
- "--args=--only=terraform_workspace_remote"
33+
- id: terraform_tfsec
34+
args:
35+
- "--args=--exclude-downloaded-modules"
36+
- "--args=--concise-output"
37+
# Native Git PreCommit Hooks
38+
- repo: https://github.com/pre-commit/pre-commit-hooks
39+
rev: v4.1.0
40+
hooks:
41+
- id: check-merge-conflict
42+
- id: check-yaml
43+
- id: no-commit-to-branch
44+
args: [--branch, main, --branch, master]
45+
#GitLeaks
46+
- repo: https://github.com/zricethezav/gitleaks
47+
rev: v8.2.0
48+
hooks:
49+
- id: gitleaks
50+
#Prettier
51+
- repo: https://github.com/pre-commit/mirrors-prettier
52+
rev: v2.6.2
53+
hooks:
54+
- id: prettier

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
README.md
2+
.terraform
3+
/.config

.tflint.hcl

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
plugin "aws" {
2+
enabled = true
3+
version = "0.13.2"
4+
source = "github.com/terraform-linters/tflint-ruleset-aws"
5+
}

README.md

+48-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# ACM Certificate Creation
2-
```
3-
This repo is used to create a certificate using Route53 DNS validation. It requires a hosted zone to which the IAM
1+
<!-- BEGIN_TF_DOCS -->
2+
# terraform-aws-acm-certificate-creation
3+
4+
GitHub: [StratusGrid/terraform-aws-terraform-aws-acm-certificate-creation](https://github.com/StratusGrid/terraform-aws-acm-certificate-creation)
5+
6+
This module is used to create a certificate using Route53 DNS validation. It requires a hosted zone to which the IAM
47
principal creating the resource has access.
5-
```
68

7-
### Example Usage:
8-
```
9-
# Variables definition
9+
## Examples
1010

11+
```hcl
12+
# Variables definition
1113
variable "acm_certificate_name" {
1214
description = "Certificate name prefix which will be trailed by the hosted-zone name"
1315
type = list(string)
@@ -20,16 +22,14 @@ variable "hosted_zone_name" {
2022
2123
acm_certificate_name = ["engineering", "sales"]
2224
hosted_zone_name = "example.com"
23-
```
24-
```
25+
26+
# Data resource retrieving the provided hosted-zone's ID
2527
data "aws_route53_zone" "hosted_zone_id" {
2628
name = var.hosted_zone_name
2729
private_zone = false
2830
}
29-
```
30-
```
31-
# Module call
3231
32+
# Module call
3333
module "new_record_and_certificate" {
3434
source = "github.com/StratusGrid/terraform-aws-acm-certificate-creation"
3535
@@ -41,4 +41,39 @@ module "new_record_and_certificate" {
4141
"Name" = "${each.key}.${var.hosted_zone_name}"
4242
}
4343
}
44-
```
44+
```
45+
---
46+
47+
## Requirements
48+
49+
| Name | Version |
50+
|------|---------|
51+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
52+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.75 |
53+
54+
## Resources
55+
56+
| Name | Type |
57+
|------|------|
58+
| [aws_acm_certificate.acm_module_certificate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate) | resource |
59+
| [aws_acm_certificate_validation.acm_module_cert_validation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate_validation) | resource |
60+
| [aws_route53_record.domain_validation_record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
61+
62+
## Inputs
63+
64+
| Name | Description | Type | Default | Required |
65+
|------|-------------|------|---------|:--------:|
66+
| <a name="input_acm_domain_name"></a> [acm\_domain\_name](#input\_acm\_domain\_name) | Name of the certificate to be created in AWS ACM / FQDN | `string` | n/a | yes |
67+
| <a name="input_input_tags"></a> [input\_tags](#input\_input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
68+
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | Route53 zone ID | `string` | n/a | yes |
69+
70+
## Outputs
71+
72+
| Name | Description |
73+
|------|-------------|
74+
| <a name="output_acm_certificate_arn"></a> [acm\_certificate\_arn](#output\_acm\_certificate\_arn) | The ARN of the certificate created by this module |
75+
76+
---
77+
78+
Note, manual changes to the README will be overwritten when the documentation is updated. To update the documentation, run `terraform-docs -c .config/.terraform-docs.yml`
79+
<!-- END_TF_DOCS -->

examples/example1.tfnot

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Variables definition
2+
variable "acm_certificate_name" {
3+
description = "Certificate name prefix which will be trailed by the hosted-zone name"
4+
type = list(string)
5+
}
6+
7+
variable "hosted_zone_name" {
8+
description = "Route53 hosted zone name"
9+
type = string
10+
}
11+
12+
acm_certificate_name = ["engineering", "sales"]
13+
hosted_zone_name = "example.com"
14+
15+
# Data resource retrieving the provided hosted-zone's ID
16+
data "aws_route53_zone" "hosted_zone_id" {
17+
name = var.hosted_zone_name
18+
private_zone = false
19+
}
20+
21+
# Module call
22+
module "new_record_and_certificate" {
23+
source = "github.com/StratusGrid/terraform-aws-acm-certificate-creation"
24+
25+
for_each = toset(var.acm_certificate_name)
26+
acm_domain_name = "${each.key}.${var.hosted_zone_name}"
27+
zone_id = data.aws_route53_zone.hosted_zone_id.zone_id
28+
29+
input_tags = {
30+
"Name" = "${each.key}.${var.hosted_zone_name}"
31+
}
32+
}

-outputs.tf outputs.tf

File renamed without changes.

-tags.tf tags.tf

File renamed without changes.

-inputs.tf variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ variable "input_tags" {
55
}
66

77
variable "acm_domain_name" {
8-
description = "Name of the certificate to be used in AWS ACM"
8+
description = "Name of the certificate to be created in AWS ACM / FQDN"
99
type = string
1010
}
1111

versions.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 3.75"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)