Skip to content
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: enhance naming for vpc resources and fix prefix checks #685

Closed
wants to merge 30 commits into from

Conversation

rajatagarwal-ibm
Copy link
Member

Description

Addresses:

Release required?

  • No release
  • Patch release (x.x.X)
  • Minor release (x.X.x)
  • Major release (X.x.x)
Release notes content

Run the pipeline

If the CI pipeline doesn't run when you create the PR, the PR requires a user with GitHub collaborators access to run the pipeline.

Run the CI pipeline when the PR is ready for review and you expect tests to pass. Add a comment to the PR with the following text:

/run pipeline

Checklist for reviewers

  • If relevant, a test for the change is included or updated with this PR.
  • If relevant, documentation for the change is included or updated with this PR.

For mergers

  • Use a conventional commit message to set the release level. Follow the guidelines.
  • Include information that users need to know about the PR in the commit message. The commit message becomes part of the GitHub release notes.
  • Use the Squash and merge option.

@rajatagarwal-ibm
Copy link
Member Author

While the code says public gateway creation is optional (

# Public Gateways (Optional)
) but in reality I have found that those are always created. For example, I need to add the public_gateway_name variable to make an "existing_vpc" example.

If we want to keep the public gateway optional - perhaps we need to create a flag or something else in the logic

@rajatagarwal-ibm
Copy link
Member Author

Ran every test locally and also ran hub-spoke-manual-resolver apply (doesn't have test) - everything worked fine.

@rajatagarwal-ibm
Copy link
Member Author

rajatagarwal-ibm commented Dec 4, 2023

Need to skip the upgrade test as there is a change of the vpc name in the main.tf (consumers won't be impacted as var.name is unchanged.)

Not skipping upgrade test anymore as reverted changes back on the vpc name with prefix.

@ocofaigh
Copy link
Member

ocofaigh commented Dec 5, 2023

@rajatagarwal-ibm It seems you added several things since skipping the upgrade test so I'm not comfortable with it being skipped. Can you unskip it (use commit with UNSKIP UPGRADE TEST) and paste the results. We can then make a call on skipping it if no breaking changes are identified.

@rajatagarwal-ibm
Copy link
Member Author

@ocofaigh

The upgrade test fails only because of the change in the VPC name, here:
name = var.prefix != null ? "${var.prefix}-vpc" : var.name

Local run test result:

TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:   # module.slz_vpc.ibm_is_vpc.vpc[0] will be updated in-place
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:   ~ resource "ibm_is_vpc" "vpc" {
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:         id                          = "r042-e8e37261-70f4-4951-b2ea-a48baf273fd3"
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:       ~ name                        = "slz-vpc-upg-hki9xw-vpc-vpc" -> "slz-vpc-upg-hki9xw-vpc"
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:         tags                        = []
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:         # (25 unchanged attributes hidden)
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185: 
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:         # (1 unchanged block hidden)
TestRunUpgradeDefaultExample 2023-12-06T09:51:28Z command.go:185:     }

I didn't like the naming this way so removed one variable, but I guess I will revert it back as its not required as part of this issue.

Copy link
Member

@ocofaigh ocofaigh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rajatagarwal-ibm See my comments please

tests/pr_test.go Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
variable "public_gateway_name" {
description = "The name of the public gateway"
type = string
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a new variable, can you just hard code the variable values in the main.tf of the existing_vpc example main.tf ?

examples/existing_vpc/main.tf Show resolved Hide resolved
variables.tf Outdated
@@ -3,11 +3,47 @@
##############################################################################

variable "name" {
description = "The name to give the newly provisioned VPC. Only used if 'create_vpc' is true."
description = "The name to give the provisioned VPC. Only used if 'create_vpc' is true."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, name is also used for other resources, not just the VPC. I would update this to:

"The string to use for the naming of VPC resources."

I think you should also then add a new variable called vpc_name which can be used to explicitly name the VPC.

Copy link
Member Author

@rajatagarwal-ibm rajatagarwal-ibm Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is being consumed in the SLZ module. Any changes which we make here with name will impact that too. I don't think so that's needed. Hence my proposal is I can rename the description to the following:

"The string to use for the naming of VPC, when var.create_vpc is true. This string also use for the naming of VPC resources."

main.tf Outdated
@@ -193,7 +198,7 @@ resource "time_sleep" "wait_for_authorization_policy" {

resource "ibm_is_vpc_routing_table" "route_table" {
for_each = module.dynamic_values.routing_table_map
name = var.prefix != null ? "${var.prefix}-${var.name}-route-${each.value.name}" : "${var.name}-route-${each.value.name}"
name = var.prefix != null ? "${var.prefix}-${var.name}-route-${each.value.name}" : "${var.routing_table_name}-${each.value.name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason to add var.routing_table_name - you can achieve this naming with the current code using var.name. There can be multiple routing tables here, so we will always be appending ${each.value.name} to the name here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the objective of the task is to give freedom to the user to name it anything they like, I have added these as variables. If they don't provide the value then it will pick up either prefix or name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how are you going to handle the naming of multiple routing tables with 1 string variable. You dont want them all named the same, so hence you will need to use ${each.value.name} in the naming

main.tf Outdated
@@ -228,7 +233,7 @@ locals {

resource "ibm_is_public_gateway" "gateway" {
for_each = local.gateway_object
name = var.prefix != null ? "${var.prefix}-${var.name}-public-gateway-${each.key}" : "${var.name}-public-gateway-${each.key}"
name = var.prefix != null ? "${var.prefix}-${var.name}-public-gateway-${each.key}" : "${var.public_gateway_name}-${each.key}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason to add var.public_gateway_name - you can achieve this naming with the current code using var.name. There can be multiple public gateways here, so we will always be appending ${each.value.name} to the name here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the objective of the task is to give freedom to the user to name it anything they like, I have added these as variables. If they don't provide the value then it will pick up either prefix or name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as #685 (comment)

variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
Copy link
Member

@vburckhardt vburckhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Rajat, some comments

main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
@rajatagarwal-ibm
Copy link
Member Author

/run pipeline

@vburckhardt
Copy link
Member

/run pipeline

@rajatagarwal-ibm
Copy link
Member Author

/run pipeline

@rajatagarwal-ibm
Copy link
Member Author

/run pipeline

SKIP UPGRADE TEST: removed vpc from prefix name in gateway name
@rajatagarwal-ibm
Copy link
Member Author

/run pipeline

Copy link
Member

@ocofaigh ocofaigh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rajatagarwal-ibm I left some comments - maybe we need to jump on a call to discuss how we want this to look as its starting to get confusing now to support all the use cases

dynamic_values.tf Outdated Show resolved Hide resolved
main.tf Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
SKIP UPGRADE TEST: removed vpc from prefix name in gateway name
main.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
main.tf Outdated
resource_group = var.resource_group_id
classic_access = var.classic_access
# address prefix is set to auto only if no address prefixes NOR any subnet is passed as input
address_prefix_management = (length([for prefix in values(coalesce(var.address_prefixes, {})) : prefix if prefix != null]) != 0) || (length([for subnet in values(coalesce(var.subnets, {})) : subnet if subnet != null]) != 0) ? "manual" : null
address_prefix_management = length([for prefix in values(coalesce(var.address_prefixes, {})) : prefix if prefix != null]) != 0 ? "manual" : null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
SKIP UPGRADE TEST: removed vpc from prefix name in gateway name
@rajatagarwal-ibm
Copy link
Member Author

rajatagarwal-ibm commented Dec 22, 2023

Created #697 since we can no longer bypass the upgrade test in this PR

This can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants