Skip to content

Commit be0aecb

Browse files
committed
Adding first test
1 parent f27eadd commit be0aecb

File tree

10 files changed

+59
-143
lines changed

10 files changed

+59
-143
lines changed

.header.md

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,14 @@
1-
# Creating modules for AWS I&A Organization
1+
# Terraform Module for AWS Shield Advanced
22

3-
This repo template is used to seed Terraform Module templates for the [AWS I&A GitHub organization](https://github.com/aws-ia). Usage of this template is allowed per included license. PRs to this template will be considered but are not guaranteed to be included. Consider creating an issue to discuss a feature you want to include before taking the time to create a PR.
3+
Terraform module that creates AWS Shield Advanced Resources
44

5-
<!-- markdownlint-disable MD001 -->
6-
### TL;DR
5+
- [Terraform Module for AWS Shield Advanced](#terraform-module-for-aws-shield-advanced)
6+
- [Usage](#usage)
7+
- [Overview Diagrams](#overview-diagrams)
8+
- [Terraform Module](#terraform-module)
79

8-
1. [install pre-commit](https://pre-commit.com/#install)
9-
- Prerequisites:
10-
- [Python](https://docs.python.org/3/using/index.html)
11-
- [Pip](https://pip.pypa.io/en/stable/installation/)
12-
2. configure pre-commit: `pre-commit install`
13-
3. install required tools
14-
- [tflint](https://github.com/terraform-linters/tflint)
15-
- [tfsec](https://aquasecurity.github.io/tfsec/v1.0.11/)
16-
- [terraform-docs](https://github.com/terraform-docs/terraform-docs)
17-
- [golang](https://go.dev/doc/install) (for macos you can use `brew`)
18-
- [coreutils](https://www.gnu.org/software/coreutils/)
10+
## Usage
1911

20-
Write code according to [I&A module standards](https://aws-ia.github.io/standards-terraform/)
12+
## Overview Diagrams
2113

22-
## Module Documentation
23-
24-
**Do not manually update README.md**. README.md is automatically generated by pulling in content from other files. For instructions, including a fill-in-the-blank content template, see [Create readmes for Terraform-based Partner Solutions.](https://aws-ia-us-west-2.s3.us-west-2.amazonaws.com/docs/content/index.html#/lessons/8rpYWWL59M7dcS-NsjYmaISUu-L_UqEv)
25-
26-
## Terratest
27-
28-
Please include tests to validate your examples/<> root modules, at a minimum. This can be accomplished with usually only slight modifications to the [boilerplate test provided in this template](./test/examples_basic_test.go)
29-
30-
### Configure and run Terratest
31-
32-
1. Install
33-
34-
[golang](https://go.dev/doc/install) (for macos you can use `brew`)
35-
2. Change directory into the test folder.
36-
37-
`cd test`
38-
3. Initialize your test
39-
40-
go mod init github.com/[github org]/[repository]
41-
42-
`go mod init github.com/aws-ia/terraform-aws-vpc`
43-
4. Run tidy
44-
45-
`go mod tidy`
46-
5. Install Terratest
47-
48-
`go get github.com/gruntwork-io/terratest/modules/terraform`
49-
6. Run test (You can have multiple test files).
50-
- Run all tests
51-
52-
`go test`
53-
- Run a specific test with a timeout
54-
55-
`go test -run TestExamplesBasic -timeout 45m`
56-
57-
## Module Standards
58-
59-
For best practices and information on developing with Terraform, see the [I&A Module Standards](https://aws-ia.github.io/standards-terraform/)
60-
61-
## Continuous Integration
62-
63-
The I&A team uses AWS CodeBuild to perform continuous integration (CI) within the organization. Our CI uses the a repo's `.pre-commit-config.yaml` file as well as some other checks. All PRs with other CI will be rejected. See our [FAQ](https://aws-ia.github.io/standards-terraform/faq/#are-modules-protected-by-ci-automation) for more details.
14+
## Terraform Module

README.md

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,24 @@
1-
# Creating modules for AWS I&A Organization
1+
# Terraform Module for AWS Shield Advanced
22

3-
This repo template is used to seed Terraform Module templates for the [AWS I&A GitHub organization](https://github.com/aws-ia). Usage of this template is allowed per included license. PRs to this template will be considered but are not guaranteed to be included. Consider creating an issue to discuss a feature you want to include before taking the time to create a PR.
3+
Terraform module that creates AWS Shield Advanced Resources
44

5-
<!-- markdownlint-disable MD001 -->
6-
### TL;DR
5+
- [Terraform Module for AWS Shield Advanced](#terraform-module-for-aws-shield-advanced)
6+
- [Usage](#usage)
7+
- [Overview Diagrams](#overview-diagrams)
8+
- [Terraform Module](#terraform-module)
79

8-
1. [install pre-commit](https://pre-commit.com/#install)
9-
- Prerequisites:
10-
- [Python](https://docs.python.org/3/using/index.html)
11-
- [Pip](https://pip.pypa.io/en/stable/installation/)
12-
2. configure pre-commit: `pre-commit install`
13-
3. install required tools
14-
- [tflint](https://github.com/terraform-linters/tflint)
15-
- [tfsec](https://aquasecurity.github.io/tfsec/v1.0.11/)
16-
- [terraform-docs](https://github.com/terraform-docs/terraform-docs)
17-
- [golang](https://go.dev/doc/install) (for macos you can use `brew`)
18-
- [coreutils](https://www.gnu.org/software/coreutils/)
10+
## Usage
1911

20-
Write code according to [I&A module standards](https://aws-ia.github.io/standards-terraform/)
12+
## Overview Diagrams
2113

22-
## Module Documentation
23-
24-
**Do not manually update README.md**. README.md is automatically generated by pulling in content from other files. For instructions, including a fill-in-the-blank content template, see [Create readmes for Terraform-based Partner Solutions.](https://aws-ia-us-west-2.s3.us-west-2.amazonaws.com/docs/content/index.html#/lessons/8rpYWWL59M7dcS-NsjYmaISUu-L_UqEv)
25-
26-
## Terratest
27-
28-
Please include tests to validate your examples/<> root modules, at a minimum. This can be accomplished with usually only slight modifications to the [boilerplate test provided in this template](./test/examples\_basic\_test.go)
29-
30-
### Configure and run Terratest
31-
32-
1. Install
33-
34-
[golang](https://go.dev/doc/install) (for macos you can use `brew`)
35-
2. Change directory into the test folder.
36-
37-
`cd test`
38-
3. Initialize your test
39-
40-
go mod init github.com/[github org]/[repository]
41-
42-
`go mod init github.com/aws-ia/terraform-aws-vpc`
43-
4. Run tidy
44-
45-
`go mod tidy`
46-
5. Install Terratest
47-
48-
`go get github.com/gruntwork-io/terratest/modules/terraform`
49-
6. Run test (You can have multiple test files).
50-
- Run all tests
51-
52-
`go test`
53-
- Run a specific test with a timeout
54-
55-
`go test -run TestExamplesBasic -timeout 45m`
56-
57-
## Module Standards
58-
59-
For best practices and information on developing with Terraform, see the [I&A Module Standards](https://aws-ia.github.io/standards-terraform/)
60-
61-
## Continuous Integration
62-
63-
The I&A team uses AWS CodeBuild to perform continuous integration (CI) within the organization. Our CI uses the a repo's `.pre-commit-config.yaml` file as well as some other checks. All PRs with other CI will be rejected. See our [FAQ](https://aws-ia.github.io/standards-terraform/faq/#are-modules-protected-by-ci-automation) for more details.
14+
## Terraform Module
6415

6516
### Requirements
6617

6718
| Name | Version |
6819
|------|---------|
6920
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
7021
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.47 |
71-
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.4 |
7222

7323
### Providers
7424

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource "aws_shield_protection_group" "this" {
3434
# Health Check
3535
##################################################
3636
resource "aws_route53_health_check" "this" {
37-
for_each = var.health_check_configuration
37+
for_each = var.health_check_configuration == null ? {} : var.health_check_configuration
3838
ip_address = each.value.resource_ip
3939
port = each.value.health_check_port
4040
type = each.value.health_check_type

test/complete/main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
provider "aws" {}
2+
3+
data "aws_region" "current" {}
4+
data "aws_caller_identity" "current" {}
5+
6+
locals {
7+
arn_prefix = "arn:aws:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:eip-allocation"
8+
}
9+
10+
resource "aws_eip" "example" {
11+
domain = "vpc"
12+
}
13+
14+
module "shield_advanced" {
15+
source = "../.."
16+
17+
name = "Example protection"
18+
resource_arn = "${local.arn_prefix}/${aws_eip.example.id}"
19+
protection_group_id = "example"
20+
aggregation = "MEAN"
21+
pattern = "ARBITRARY"
22+
}

test/complete/outputs.tf

Whitespace-only changes.

test/complete/variables.tf

Whitespace-only changes.

test/complete/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 4.47"
8+
}
9+
}
10+
}

test/examples_basic_test.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ variable "protection_group_id" {
1616
variable "aggregation" {
1717
description = "Defines how AWS Shield combines resource data for the group in order to detect, mitigate, and report events."
1818
type = string
19+
validation {
20+
condition = contains([
21+
"SUM",
22+
"MEAN",
23+
"MAX",
24+
], var.aggregation)
25+
error_message = "Valid values for `var.aggregation` are `SUM | MEAN | MAX`."
26+
}
1927
}
2028

2129
variable "pattern" {

versions.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 4.47"
88
}
9-
random = {
10-
source = "hashicorp/random"
11-
version = ">= 3.4"
12-
}
139
}
1410
}

0 commit comments

Comments
 (0)