Skip to content

Commit 60f0784

Browse files
committed
feat: initial Terraform configuration files
1 parent 1895666 commit 60f0784

14 files changed

+12544
-0
lines changed

.github/workflows/pipeline.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
jobs:
2+
documentation:
3+
name: Run terraform-docs
4+
runs-on: ubuntu-20.04
5+
steps:
6+
- uses: actions/checkout@v2
7+
with:
8+
ref: main
9+
- uses: terraform-docs/gh-actions@main
10+
with:
11+
git-commit-message: |
12+
docs: Run terraform-docs
13+
git-push: "true"
14+
output-file: README.md
15+
output-method: inject
16+
working-dir: .
17+
release:
18+
name: Run semantic-release
19+
needs:
20+
- documentation
21+
runs-on: ubuntu-20.04
22+
steps:
23+
- uses: actions/checkout@v2
24+
- uses: actions/setup-node@v2
25+
with:
26+
node-version: 16
27+
- run: npm ci
28+
- env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
run: npx semantic-release@18
31+
name: Run release pipeline
32+
on:
33+
push:
34+
branches:
35+
- main

.github/workflows/prettier.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
jobs:
2+
prettier:
3+
name: Run prettier
4+
runs-on: ubuntu-20.04
5+
steps:
6+
- uses: actions/checkout@v2
7+
- uses: actions/setup-node@v2
8+
with:
9+
node-version: 16
10+
- run: npm ci
11+
- run: npx prettier --check .
12+
name: Run prettier
13+
on:
14+
- pull_request
15+
- push

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ override.tf.json
2727

