diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 3119899..0000000 --- a/.editorconfig +++ /dev/null @@ -1,25 +0,0 @@ -# Unix-style newlines with a newline ending every file -[*] -charset = utf-8 -end_of_line = lf -indent_size = 2 -indent_style = space -insert_final_newline = true -trim_trailing_whitespace = true - -[*.{tf,tfvars,tpl}] -indent_size = 2 -indent_style = space - -[*.md] -max_line_length = 0 -trim_trailing_whitespace = false - -# Override for Makefile -[{Makefile, makefile, GNUmakefile, Makefile.*}] -tab_width = 2 -indent_style = tab -indent_size = 4 - -[COMMIT_EDITMSG] -max_line_length = 0 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 9b65ef8..0000000 --- a/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -# Local .terraform directories -**/.terraform/* - -# .tfstate files -*.tfstate -*.tfstate.* -*.lock.hcl - -# Crash log files -crash.log -crash.*.log - -# Exclude all .tfvars files, which are likely to contain sensitive data, such as -# password, private keys, and other secrets. These should not be part of version -# control as they are data points which are potentially sensitive and subject -# to change depending on the environment. -*.tfvars -*.tfvars.json - -# Ignore override files as they are usually used to override resources locally and so -# are not checked in -override.tf -override.tf.json -*_override.tf -*_override.tf.json - -# Ignore transient lock info files created by terraform apply -.terraform.tfstate.lock.info - -# Include override files you do wish to add to version control using negated pattern -# !example_override.tf - -# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan -# example: *tfplan* - -# Ignore CLI configuration files -.terraformrc -terraform.rc diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/README.md b/README.md index 02843a5..c5d2c6f 100644 --- a/README.md +++ b/README.md @@ -1,131 +1,100 @@ -# terraform module to create VPC endpoints and security groups -Terraform module to create VPC endpoints and security groups. -## Goal -This terraform module creates VPC endpoints (interface and gateway type endpoints) and security groups. +## Terraform AWS VPC Endpoint -## Dependencies -Please make sure that the following AWS resources are created before executing this module. -- VPC -- Subnet -- RouteTables - -## Considerations -### 1. Naming conventions +This Terraform module simplifies the creation and management of VPC Endpoints, supporting both Interface and Gateway types. It allows you to securely connect your VPC to supported AWS services without requiring an internet gateway, NAT device, or VPN connection. +## Prerequisites +Before using this module, ensure that the following resources are already provisioned: -## Requirements +- A VPC -| Name | Version | -|------|---------| -| [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.30 | +- At least one Subnet (required for Interface endpoints) -## Providers +- One or more Route Tables (required for Gateway endpoints) + +## Architecture -No providers. + -## Modules -| Name | Source | Version | -|------|--------|---------| -| [name\_gateway\_ep](#module\_name\_gateway\_ep) | google.com/naming-tag.git | feature/US106973 | -| [name\_interface\_ep](#module\_name\_interface\_ep) | google.com/naming-tag.git | feature/US106973 | -| [name\_security\_group](#module\_name\_security\_group) | google.com/naming-tag.git | feature/US106973 | -| [security\_group](#module\_security\_group) | google.com/aws-security-group.git | tag-name-change | -| [vpc\_gateway\_endpoint](#module\_vpc\_gateway\_endpoint) | google.com/aws-gateway-vpc-endpoint.git | tag-name-change | -| [vpc\_interface\_endpoint](#module\_vpc\_interface\_endpoint) | google.com/aws-interface-vpc-endpoint.git | tag-name-change | +## Providers -## Resources +| Name | Version | +|---------------------------------------------------|----------| +| [aws](#provider\_aws) | 5.82.2 | +| [Terraform](Terraform\module) | >= 1.12.1| -No resources. -## Inputs +# Usage -| Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| -| [app](#input\_app) | Name of the application, For ex: network, shared, ot etc. | `string` | n/a | yes | -| [bu](#input\_bu) | Name of the business unit, For ex: bu which are supported by ot are: pcs, ultrasound etc. | `string` | n/a | yes | -| [env](#input\_env) | Name of the environment example: for development env it should be 'd', prod env should be 'p', testing env should be 'q' and staging env should be's'. | `string` | n/a | yes | -| [sg\_egress\_variables](#input\_sg\_egress\_variables) | List of egress rules for the security group |
list(object({
cidr_blocks = optional(list(string))
description = optional(string)
from_port = number
to_port = number
protocol = string
})) | [| no | -| [sg\_ingress\_variables](#input\_sg\_ingress\_variables) | List of ingress rules for the security group |
{
"cidr_blocks": [],
"description": null,
"from_port": 0,
"protocol": "-1",
"to_port": 0
}
]
list(object({
cidr_blocks = optional(list(string))
description = optional(string)
from_port = number
to_port = number
protocol = string
})) | [| no | -| [sg\_tags](#input\_sg\_tags) | Tags for the security group | `map(string)` | `{}` | no | -| [vpc\_gateway\_ep\_list](#input\_vpc\_gateway\_ep\_list) | A list of all VPC gateway endpoints |
{
"cidr_blocks": [],
"description": null,
"from_port": 0,
"protocol": "-1",
"to_port": 0
}
]
list(object({
service_name = optional(string, null)
auto_accept = optional(bool, true)
policy = optional(any, {
Statement = [
{
Action = "*"
Effect = "Allow"
Principal = "*"
Resource = "*"
}
]
})
})) | `[]` | no |
-| [vpc\_gateway\_ep\_route\_table\_ids](#input\_vpc\_gateway\_ep\_route\_table\_ids) | Route table ids for all VPC gateway endpoints | `list(string)` | `[]` | no |
-| [vpc\_gateway\_ep\_tags](#input\_vpc\_gateway\_ep\_tags) | Tags for all VPC gateway endpoints | `map(string)` | `{}` | no |
-| [vpc\_id](#input\_vpc\_id) | VPC ID for the composite module | `string` | n/a | yes |
-| [vpc\_interface\_ep\_list](#input\_vpc\_interface\_ep\_list) | A list of all VPC interface endpoints | list(object({
service_name = optional(string, null)
private_dns_enabled = optional(bool, true)
ip_address_type = optional(string, "ipv4")
auto_accept = optional(bool, true)
policy = optional(any, {
Statement = [
{
Action = "*"
Effect = "Allow"
Principal = "*"
Resource = "*"
}
]
})
})) | `[]` | no |
-| [vpc\_interface\_ep\_subnet\_ids](#input\_vpc\_interface\_ep\_subnet\_ids) | Subnet ids for all VPC interface endpoints | `list(string)` | `[]` | no |
-| [vpc\_interface\_ep\_tags](#input\_vpc\_interface\_ep\_tags) | Tags for all VPC interface endpoints | `map(string)` | `{}` | no |
+```hcl
-## Outputs
+module "vpc_endpoints" {
+ for_each = var.vpc_endpoints
-| Name | Description |
-|------|-------------|
-| [vpc\_gateway\_ep\_arns](#output\_vpc\_gateway\_ep\_arns) | ARNs of the VPC gateway endpoints |
-| [vpc\_gateway\_ep\_ids](#output\_vpc\_gateway\_ep\_ids) | IDs of the VPC gateway endpoints |
-| [vpc\_interface\_ep\_arns](#output\_vpc\_interface\_ep\_arns) | ARNs of the VPC interface endpoints |
-| [vpc\_interface\_ep\_ids](#output\_vpc\_interface\_ep\_ids) | IDs of the VPC interface endpoints |
+ source = "../"
+ vpc_id = var.vpc_id
+ service_name = each.value.service_name
+ vpc_endpoint_type = each.value.vpc_endpoint_type
+ subnet_ids = each.value.subnet_ids
+ security_group_ids = each.value.security_group_ids
+ route_table_ids = each.value.route_table_ids
+ auto_accept = each.value.auto_accept
+ private_dns_enabled = each.value.private_dns_enabled
+ name = each.value.name
+ tags = var.common_tags
+}
-
-## Requirements
+```
-| Name | Version |
-|------|---------|
-| [terraform](#requirement\_terraform) | >= 1.0 |
-| [aws](#requirement\_aws) | >= 5.30 |
+> **Note:**
+> The above example demonstrates how to use the module. All variables, resources, and outputs used here are already defined within this module.
-## Providers
-
-No providers.
-
-## Modules
-
-| Name | Source | Version |
-|------|--------|---------|
-| [name\_gateway\_ep](#module\_name\_gateway\_ep) | naming-tag | n/a |
-| [name\_gateway\_loadbalancer\_ep](#module\_name\_gateway\_loadbalancer\_ep) | naming-tag | n/a |
-| [name\_interface\_ep](#module\_name\_interface\_ep) | naming-tag | n/a |
-| [name\_security\_group](#module\_name\_security\_group) | naming-tag | n/a |
-| [security\_group](#module\_security\_group) | aws-security-group | n/a |
-| [vpc\_gateway\_endpoint](#module\_vpc\_gateway\_endpoint) | aws-gateway-vpc-endpoint | n/a |
-| [vpc\_gateway\_loadbalancer\_endpoint](#module\_vpc\_gateway\_loadbalancer\_endpoint) | aws-gateway-loadbalancer-vpc-endpoint | n/a |
-| [vpc\_interface\_endpoint](#module\_vpc\_interface\_endpoint) | aws-interface-vpc-endpoint | n/a |
+> **Related Module:**
+> If you're looking for a production-ready VPC setup with best practices (CIDR structure, subnets, route tables, flow logs, tagging, etc.), check out our
+> [Terraform AWS Network Skeleton](https://github.com/OT-CLOUD-KIT/terraform-aws-network-skeleton)
+---
## Resources
-No resources.
+| Name | Type |
+|------|------|
+| [aws_vpc_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
-| [app](#input\_app) | Name of the application, For ex: network, shared, ot etc. | `string` | n/a | yes |
-| [bu](#input\_bu) | Name of the business unit, For ex: bu which are supported by ot are: pcs, ultrasound etc. | `string` | n/a | yes |
-| [env](#input\_env) | Name of the environment example: for development env it should be 'd', prod env should be 'p', testing env should be 'q' and staging env should be's'. | `string` | n/a | yes |
-| [sg\_egress\_variables](#input\_sg\_egress\_variables) | List of egress rules for the security group | list(object({
cidr_blocks = optional(list(string))
description = optional(string)
from_port = number
to_port = number
protocol = string
})) | [| no | -| [sg\_ingress\_variables](#input\_sg\_ingress\_variables) | List of ingress rules for the security group |
{
"cidr_blocks": [],
"description": null,
"from_port": 0,
"protocol": "-1",
"to_port": 0
}
]
list(object({
cidr_blocks = optional(list(string))
description = optional(string)
from_port = number
to_port = number
protocol = string
})) | [| no | -| [sg\_tags](#input\_sg\_tags) | Tags for the security group | `map(string)` | `{}` | no | -| [tags](#input\_tags) | Tags for the security group | `map(string)` | `{}` | no | -| [tenant](#input\_tenant) | Name of the tenant | `string` | `""` | no | -| [vpc\_gateway\_ep\_list](#input\_vpc\_gateway\_ep\_list) | Map of all VPC gateway endpoints |
{
"cidr_blocks": [],
"description": null,
"from_port": 0,
"protocol": "-1",
"to_port": 0
}
]
map(object({
service_name = optional(string, null)
auto_accept = optional(bool, true)
policy = optional(any, {
Statement = [
{
Action = "*"
Effect = "Allow"
Principal = "*"
Resource = "*"
}
]
})
})) | `{}` | no |
-| [vpc\_gateway\_ep\_route\_table\_ids](#input\_vpc\_gateway\_ep\_route\_table\_ids) | Route table ids for all VPC gateway endpoints | `list(string)` | `[]` | no |
-| [vpc\_gateway\_ep\_tags](#input\_vpc\_gateway\_ep\_tags) | Tags for all VPC gateway endpoints | `map(string)` | `{}` | no |
-| [vpc\_gateway\_loadbalancer\_ep\_list](#input\_vpc\_gateway\_loadbalancer\_ep\_list) | Map of all VPC gateway loadbalancer endpoints | map(object({
service_name = optional(string, null)
ip_address_type = optional(string, null)
auto_accept = optional(bool, true)
})) | `{}` | no |
-| [vpc\_gateway\_loadbalancer\_ep\_subnet\_configuration](#input\_vpc\_gateway\_loadbalancer\_ep\_subnet\_configuration) | Subnet configuration for all VPC gateway loadbalancer endpoints | `list(any)` | `[]` | no |
-| [vpc\_gateway\_loadbalancer\_ep\_subnet\_ids](#input\_vpc\_gateway\_loadbalancer\_ep\_subnet\_ids) | Subnet ids for all VPC gateway loadbalancer endpoints | `list(string)` | `[]` | no |
-| [vpc\_gateway\_loadbalancer\_ep\_tags](#input\_vpc\_gateway\_loadbalancer\_ep\_tags) | Tags for all VPC gateway loadbalancer endpoints | `map(string)` | `{}` | no |
-| [vpc\_id](#input\_vpc\_id) | VPC ID for the composite module | `string` | n/a | yes |
-| [vpc\_interface\_ep\_list](#input\_vpc\_interface\_ep\_list) | Map of all VPC interface endpoints | map(object({
service_name = optional(string, null)
private_dns_enabled = optional(bool, true)
ip_address_type = optional(string, "ipv4")
auto_accept = optional(bool, true)
policy = optional(any, {
Statement = [
{
Action = "*"
Effect = "Allow"
Principal = "*"
Resource = "*"
}
]
})
})) | `{}` | no |
-| [vpc\_interface\_ep\_subnet\_ids](#input\_vpc\_interface\_ep\_subnet\_ids) | Subnet ids for all VPC interface endpoints | `list(string)` | `[]` | no |
-| [vpc\_interface\_ep\_tags](#input\_vpc\_interface\_ep\_tags) | Tags for all VPC interface endpoints | `map(string)` | `{}` | no |
+| [`vpc_id`](#input_vpc_id) | The ID of the VPC in which to create the endpoint(s) | `string` | n/a | yes|
+| [`common_tags`](#input_common_tags) | Common tags applied to all resources | `map(string)` | `{}` | No |
+| [`vpc_endpoints`](#input_vpc_endpoints) | Map of endpoint definitions with full configuration per endpoint | `map(object)` | `{}` | yes |
+| [`service_name`](#attr_service_name) | AWS service name (e.g., `com.amazonaws.us-east-1.s3`) | `string` | yes|yes|
+| [`vpc_endpoint_type`](#attr_vpc_endpoint_type) | Type of endpoint (`Interface` or `Gateway`) | `string` | yes|yes|
+| [`subnet_ids`](#attr_subnet_ids) | Subnet IDs (used for Interface endpoints) | `list(string)` | No |yes|
+| [`security_group_ids`](#attr_security_group_ids) | Security Group IDs (used for Interface endpoints) | `list(string)` | No |yes|
+| [`route_table_ids`](#attr_route_table_ids) | Route Table IDs (used for Gateway endpoints) | `list(string)` | No |yes|
+| [`auto_accept`](#attr_auto_accept) | Whether the endpoint connection should be auto-accepted | `bool` | No|yes|
+| [`private_dns_enabled`](#attr_private_dns_enabled) | Enable private DNS for the service (Interface only) | `bool` | No |No|
+
+---
## Outputs
| Name | Description |
|------|-------------|
-| [security\_group](#output\_security\_group) | Security group details |
-| [vpc\_endpoint](#output\_vpc\_endpoint) | VPC endpoint details |
-| [vpc\_endpoint\_id](#output\_vpc\_endpoint\_id) | Map of VPC endpoint IDs |
-| [vpc\_endpoint\_service\_name](#output\_vpc\_endpoint\_service\_name) | Map of VPC endpoint Service names |
-
+| [`vpc_endpoint_ids`](#vpc_endpoint_ids) | Map of VPC Endpoint IDs for all defined services |
+| [`vpc_endpoint_types`](#vpc_endpoint_types) | Map of VPC Endpoint Types (`Interface` or `Gateway`) |
+
+
+
+## Considerations
+- Ensure VPC, Subnets, and Route Tables are created beforehand.
+- Use appropriate naming conventions to match organizational standards.
+
+---
+
+## Contributors
+
+- [Piyush Upadhyay](https://github.com/piiiyuushh)
+- [Nikita Joshi](https://github.com/jnikita19)
+
diff --git a/example/backend.tf b/example/backend.tf
new file mode 100644
index 0000000..2ad3c20
--- /dev/null
+++ b/example/backend.tf
@@ -0,0 +1,8 @@
+terraform {
+ backend "s3" {
+ bucket = "ot-cloud-kit-bucket"
+ key = "ot/module/vpc-endpoint/terraform.tfstate"
+ region = "us-east-1"
+ encrypt = true
+ }
+}
\ No newline at end of file
diff --git a/example/main.tf b/example/main.tf
new file mode 100644
index 0000000..984686b
--- /dev/null
+++ b/example/main.tf
@@ -0,0 +1,15 @@
+module "vpc_endpoints" {
+ for_each = var.vpc_endpoints
+
+ source = "../"
+ vpc_id = var.vpc_id
+ service_name = each.value.service_name
+ vpc_endpoint_type = each.value.vpc_endpoint_type
+ subnet_ids = each.value.subnet_ids
+ security_group_ids = each.value.security_group_ids
+ route_table_ids = each.value.route_table_ids
+ auto_accept = each.value.auto_accept
+ private_dns_enabled = each.value.private_dns_enabled
+ name = each.value.name
+ tags = var.common_tags
+}
diff --git a/example/output.tf b/example/output.tf
new file mode 100644
index 0000000..bf7b0e3
--- /dev/null
+++ b/example/output.tf
@@ -0,0 +1,13 @@
+output "vpc_endpoint_ids" {
+ description = "Map of VPC Endpoint IDs for all defined services"
+ value = {
+ for k, mod in module.vpc_endpoints : k => mod.vpc_endpoint_id
+ }
+}
+
+output "vpc_endpoint_types" {
+ description = "Map of VPC Endpoint Types (Interface or Gateway)"
+ value = {
+ for k, mod in module.vpc_endpoints : k => mod.vpc_endpoint_type
+ }
+}
diff --git a/example/provider.tf b/example/provider.tf
new file mode 100644
index 0000000..e70fb2f
--- /dev/null
+++ b/example/provider.tf
@@ -0,0 +1,3 @@
+provider "aws" {
+ region = "us-east-1"
+}
\ No newline at end of file
diff --git a/example/terraform.tfvars b/example/terraform.tfvars
new file mode 100644
index 0000000..834449d
--- /dev/null
+++ b/example/terraform.tfvars
@@ -0,0 +1,22 @@
+vpc_id = "vpc-0bfa15004ff55e107"
+
+common_tags = {
+ Environment = "dev"
+ Project = "ot-cloud"
+ Owner = "nikita"
+}
+
+vpc_endpoints = {
+ s3_endpoint = {
+ service_name = "com.amazonaws.us-east-1.s3"
+ vpc_endpoint_type = "Gateway"
+ subnet_ids = ["subnet-08a2aa30dbc179a2b"]
+ security_group_ids = ["sg-04fb2f273d8865af3"]
+ route_table_ids = ["rtb-0f05d6fd762bf3a45"]
+ auto_accept = true
+ private_dns_enabled = false
+ name = "s3-endpoint"
+ }
+
+
+}
diff --git a/example/variable.tf b/example/variable.tf
new file mode 100644
index 0000000..03c7595
--- /dev/null
+++ b/example/variable.tf
@@ -0,0 +1,22 @@
+variable "vpc_id" {
+ type = string
+}
+
+variable "common_tags" {
+ type = map(string)
+ default = {}
+ description = "Tags applied to all endpoints"
+}
+
+variable "vpc_endpoints" {
+ type = map(object({
+ service_name = string
+ vpc_endpoint_type = string
+ subnet_ids = list(string)
+ security_group_ids = list(string)
+ route_table_ids = list(string)
+ auto_accept = bool
+ private_dns_enabled = bool
+ name = string
+ }))
+}
diff --git a/examples/maint.tf b/examples/maint.tf
deleted file mode 100644
index f4881f3..0000000
--- a/examples/maint.tf
+++ /dev/null
@@ -1,28 +0,0 @@
-module "standard_tags" {
- source = "git@github.com:OT-CLOUD-KIT/terraform-aws-standard-tagging.git?ref=dev"
- env = var.env
- app = var.app
- bu = var.bu
- program = "edcil"
- team = "lspl"
- region = "ap-south-1"
-}
-
-module "example_ep" {
- source = "../"
-
- env = var.env
- app = var.app
- bu = var.bu
- vpc_id = var.vpc_id
- tags = module.standard_tags.standard_tags
-
- # VPC Interface Endpoints
- vpc_interface_ep_list = var.vpc_interface_ep_list
- vpc_interface_ep_subnet_ids = var.vpc_interface_ep_subnet_ids
-
- # VPC Interface Endpoints
-
- vpc_gateway_ep_list = var.vpc_gateway_ep_list
- vpc_gateway_ep_route_table_ids = var.vpc_gateway_ep_route_table_ids
-}
diff --git a/examples/outputs.tf b/examples/outputs.tf
deleted file mode 100644
index 00b18f9..0000000
--- a/examples/outputs.tf
+++ /dev/null
@@ -1,7 +0,0 @@
-output "sg" {
- value = module.example_ep.security_group
-}
-
-output "interface_ep" {
- value = module.example_ep.vpc_endpoint
-}
diff --git a/examples/variables.tf b/examples/variables.tf
deleted file mode 100644
index 0705a9e..0000000
--- a/examples/variables.tf
+++ /dev/null
@@ -1,80 +0,0 @@
-# ------------------------------------------------------------
-# naming conventions variables
-# ------------------------------------------------------------
-variable "env" {
- description = "name of the environment"
- type = string
-}
-
-variable "bu" {
- description = "name of the business unit"
- type = string
-}
-
-variable "app" {
- description = "Name of the application, For ex: network, shared, ot etc."
- type = string
-}
-
-variable "tenant" {
- description = "Name of the tenant"
- type = string
- default = ""
-}
-
-variable "vpc_id" {
- description = "VPC ID for the security group"
- type = string
-}
-
-variable "vpc_interface_ep_list" {
- description = "Map of all VPC interface endpoints"
- type = map(object({
- service_name = optional(string, null)
- private_dns_enabled = optional(bool, true)
- ip_address_type = optional(string, "ipv4")
- auto_accept = optional(bool, true)
- policy = optional(any, {
- Statement = [
- {
- Action = "*"
- Effect = "Allow"
- Principal = "*"
- Resource = "*"
- }
- ]
- })
- }))
- default = {}
-}
-
-variable "vpc_interface_ep_subnet_ids" {
- description = "Subnet ids for all VPC interface endpoints"
- type = list(string)
- default = []
-}
-
-variable "vpc_gateway_ep_list" {
- description = "Map of all VPC gateway endpoints"
- type = map(object({
- service_name = optional(string, null)
- auto_accept = optional(bool, true)
- policy = optional(any, {
- Statement = [
- {
- Action = "*"
- Effect = "Allow"
- Principal = "*"
- Resource = "*"
- }
- ]
- })
- }))
- default = {}
-}
-
-variable "vpc_gateway_ep_route_table_ids" {
- description = "Route table ids for all VPC gateway endpoints"
- type = list(string)
- default = []
-}
diff --git a/main.tf b/main.tf
index 5361ac1..2de8f8c 100644
--- a/main.tf
+++ b/main.tf
@@ -1,176 +1,18 @@
-#-----------------------------------------------------------------------------------
-# Name for security for VPC Interface Endpoints
-#-----------------------------------------------------------------------------------
-module "name_security_group" {
- for_each = var.vpc_interface_ep_list
- source = "git@github.com:OT-CLOUD-KIT/terraform-aws-naming.git?ref=dev"
- bu = var.bu
- env = var.env
- app = var.app
- tenant = var.tenant
- resource = "${each.key}-sg"
-}
-
-#-----------------------------------------------------------------------------------
-# Security Group for VPC Interface Endpoints
-#-----------------------------------------------------------------------------------
-module "security_group" {
- for_each = var.vpc_interface_ep_list
- source = "git@github.com:OT-CLOUD-KIT/terraform-aws-security-groups.git?ref=v.0.0.4"
- vpc_id = var.vpc_id
- name = module.name_security_group[each.key].naming_tag[0]
- tags = merge(
- var.sg_tags,
- var.tags,
- {
- "Name" = module.name_security_group[each.key].naming_tag[0]
- }
- )
- aws_security_group_variables = [
- {
- aws_security_group_ingress = var.sg_ingress_variables
- aws_security_group_egress = var.sg_egress_variables
- }
- ]
-}
-
-#-----------------------------------------------------------------------------------
-# Name for VPC Interface Indpoints
-#-----------------------------------------------------------------------------------
-module "name_interface_ep" {
- for_each = var.vpc_interface_ep_list
- source = "git@github.com:OT-CLOUD-KIT/terraform-aws-naming.git?ref=dev"
-
- bu = var.bu
- env = var.env
- app = var.app
- tenant = var.tenant
- resource = "${each.key}-ep"
-}
-
-#-----------------------------------------------------------------
-# VPC interface endpoint(s)
-#-----------------------------------------------------------------
-resource "aws_vpc_endpoint" "interface_ep" {
- for_each = var.vpc_interface_ep_list
-
- vpc_endpoint_type = "Interface"
- service_name = var.vpc_interface_ep_list[each.key].service_name
- private_dns_enabled = try(var.vpc_interface_ep_list[each.key].private_dns_enabled, null)
- ip_address_type = try(var.vpc_interface_ep_list[each.key].ip_address_type, null)
- policy = can(var.vpc_interface_ep_list[each.key].policy) ? jsonencode(var.vpc_interface_ep_list[each.key].policy) : null
- auto_accept = try(var.vpc_interface_ep_list[each.key].auto_accept, null)
+resource "aws_vpc_endpoint" "this" {
vpc_id = var.vpc_id
- security_group_ids = module.security_group[each.key].id
- subnet_ids = var.vpc_interface_ep_subnet_ids
-
- dynamic "dns_options" {
- for_each = try([var.vpc_interface_ep_list[each.key].dns_options], [])
- content {
- dns_record_ip_type = try(dns_options.value.dns_options.dns_record_ip_type, null)
- private_dns_only_for_inbound_resolver_endpoint = try(dns_options.value.private_dns_only_for_inbound_resolver_endpoint, null)
- }
- }
-
- tags = merge(
- var.vpc_interface_ep_tags,
- var.tags,
- {
- "Name" = module.name_interface_ep[each.key].naming_tag[0]
- }
- )
-
- lifecycle {
- ignore_changes = [vpc_id]
- }
-}
-
-#-----------------------------------------------------------------------------------
-# Name for VPC Gateway Endpoints
-#-----------------------------------------------------------------------------------
-module "name_gateway_ep" {
- for_each = var.vpc_gateway_ep_list
- source = "git@github.com:OT-CLOUD-KIT/terraform-aws-naming.git?ref=dev"
-
- bu = var.bu
- env = var.env
- app = var.app
- tenant = var.tenant
- resource = "${each.key}-ep"
-}
-
-#-----------------------------------------------------------------------------------
-# VPC Gateway Endpoint(s)
-#-----------------------------------------------------------------------------------
-resource "aws_vpc_endpoint" "gateway_ep" {
- for_each = var.vpc_gateway_ep_list
-
- vpc_endpoint_type = "Gateway"
- service_name = var.vpc_gateway_ep_list[each.key].service_name
- auto_accept = try(var.vpc_gateway_ep_list[each.key].auto_accept, null)
-
- vpc_id = var.vpc_id
- route_table_ids = var.vpc_gateway_ep_route_table_ids
-
- tags = merge(
- var.vpc_gateway_ep_tags,
- var.tags,
- {
- "Name" = module.name_gateway_ep[each.key].naming_tag[0]
- }
- )
-
- lifecycle {
- ignore_changes = [vpc_id]
- }
-}
-
-#-----------------------------------------------------------------------------------
-# Name for VPC Gateway Loadbalancer Endpoints
-#-----------------------------------------------------------------------------------
-module "name_gateway_loadbalancer_ep" {
- for_each = var.vpc_gateway_loadbalancer_ep_list
- source = "git@github.com:OT-CLOUD-KIT/terraform-aws-naming.git?ref=dev"
- bu = var.bu
- env = var.env
- app = var.app
- tenant = var.tenant
- resource = "${each.key}-ep"
-}
-
-#-----------------------------------------------------------------------------------
-# Name for VPC Gateway Loadbalancer Endpoint(s)
-#-----------------------------------------------------------------------------------
-resource "aws_vpc_endpoint" "gateway_loadbalancer_ep" {
- for_each = var.vpc_gateway_loadbalancer_ep_list
-
- vpc_endpoint_type = "GatewayLoadBalancer"
- service_name = var.vpc_gateway_loadbalancer_ep_list[each.key].service_name
- auto_accept = var.vpc_gateway_loadbalancer_ep_list[each.key].auto_accept
- ip_address_type = var.vpc_gateway_loadbalancer_ep_list[each.key].ip_address_type
- policy = can(var.vpc_gateway_loadbalancer_ep_list[each.key].policy) ? jsonencode(var.vpc_gateway_loadbalancer_ep_list[each.key].policy) : null
-
- vpc_id = var.vpc_id
- subnet_ids = var.vpc_gateway_loadbalancer_ep_subnet_ids
+ service_name = var.service_name
+ vpc_endpoint_type = var.vpc_endpoint_type
+ auto_accept = var.auto_accept
+ private_dns_enabled = var.private_dns_enabled
- tags = merge(
- var.vpc_gateway_ep_tags,
- var.tags,
- {
- "Name" = module.name_gateway_loadbalancer_ep[each.key].naming_tag[0]
- }
- )
+ # Only for Interface
+ subnet_ids = var.vpc_endpoint_type == "Interface" ? var.subnet_ids : null
+ security_group_ids = var.vpc_endpoint_type == "Interface" ? var.security_group_ids : null
- dynamic "subnet_configuration" {
- for_each = try(var.vpc_gateway_loadbalancer_ep_subnet_configuration, [])
- content {
- ipv4 = subnet_configuration.value.ipv4
- ipv6 = subnet_configuration.value.ipv6
- subnet_id = subnet_configuration.value.subnet_id
- }
- }
+ # Only for Gateway
+ route_table_ids = var.vpc_endpoint_type == "Gateway" ? var.route_table_ids : null
- lifecycle {
- ignore_changes = [vpc_id]
- }
+ tags = merge(var.tags, {
+ Name = var.name
+ })
}
diff --git a/output.tf b/output.tf
new file mode 100644
index 0000000..fcbd227
--- /dev/null
+++ b/output.tf
@@ -0,0 +1,7 @@
+output "vpc_endpoint_id" {
+ value = aws_vpc_endpoint.this.id
+}
+
+output "vpc_endpoint_type" {
+ value = aws_vpc_endpoint.this.vpc_endpoint_type
+}
diff --git a/outputs.tf b/outputs.tf
deleted file mode 100644
index 64afb6e..0000000
--- a/outputs.tf
+++ /dev/null
@@ -1,73 +0,0 @@
-output "security_group" {
- description = "Security group details"
- value = {
- "id" = flatten([for sg in module.security_group : sg.id]),
- "name" = flatten([for sg in module.security_group : sg.name]),
- "arn" = flatten([for sg in module.security_group : sg.arn]),
- "type" = "security-group"
- }
-}
-
-output "vpc_endpoint" {
- description = "VPC endpoint details"
- value = {
- id = flatten(concat([for ep in aws_vpc_endpoint.interface_ep : ep.id],[for ep in aws_vpc_endpoint.gateway_ep: ep.id], [for ep in aws_vpc_endpoint.gateway_loadbalancer_ep: ep.id]))
- arn = flatten(concat([for ep in aws_vpc_endpoint.interface_ep : ep.arn],[for ep in aws_vpc_endpoint.gateway_ep : ep.id], [for ep in aws_vpc_endpoint.gateway_loadbalancer_ep : ep.id]))
- name = flatten(concat([for ep in aws_vpc_endpoint.interface_ep : ep.arn],[for ep in aws_vpc_endpoint.gateway_ep : ep.id], [for ep in aws_vpc_endpoint.gateway_loadbalancer_ep : ep.id]))
- service_name = flatten(concat([for ep in aws_vpc_endpoint.interface_ep : ep.arn],[for ep in aws_vpc_endpoint.gateway_ep: ep.id], [for ep in aws_vpc_endpoint.gateway_loadbalancer_ep : ep.id]))
- type = "vpc-endpoint"
- }
-}
-
-# output "vpc_endpoint_id" {
-# description = "Map of VPC endpoint IDs"
-# value = {
-# for key, ep in module.vpc_interface_endpoint : key => ep.id
-# }
-# }
-
-# output "vpc_endpoint_service_name" {
-# description = "Map of VPC endpoint Service names"
-# value = merge(
-# {
-# for key, ep in module.vpc_interface_endpoint : key => ep.service_name
-# },
-# {
-# for key, ep in module.vpc_gateway_endpoint : key => ep.service_name
-# },
-# {
-# for key, ep in module.vpc_gateway_loadbalancer_endpoint : key => ep.service_name
-# }
-# )
-# }
-
-# output "vpc_endpoint_service_name" {
-# description = "Map of VPC endpoint service names"
-# value = {
-# for k, v in var.vpc_interface_ep_list : k => {
-# service_name = v.service_name
-# }
-# }
-# }
-
-
-
-# output "vpc_endpoint_ip_address" {
-# description = "Map of ip address for all VPC endpoints"
-# value = merge(
-# {
-# for key, ep in module.vpc_interface_endpoint : key => ep.vpc_interface_endpoint_ip_address
-# },
-# {
-# for key, ep in module.vpc_gateway_endpoint : key => ep.vpc_gateway_endpoint_ip_address
-# },
-# {
-# for key, ep in module.vpc_gateway_loadbalancer_endpoint : key => ep.vpc_gateway_loadbalancer_endpoint_ip_address
-# }
-# )
-# }
-
-# output "vpc_id" {
-# description = "The VPC ID where interface endpoints are created"
-# value = var.vpc_id
-# }
diff --git a/variable.tf b/variable.tf
new file mode 100644
index 0000000..224d639
--- /dev/null
+++ b/variable.tf
@@ -0,0 +1,45 @@
+variable "vpc_id" {
+ type = string
+}
+
+variable "service_name" {
+ type = string
+}
+
+variable "vpc_endpoint_type" {
+ type = string
+}
+
+variable "subnet_ids" {
+ type = list(string)
+ default = []
+}
+
+variable "security_group_ids" {
+ type = list(string)
+ default = []
+}
+
+variable "route_table_ids" {
+ type = list(string)
+ default = []
+}
+
+variable "auto_accept" {
+ type = bool
+ default = false
+}
+
+variable "private_dns_enabled" {
+ type = bool
+ default = false
+}
+
+variable "name" {
+ type = string
+}
+
+variable "tags" {
+ type = map(string)
+ default = {}
+}
diff --git a/variables.tf b/variables.tf
deleted file mode 100644
index 9cf294f..0000000
--- a/variables.tf
+++ /dev/null
@@ -1,188 +0,0 @@
-#-----------------------------------------------------------------------------------
-# Common variables
-#-----------------------------------------------------------------------------------
-variable "vpc_id" {
- description = "VPC ID for the composite module"
- type = string
-}
-
-variable "tags" {
- description = "Tags for the security group"
- type = map(string)
- default = {}
-}
-
-#-----------------------------------------------------------------------------------
-# Naming and Tag variables
-#-----------------------------------------------------------------------------------
-variable "bu" {
- description = "Name of the business unit, For ex: bu which are supported by DDP are: pcs, ultrasound etc."
- type = string
-}
-
-variable "env" {
- description = "Name of the environment example: for development env it should be 'd', prod env should be 'p', testing env should be 'q' and staging env should be's'."
- type = string
-}
-
-variable "app" {
- description = "Name of the application, For ex: network, shared, ddp etc."
- type = string
-}
-
-variable "tenant" {
- description = "Name of the tenant"
- type = string
- default = ""
-}
-
-#-----------------------------------------------------------------------------------
-# Security group variables
-#-----------------------------------------------------------------------------------
-variable "sg_tags" {
- description = "Tags for the security group"
- type = map(string)
- default = {}
-}
-
-variable "sg_ingress_variables" {
- description = "List of ingress rules for the security group"
- type = list(object({
- cidr_blocks = optional(list(string))
- description = optional(string)
- from_port = number
- to_port = number
- protocol = string
- }))
- default = [
- {
- cidr_blocks = []
- description = null
- from_port = 0
- to_port = 0
- protocol = "-1"
- }
- ]
-}
-
-variable "sg_egress_variables" {
- description = "List of egress rules for the security group"
- type = list(object({
- cidr_blocks = optional(list(string))
- description = optional(string)
- from_port = number
- to_port = number
- protocol = string
- }))
- default = [
- {
- cidr_blocks = []
- description = null
- from_port = 0
- to_port = 0
- protocol = "-1"
- }
- ]
-}
-
-#-----------------------------------------------------------------------------------
-# VPC interface endpoint variables
-#-----------------------------------------------------------------------------------
-variable "vpc_interface_ep_tags" {
- description = "Tags for all VPC interface endpoints"
- type = map(string)
- default = {}
-}
-
-variable "vpc_interface_ep_list" {
- description = "Map of all VPC interface endpoints"
- type = map(object({
- service_name = optional(string, null)
- private_dns_enabled = optional(bool, true)
- ip_address_type = optional(string, "ipv4")
- auto_accept = optional(bool, true)
- policy = optional(any, {
- Statement = [
- {
- Action = "*"
- Effect = "Allow"
- Principal = "*"
- Resource = "*"
- }
- ]
- })
- }))
- default = {}
-}
-
-variable "vpc_interface_ep_subnet_ids" {
- description = "Subnet ids for all VPC interface endpoints"
- type = list(string)
- default = []
-}
-
-#-----------------------------------------------------------------------------------
-# VPC gateway endpoint variables
-#-----------------------------------------------------------------------------------
-variable "vpc_gateway_ep_tags" {
- description = "Tags for all VPC gateway endpoints"
- type = map(string)
- default = {}
-}
-
-variable "vpc_gateway_ep_list" {
- description = "Map of all VPC gateway endpoints"
- type = map(object({
- service_name = optional(string, null)
- auto_accept = optional(bool, true)
- policy = optional(any, {
- Statement = [
- {
- Action = "*"
- Effect = "Allow"
- Principal = "*"
- Resource = "*"
- }
- ]
- })
- }))
- default = {}
-}
-
-variable "vpc_gateway_ep_route_table_ids" {
- description = "Route table ids for all VPC gateway endpoints"
- type = list(string)
- default = []
-}
-
-#-----------------------------------------------------------------------------------
-# VPC gateway loadbalancer endpoint variables
-#-----------------------------------------------------------------------------------
-variable "vpc_gateway_loadbalancer_ep_tags" {
- description = "Tags for all VPC gateway loadbalancer endpoints"
- type = map(string)
- default = {}
-}
-
-variable "vpc_gateway_loadbalancer_ep_list" {
- description = "Map of all VPC gateway loadbalancer endpoints"
- type = map(object({
- service_name = optional(string, null)
- ip_address_type = optional(string, null)
- auto_accept = optional(bool, true)
- }))
- default = {}
-}
-
-variable "vpc_gateway_loadbalancer_ep_subnet_ids" {
- description = "Subnet ids for all VPC gateway loadbalancer endpoints"
- type = list(string)
- default = []
-}
-
-variable "vpc_gateway_loadbalancer_ep_subnet_configuration" {
- description = "Subnet configuration for all VPC gateway loadbalancer endpoints"
- type = list(any)
- default = []
-}
-