diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 027e002..fab32b7 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.2.1 +current_version = 1.0.0 commit = True message = Bumps version to {new_version} tag = False diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2c7ee79..85e5676 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,3 +17,5 @@ jobs: uses: plus3it/actions-workflows/.github/workflows/release.yml@00bdf2c02c2bb252dc7ba7f74816ac8359aa6693 secrets: release-token: ${{ secrets.GH_RELEASES_TOKEN }} + with: + mockstacktest-enable: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 5caad15..de6cfd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,40 +1,13 @@ -## repo-template +## terraform-aws-tardigrade-ec2-managed-prefix-list All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -### [1.2.1] (https://github.com/plus3it/repo-template/releases/tag/1.2.1) +### [1.0.0](https://github.com/plus3it/terraform-aws-tardigrade-ec2-managed-prefix-list/releases/tag/1.0.0) -**Summary**: - -* Updated README.md to include config settings for github -* Updated LICENSE copyright year - -### [1.2.0] (https://github.com/plus3it/repo-template/releases/tag/1.2.0) - -**Summary**: - -* Updated SHA value for Github Actions Workflows -* Updated CHANGELOG.template.md file -* Added Master branch in release workflow logic to make migration to Github Actions more efficient - -### 1.1.0 - -**Commit Delta**: N/A - -**Released**: 2023.01.27 - -**Summary**: - -* Updated workflow files to be consumable and reusable, and now points to actions-workflows repo - -### 1.0.0 - -**Commit Delta**: N/A - -**Released**: 2023.01.10 +**Released**: 2024.11.11 **Summary**: -* Initial release of capability +* Initial release of capability to manage an EC2 prefix list and its rules diff --git a/CHANGELOG.template.md b/CHANGELOG.template.md deleted file mode 100644 index c61f573..0000000 --- a/CHANGELOG.template.md +++ /dev/null @@ -1,13 +0,0 @@ -## {{ repo-name }} - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). - -### [{{Major.Minor.Patch}}](https://github.com/plus3it/{{RepoName}}/releases/tag/{{Major.Minor.Patch}}) - -**Released**: {{ YYYY.MM.DD }} - -**Summary**: - -* {{ Bulleted descriptions of enhancements, changes, or fixes }} diff --git a/LICENSE b/LICENSE index c2f93d6..3f74d66 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2024 Maintainers of plus3it/repo-template + Copyright 2024 Maintainers of plus3it/terraform-aws-tardigrade-ec2-managed-prefix-list Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 5de6c40..ac1d19c 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,34 @@ -# repo-template -Generic repo template for Plus3IT repositories - -To use this template: - -1. Select the green "Use this template" button, or [click here](https://github.com/plus3it/repo-template/generate). -2. Select the repo Owner, give the repo a name, enter a description, select Public or Private, and click "Create repository from template". -3. Clone the repository and create a new branch. -4. Configure the following settings on your new repo. - * `GENERAL` - * `Features` - * Turn off Wikis, Sponsorships, Discussions, and Projects - * `Pull Requests` - * Turn off Squash Merging - * Turn off Rebase Merging - * Turn on Allow Auto-Merge - * Turn on Automatically delete head branches - * `Pushes` - * Limit how many branches can be updated in a single push: 2 - * `COLLABORATORS and TEAMS` - * `Manage Access` - * Add relevant team roles, for example - * `tardigrade-admins` (Admin) - * `terraform` (Write) - * `releasebot` (Write) - * `Branches` - * `Create Branch Protection rule` for `main` - * Turn on Require pull request before merging - * Turn on Require approvals - * Turn on Dismiss stale pull requests... - * `Required Status Checks` - * As relevant to projects, for example - * WIP - * lint/actionlint - * lint/tardigradelint - * test / mockstacktest - * Turn on Do not allow bypassing the above settings -5. Edit the following files to customize them for the new repository: - * `LICENSE` - * Near the end of the file, edit the date and change the repository name - * `CHANGELOG.template.md` - * Rename to `CHANGELOG.md`, replacing the repo-template changelog - * Edit templated items for the new repo - * `.bumpversion.cfg` - * Edit the version number for the new repo, ask team if not sure what to - start with - * `README.md` - * Replace contents for the new repo - * `.github/` - * Inspect dependabot and workflow files in case changes are needed for - the new repo -6. Commit the changes and open a pull request +# terraform-aws-tardigrade-ec2-managed-prefix-list + +Terraform module for managing an EC2 Prefix List and its entries. + + +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | n/a | + +## Resources + +| Name | Type | +|------|------| + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [ec2\_managed\_prefix\_list](#input\_ec2\_managed\_prefix\_list) | Object of attributes for the EC2 managed prefix list |
object({
name = string
address_family = optional(string, "IPv4")
max_entries = optional(number)
tags = optional(map(string), {})

entries = optional(list(object({
name = string
cidr = string
description = optional(string)
})), [])
})
| n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [ec2\_managed\_prefix\_list](#output\_ec2\_managed\_prefix\_list) | Object of attributes for the managed prefix list | +| [ec2\_managed\_prefix\_list\_entries](#output\_ec2\_managed\_prefix\_list\_entries) | Object of attributes for the managed prefix list entries | + + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..ac1f152 --- /dev/null +++ b/main.tf @@ -0,0 +1,15 @@ +resource "aws_ec2_managed_prefix_list" "this" { + name = var.ec2_managed_prefix_list.name + + address_family = var.ec2_managed_prefix_list.address_family + max_entries = coalesce(var.ec2_managed_prefix_list.max_entries, max(length(var.ec2_managed_prefix_list.entries), 1)) + tags = var.ec2_managed_prefix_list.tags +} + +resource "aws_ec2_managed_prefix_list_entry" "this" { + for_each = { for prefix_list in var.ec2_managed_prefix_list.entries : prefix_list.name => prefix_list } + + cidr = each.value.cidr + description = coalesce(each.value.description, each.value.name) + prefix_list_id = aws_ec2_managed_prefix_list.this.id +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..6eaebd3 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,9 @@ +output "ec2_managed_prefix_list" { + description = "Object of attributes for the managed prefix list" + value = aws_ec2_managed_prefix_list.this +} + +output "ec2_managed_prefix_list_entries" { + description = "Object of attributes for the managed prefix list entries" + value = aws_ec2_managed_prefix_list_entry.this +} diff --git a/tests/all-inputs/main.tf b/tests/all-inputs/main.tf new file mode 100644 index 0000000..26e1917 --- /dev/null +++ b/tests/all-inputs/main.tf @@ -0,0 +1,31 @@ +module "ec2_managed_prefix_list" { + source = "../.." + + ec2_managed_prefix_list = { + name = "tardigrade-test-prefix-list-${local.id}" + address_family = "IPv4" + max_entries = 5 + tags = { + Name = "tardigrade-test-prefix-list-${local.id}" + } + + entries = [ + { + name = "tardigrade-test-prefix-list-entry-${local.id}-1" + cidr = "10.0.0.0/16" + description = "tardigrade-test-prefix-list-entry-${local.id}-1" + }, + ] + } +} + +data "terraform_remote_state" "prereq" { + backend = "local" + config = { + path = "prereq/terraform.tfstate" + } +} + +locals { + id = data.terraform_remote_state.prereq.outputs.test_id.result +} diff --git a/tests/all-inputs/prereq/main.tf b/tests/all-inputs/prereq/main.tf new file mode 100644 index 0000000..f6e28ae --- /dev/null +++ b/tests/all-inputs/prereq/main.tf @@ -0,0 +1,10 @@ +resource "random_string" "this" { + length = 6 + upper = false + special = false + numeric = false +} + +output "test_id" { + value = random_string.this +} diff --git a/tests/defaults/main.tf b/tests/defaults/main.tf new file mode 100644 index 0000000..7963e09 --- /dev/null +++ b/tests/defaults/main.tf @@ -0,0 +1,18 @@ +module "ec2_managed_prefix_list" { + source = "../.." + + ec2_managed_prefix_list = { + name = "tardigrade-test-prefix-list-${random_string.this.result}" + } +} + +resource "random_string" "this" { + length = 6 + upper = false + special = false + numeric = false +} + +locals { + id = random_string.this.result +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..570f4a0 --- /dev/null +++ b/variables.tf @@ -0,0 +1,15 @@ +variable "ec2_managed_prefix_list" { + description = "Object of attributes for the EC2 managed prefix list" + type = object({ + name = string + address_family = optional(string, "IPv4") + max_entries = optional(number) + tags = optional(map(string), {}) + + entries = optional(list(object({ + name = string + cidr = string + description = optional(string) + })), []) + }) +}