2828
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
2929
# example: *tfplan*
30+
31+
node_modules/

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Local .terraform directories
2+
**/.terraform/*

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.terraform.lock.hcl

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

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,92 @@
88
<p>Returns descriptive information about an Amazon VPC</p>
99
</div>
1010

11+
## Purpose
12+
13+
This module is considered to be a [data-only](https://www.terraform.io/docs/language/modules/develop/composition.html#data-only-modules) module. Given the name of a VPC and an optional set of availability zones, this module returns information about a VPC, such as public and private subnets, the VPC ID, etc. See the [outputs](outputs.tf) file for which data is returned from this module. This module is useful for workspaces that require such information without declaring repetitive `data` sources in your Terraform configurations.
14+
15+
## Usage
16+
17+
The following example creates a security group and an application load balancer.
18+
19+
```hcl
20+
provider "aws" {}
21+
22+
module "networking" {
23+
source = "github.com/mongodb-ansible-roles/terraform-aws-networking-readonly"
24+
version = "1.1.0"
25+
26+
vpc_name = "tutorial-vpc"
27+
}
28+
29+
resource "aws_security_group" "this" {
30+
ingress = [
31+
{
32+
cidr_blocks = ["0.0.0.0/0"]
33+
from_port = 443
34+
protocol = "TCP"
35+
to_port = 443
36+
}
37+
]
38+
39+
vpc_id = module.networking.vpc_id
40+
}
41+
42+
resource "aws_lb" "this" {
43+
internal = false
44+
load_balancer_type = "application"
45+
security_groups = [aws_security_group.this.id]
46+
subnets = module.networking.public_subnets
47+
}
48+
```
49+
1150
<!-- BEGIN_TF_DOCS -->
51+
52+
## Requirements
53+
54+
| Name | Version |
55+
| ------------------------------------------------------------------------ | --------- |
56+
| <a name="requirement_terraform"></a> [terraform](#requirement_terraform) | >= 1.0 |
57+
| <a name="requirement_aws"></a> [aws](#requirement_aws) | >= 3.64.2 |
58+
59+
## Providers
60+
61+
| Name | Version |
62+
| ------------------------------------------------ | ------- |
63+
| <a name="provider_aws"></a> [aws](#provider_aws) | 3.70.0 |
64+
65+
## Modules
66+
67+
No modules.
68+
69+
## Resources
70+
71+
| Name | Type |
72+
| -------------------------------------------------------------------------------------------------------------------------------- | ----------- |
73+
| [aws_availability_zones.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
74+
| [aws_subnet.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | data source |
75+
| [aws_subnet_ids.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
76+
| [aws_vpc.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
77+
78+
## Inputs
79+
80+
| Name | Description | Type | Default | Required |
81+
| --------------------------------------------------------------------------------------- | ------------------------------------ | ------------- | ------- | :------: |
82+
| <a name="input_availability_zones"></a> [availability_zones](#input_availability_zones) | Select subnets only in the given AZs | `set(string)` | `[]` | no |
83+
| <a name="input_vpc_name"></a> [vpc_name](#input_vpc_name) | The name of the VPC | `string` | n/a | yes |
84+
85+
## Outputs
86+
87+
| Name | Description |
88+
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
89+
| <a name="output_dns_hostnames_enabled"></a> [dns_hostnames_enabled](#output_dns_hostnames_enabled) | Indicates if instances launched in this VPC will have public DNS hostnames |
90+
| <a name="output_dns_support_enabled"></a> [dns_support_enabled](#output_dns_support_enabled) | Indicates if DNS support is enabled for this VPC |
91+
| <a name="output_private_subnets"></a> [private_subnets](#output_private_subnets) | List of private subnets in this VPC |
92+
| <a name="output_public_subnets"></a> [public_subnets](#output_public_subnets) | List of public subnets in this VPC |
93+
| <a name="output_vpc_arn"></a> [vpc_arn](#output_vpc_arn) | Arn of this VPC |
94+
| <a name="output_vpc_cidr_block"></a> [vpc_cidr_block](#output_vpc_cidr_block) | CIDR range for this VPC |
95+
| <a name="output_vpc_id"></a> [vpc_id](#output_vpc_id) | The ID of the VPC |
96+
1297
<!-- END_TF_DOCS -->
1398

1499
## Contributing

main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
data "aws_availability_zones" "this" {
2+
filter {
3+
name = "zone-name"
4+
values = var.availability_zones
5+
}
6+
}
7+
8+
data "aws_vpc" "this" {
9+
filter {
10+
name = "tag:Name"
11+
values = [var.vpc_name]
12+
}
13+
14+
state = "available"
15+
}
16+
17+
data "aws_subnet_ids" "this" {
18+
dynamic "filter" {
19+
for_each = length(data.aws_availability_zones.this.names) > 0 ? range(1) : range(0)
20+
21+
content {
22+
name = "availability-zone"
23+
values = data.aws_availability_zones.this.names
24+
}
25+
}
26+
27+
vpc_id = data.aws_vpc.this.id
28+
}
29+
30+
data "aws_subnet" "this" {
31+
for_each = data.aws_subnet_ids.this.ids
32+
33+
id = each.value
34+
}

outputs.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
output "dns_hostnames_enabled" {
2+
description = "Indicates if instances launched in this VPC will have public DNS hostnames"
3+
value = data.aws_vpc.this.enable_dns_hostnames
4+
}
5+
6+
output "dns_support_enabled" {
7+
description = "Indicates if DNS support is enabled for this VPC"
8+
value = data.aws_vpc.this.enable_dns_support
9+
}
10+
11+
output "private_subnets" {
12+
description = "List of private subnets in this VPC"
13+
value = sort([for subnet in data.aws_subnet.this : subnet.id if !subnet.map_public_ip_on_launch])
14+
}
15+
16+
output "public_subnets" {
17+
description = "List of public subnets in this VPC"
18+
value = sort([for subnet in data.aws_subnet.this : subnet.id if subnet.map_public_ip_on_launch])
19+
}
20+
21+
output "vpc_arn" {
22+
description = "Arn of this VPC"
23+
value = data.aws_vpc.this.arn
24+
}
25+
26+
output "vpc_cidr_block" {
27+
description = "CIDR range for this VPC"
28+
value = data.aws_vpc.this.cidr_block
29+
}
30+
31+
output "vpc_id" {
32+
description = "The ID of the VPC"
33+
value = data.aws_vpc.this.id
34+
}

0 commit comments

Comments
 (0)