Skip to content

Commit

Permalink
First working version.
Browse files Browse the repository at this point in the history
  • Loading branch information
skyzyx committed Mar 26, 2024
1 parent 517f598 commit fc53bb6
Show file tree
Hide file tree
Showing 10 changed files with 1,810 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .markdownlint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Add strings to this array for words that should be spelled a particular way.
"names": [
"Northwood Labs",
"Northwood Labs"
]
}
}
81 changes: 67 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

---

# {NAME OF MODULE}
# AWS Networking

[![AWS](https://img.shields.io/badge/AWS-232f3e.svg?logoColor=ffffff&style=for-the-badge&logo=amazonaws)][aws]
[![Terraform](https://img.shields.io/badge/Terraform-623ce4.svg?logoColor=ffffff&style=for-the-badge&logo=terraform)][terraform]
[![OpenTofu](https://img.shields.io/badge/OpenTofu-ffda18.svg?logoColor=171e21&style=for-the-badge&logo=opentofu)][opentofu]
[![Golang](https://img.shields.io/badge/Go-00add8.svg?logoColor=ffffff&style=for-the-badge&logo=go)][golang]
[![Node.js](https://img.shields.io/badge/Node.js-339933.svg?logoColor=ffffff&style=for-the-badge&logo=node.js)][node.js]

{DESCRIPTION}
Simplifies the process of discovering AWS networking data for Northwood Labs resources.

| Information | Description |
|------------------------|---------------|
Expand All @@ -21,23 +21,37 @@

* Designed to be highly _composable_, and has no hard-dependencies on other modules.

{OTHER BULLET POINTS}
* Outputs can be easily used with other modules which need network identifiers for VPCs and Subnets.

* Only looks-up data, but does not persist any data itself, making it completely stateless.

## Examples

More examples can be found in the `./examples` directory.

```hcl
{EXAMPLE}
# Load the module
module "aws_networking" {
source = "https://github.com/northwood-labs/mod-aws-networking.git?ref={tag}"
}
resource "aws_lambda_function" "test_lambda" {
function_name = var.lambda_function_name
# other configuration...
vpc_config {
subnet_ids = module.aws_networking.subnet_ids
}
}
```

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Provider | Version |
|------|----------|---------|
| `terraform` | | `~> 1.6` |
| `aws` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) | `~> 5.0` |
| Name | Provider | Version |
|-------------|------------------------------------------------------------------------------------|----------|
| `terraform` | | `~> 1.6` |
| `aws` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) | `~> 5.0` |

## Inputs

Expand All @@ -46,15 +60,54 @@ More examples can be found in the `./examples` directory.

## Outputs

| Name | Description |
|------|-------------|
| Name | Description |
|------------------------|----------------------------------------------------------------------------|
| `internet_gateway` | An object containing all data for this internet gateway. |
| `internet_gateway_arn` | The ARN of this internet gateway. |
| `internet_gateway_id` | The ID of this internet gateway. |
| `nacl` | An object containing all data for this Network Access Control List (NACL). |
| `nacl_ids` | List of all Network Access Control List (NACL) IDs in the VPC. |
| `route_table` | An object containing all data for this route table. |
| `route_table_arn` | The ARN of this route table. |
| `route_table_id` | The ID of this route table. |
| `subnet_ids` | List of all Subnet IDs in the VPC. |
| `subnet_int_a` | An object containing all data for subnet A. |
| `subnet_int_a_arn` | The ARN of subnet A. |
| `subnet_int_a_cidr` | The Availability Zone CIDR block of subnet A. |
| `subnet_int_a_id` | The ID of subnet A. |
| `subnet_int_a_zone` | The Availability Zone of subnet A. |
| `subnet_int_a_zone_id` | The Availability Zone ID of subnet A. |
| `subnet_int_b` | An object containing all data for subnet B. |
| `subnet_int_b_arn` | The ARN of subnet B. |
| `subnet_int_b_cidr` | The Availability Zone CIDR block of subnet B. |
| `subnet_int_b_id` | The ID of subnet B. |
| `subnet_int_b_zone` | The Availability Zone of subnet B. |
| `subnet_int_b_zone_id` | The Availability Zone ID of subnet B. |
| `subnet_int_c` | An object containing all data for subnet C. |
| `subnet_int_c_arn` | The ARN of subnet C. |
| `subnet_int_c_cidr` | The Availability Zone CIDR block of subnet C. |
| `subnet_int_c_id` | The ID of subnet C. |
| `subnet_int_c_zone` | The Availability Zone of subnet C. |
| `subnet_int_c_zone_id` | The Availability Zone ID of subnet C. |
| `vpc` | An object containing all VPC data. |
| `vpc_arn` | The ARN of the VPC in this account. |
| `vpc_cidr` | The CIDR of the VPC in this account. |
| `vpc_id` | The ID of the VPC in this account. |

## Resources

| Kind | Source | Name | Provider |
|------|--------|------|----------|
| data source | [`data.aws_caller_identity`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | `current` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_region`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | `current` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| Kind | Source | Name | Provider |
|-------------|--------------------------------------------------------------------------------------------------------------------------------|----------------|------------------------------------------------------------------------------------|
| data source | [`data.aws_caller_identity`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | `current` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_internet_gateway`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/internet_gateway) | `default` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_network_acls`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/network_acls) | `default` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_region`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | `current` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_route_table`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route_table) | `route_table` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_subnet`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | `subnet_int_a` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_subnet`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | `subnet_int_b` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_subnet`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | `subnet_int_c` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_subnets`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnets) | `subnets` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
| data source | [`data.aws_vpc`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | `default` | [hashicorp/aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) |
<!-- END_TF_DOCS -->

## Testing
Expand Down
51 changes: 51 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Expects a single VPC in the account, and will fail if there are none or more than one.
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc
data "aws_vpc" "default" {}

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnets
data "aws_subnets" "subnets" {
filter {
name = "vpc-id"
values = [
data.aws_vpc.default.id,
]
}
}

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet
data "aws_subnet" "subnet_int_a" {
vpc_id = data.aws_vpc.default.id
availability_zone = "${data.aws_region.current.name}a"
}

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet
data "aws_subnet" "subnet_int_b" {
vpc_id = data.aws_vpc.default.id
availability_zone = "${data.aws_region.current.name}b"
}

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet
data "aws_subnet" "subnet_int_c" {
vpc_id = data.aws_vpc.default.id
availability_zone = "${data.aws_region.current.name}c"
}

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route_table
data "aws_route_table" "route_table" {
vpc_id = data.aws_vpc.default.id
}

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/internet_gateway
data "aws_internet_gateway" "default" {
filter {
name = "attachment.vpc-id"
values = [
data.aws_vpc.default.id,
]
}
}

# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/network_acls
data "aws_network_acls" "default" {
vpc_id = data.aws_vpc.default.id
}
101 changes: 101 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
module tests

go 1.21

toolchain go1.22.1

require (
github.com/gruntwork-io/terratest v0.46.13
github.com/hairyhenderson/go-which v0.2.0
github.com/stretchr/testify v1.9.0
)

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.1 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
github.com/hashicorp/terraform-json v0.13.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/otp v1.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/afero v1.3.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tmccombs/hcl2json v0.3.3 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/urfave/cli v1.22.2 // indirect
github.com/zclconf/go-cty v1.9.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.114.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.4 // indirect
k8s.io/apimachinery v0.28.4 // indirect
k8s.io/client-go v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit fc53bb6

Please sign in to comment.