-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add custom subnet names #816
feat: Add custom subnet names #816
Conversation
main.tf
Outdated
@@ -389,6 +393,10 @@ resource "aws_subnet" "private" { | |||
ipv6_cidr_block = var.enable_ipv6 && length(var.private_subnet_ipv6_prefixes) > 0 ? cidrsubnet(aws_vpc.this[0].ipv6_cidr_block, 8, var.private_subnet_ipv6_prefixes[count.index]) : null | |||
|
|||
tags = merge( | |||
length(var.private_subnet_names) > 0 ? | |||
{ | |||
"Name" = element(var.private_subnet_names, count.index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your approach would make sense to keep the az value appended? e.g.
"Name" = element(var.private_subnet_names, count.index) | |
"Name" = format( | |
"${element(var.private_subnet_names, count.index)}-%s", | |
element(var.azs, count.index), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@v-rosa Thank you for the suggestion. I tested this out and it worked well. I rebased my branch onto latest master, and while I did so I also re-wrote my original commit to include your suggested change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I don't get it. Why would you append AZ when you want to control subnet names manually? Is this the whole point of this PR - to be able to set custom names to subnets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you define your network with multiple AZs, e.g. 3, you would get per custom name, 3 subnets with the same custom name. Also the naming wouldn't be consistent with the other subnets created using default naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@v-rosa I think default naming
and custom naming
are two separate things, you usually want to pick just one approach. If you want to include AZ to your custom naming
you just do something like this
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.14.4"
name = "development"
azs = ["us-west-2a", "us-west-2b"]
public_subnets = ["10.16.0.0/21", "10.16.8.0/21"]
...
public_subnet_names = ["mysuper-custom-name-us-west-2a", "another-name-us-west-2b"]
}
In my case I don't want to include AZ to my custom subnet schema, I should be able to do that since it's custom :)
Anyone still working on this PR? |
@NIXKnight Yes, I am still interested in bringing this PR out of draft status and getting it accepted. I plan to finish a minor detail and publish it today. |
I was about to make my PR to be able to provide custom tags per a subnet, tho just found your PR, and it actually looks fantastic! I like the tag name auto-generation compatibility part. I think forcefully inserting the availability zone at the end of a custom name is redundant. Why would you do it if you want to manually control the names of your subnets? |
@rooty0 Thanks for the support on this PR. Your question about forcing the availability zone has me thinking again, because my first pass at this did not include the AZ in the name for simplicity. Your question also made me realize that, as implemented at the current moment in this PR, this feature should have also considered the I think it would be good for me to change this as you suggest, but also include an example Terraform snippet that could generate a naming convention based on a |
Adds optional inputs that specify strings to assign to the tags.Name property of private and public subnets. Includes example usage in complete-vpc example.
I updated the PR description to reflect the change (which I rewrote over the old commit to try and keep the review neat and readable). The snippet I came up with to generate names is a bit messy. Any ways to neaten it up would be welcome. Put this into a new file in its own directory and run locals {
app_names = ["Alpha private", "Beta private"]
azs = ["eu-west-1a", "eu-west-1b"]
}
output "example" {
value = split(";", trim(join("", flatten([for k, v in local.app_names : [for a, b in local.azs : "${v} ${b};"]])), ";"))
} |
Hello there! When is going to be merged this PR? I am really interested! Thanks. |
I added example PR with code how external subnets can be created in VPC. |
@antonbabenko any chance you can review/merge this please? |
This would be also usefull when you have private subnets and want to have separate EKS subnets. |
Yes I create my code to create additional subnets, when I need to create dedicated EKS subnets. |
@lordz-md Here we go! Thank you, @andrewtcymmer , for the PR! |
## [3.17.0](v3.16.1...v3.17.0) (2022-10-21) ### Features * Add custom subnet names ([#816](#816)) ([4416e37](4416e37))
This PR is included in version 3.17.0 🎉 |
Co-authored-by: Anton Babenko <anton@antonbabenko.com>
## [3.17.0](terraform-aws-modules/terraform-aws-vpc@v3.16.1...v3.17.0) (2022-10-21) ### Features * Add custom subnet names ([terraform-aws-modules#816](terraform-aws-modules#816)) ([4416e37](terraform-aws-modules@4416e37))
I recently opened a PR to have separated EKS subnets also. |
This feature is not working. Here is my network.tf file. `provider "aws" { locals { tags = { ################################################################################ VPC Module -################################################################################ name = "blue-vpn-vpc" azs = ["${local.region}a", "${local.region}b", "${local.region}c"] private_subnet_names = ["blue-subnet-us-gov-west-1a", "blue-subnet-us-gov-west-1b", "blue-subnet-us-gov-west-1c"] VPC Flow Logs (Cloudwatch log group and IAM role will be created)enable_flow_log = true create_vpc = true create_database_internet_gateway_route = false create_igw = true create_redshift_subnet_group = false manage_default_network_acl = true manage_default_route_table = true manage_default_security_group = true enable_dns_hostnames = true enable_nat_gateway = false customer_gateways = {IP1 = {bgp_asn = 65112ip_address = "1.2.3.4"device_name = "some_name"},IP2 = {bgp_asn = 65112ip_address = "5.6.7.8"}}enable_vpn_gateway = false enable_dhcp_options = true tags = local.tags This results in subnets all created with the name name from locals.name You can see the local.name repeated for the Name of the Subnets. Name | Subnet ID | State | VPC | IPv4 CIDR |
Hey, this didn't work on my side too. module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.18.1"
name = "${var.prefix}-vpc-default"
cidr = var.cidr
azs = var.azs
private_subnets = local.private_subnets
public_subnets = local.public_subnets
private_subnet_names = local.private_subnet_names
public_subnet_names = local.public_subnet_names
.... |
@balq60 @dduzgun-security |
The problem for me was no support for Terraform files.
So if your file type is not supported it won’t work. Even if they are in
the root folder
Bernie
…On Wed, Nov 23, 2022 at 12:32 PM Deniz Onur Duzgun ***@***.***> wrote:
Hey, this didn't work on my side too.
Subnet names are not changed.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.18.1"
name = "${var.prefix}-vpc-default"
cidr = var.cidr
azs = var.azs
private_subnets = local.private_subnets
public_subnets = local.public_subnets
private_subnet_names = local.private_subnet_names
public_subnet_names = local.public_subnet_names....
—
Reply to this email directly, view it on GitHub
<#816 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGNQUZSZLV547LXD6K6SJ3TWJZPL5ANCNFSM5354RR7Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
What?! |
Terraform files end in .tf
If you look at the code, there is no filter for .tf files.
So they get ignored.
…-Bernie
On Wed, Nov 23, 2022 at 4:50 PM Bryant Biggs ***@***.***> wrote:
The problem for me was no support for Terraform files.
So if your file type is not supported it won’t work. Even if they are in
the root folder
What?!
—
Reply to this email directly, view it on GitHub
<#816 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGNQUZWCZZSA4UOWUVAJN5LWJ2NSRANCNFSM5354RR7Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@balq60 @dduzgun-security @rooty0 @andrewtcymmer |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Description
This PR adds the option to override the values used in resource tags with key "Name" (Name tags) with a list of strings, on public and private subnets. By default (if the optional variables are not specified, or if they are empty arrays), the module will generate the same Name tag values it did prior to this change.
Please reference issue #817 requesting this feature.
Motivation and Context
For VPCs which support multiple applications in multiple subnets, allowing the module to generate Name tags on subnets may cause multiple subnets to have the same value for their Name tag. Example VPC which generates such a condition, using two groups of private subnets:
It may be useful to specify the names of the subnets from the consumer side of the module, rather than let the module generate it. Proposed solution:
This solution also accommodates a case where a consumer would want to generate their own naming convention. As an example, consider the example below which adds in the availability zone to the names.
Breaking Changes
This change should be backwards compatible with the current major version, since the change adds an optional (opt-in) variable.
How Has This Been Tested?
examples/*
to demonstrate and validate my change(s)I have tested and validated these changes using one or more of the providedI have run this change with a Terraform project in my organization. That project has the characteristics explained in the Motivation and Context section above (the example is the same concept, but reduced to simplest terms and scrubbed of company-specific information). PR includes updates to theexamples/*
projectsexamples/*
which are exactly the same as I have tested on my project.pre-commit run -a
on my pull request