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

redevelop the VPC module upgrade to Terraform 0.12 #28

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

brianmori
Copy link

Hi @xiaozhu36

I redeveloped the VPC module to include different resources (NAT GW, CEN, ...) and the use of Terraform 0.12 constructs.

Local tests are fine and we will deploy the module on the final infrastructure in the coming days.
Please let me know your thoughts

P.S.: I need to readapt some part of the documentation

@jeanpierremilan
Copy link

+1

2 similar comments
@supertom25
Copy link

+1

@supertom25
Copy link

👍

@xiaozhu36
Copy link
Contributor

xiaozhu36 commented Aug 19, 2020

@brianmori I am sorry for late reply. Thanks for your contribution. I think this PR should be submitted into https://github.com/terraform-alicloud-modules/terraform-alicloud-network-with-nat. Please check it.

@brianmori
Copy link
Author

@brianmori I am sorry for late reply. Thanks for your contribution. I think this PR should be submitted into https://github.com/terraform-alicloud-modules/terraform-alicloud-network-with-nat. Please check it.

Hi @xiaozhu36

the repository https://github.com/terraform-alicloud-modules/terraform-alicloud-network-with-nat actually calls different Alicloud modules. It is not an implementation like the PR I did.

The goal of my PR is to have this repository/module to provision the Alicloud Network with different resources and different topologies.

  • VPC (optional in the context of Shared VPC, this module can be used to create only the VSwitches)

  • VSwitch (optional in the context of Shared VPC, this module can be used to create only the VPC)

  • Route Table

  • CEN Grant (optional)

  • NAT Gateway (optional)

Alicloud supports "Standalone/Standard" VPC and "Shared VPC".

The Alicloud NAT Gateway is optional as companies may prefer a different solution to allow egress traffic to the internet.
I thought about the Alicloud NAT Gateway SNATs and I think I should remove it from this module because it should be managed externally with this module: https://github.com/terraform-alicloud-modules/terraform-alicloud-snat
It has dependencies with the VPC and VSwitches.

@brianmori
Copy link
Author

I removed the SNAT from this module as it would require to cover multiple use cases and not only the NAT Gateway. What do you think of my latest commit?

main.tf Outdated

resource "alicloud_nat_gateway" "this" {
count = var.create_nat_gateway ? 1 : 0
vpc_id = alicloud_vpc.this[0].id
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this PR have a test?
I think there is a potential issue: if create_vpc = false, the alicloud_vpc.this will be null and there will throw an error.
In addition, this resource does not support the var.vpc_id.

Copy link
Author

Choose a reason for hiding this comment

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

The NAT Gateway would be provisioned for this VPC as it is a 'VPC resource'. It is not going to be created for a different VPC, henceforth the only VPC ID will be the one of the VPC created in this module.
I have not found a test pipeline for this module, I only did local tests

I did the modification to support the var.vpc_id although the aim of this module is to provision a complete alibaba network

output "this_vpc_id" {
description = "The VPC id"
value = local.this_vpc_id
output "vpc_cidr_block" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this_vpc_id is ok and why change it to vpc_id?

Copy link
Author

Choose a reason for hiding this comment

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

it is to be consistent with the other outputs of vpc

Copy link
Contributor

Choose a reason for hiding this comment

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

The other outputs of vpc also have a prefix this_

Copy link
Contributor

Choose a reason for hiding this comment

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

If not, I think them should be added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please improve the outputs and set a prefix this_ for them.

Copy link
Author

Choose a reason for hiding this comment

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

I am a bit lost on the advantage to use "this". When I saw other Terraform modules in GitHub, the maintainer omits the name of the resource, in this case "this" because it is unique.

You can take as example these other alibaba modules:

I propose I add the "this" and I keep also the other ones.

As for the description, the "The VPC id" is the actual description of today's module. How do you suggest to improve ?
"The VPC id created by the Terraform module" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think "The VPC id created by the Terraform module." is ok. But, I think there is no need to keep both. Other modules' outputs also need to be improved. The module https://github.com/terraform-alicloud-modules/terraform-alicloud-kubernetes/blob/master/outputs.tf has not improved yet. But most modules have had this prefix for each output.

Copy link
Author

Choose a reason for hiding this comment

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

I have not worked on the alicloud kubernetes, no PRs from my side at the moment. I looked at other official terraform modules and "this" or other identifiers are not used when there is only one type of resource.
I think we should follow this current best practice as it is also easier to read

In any case, I removed the duplicates ,)

variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated
resource "alicloud_nat_gateway" "this" {
count = var.create_nat_gateway ? 1 : 0
vpc_id = local.vpc_id
name = var.vpc_name
Copy link
Contributor

Choose a reason for hiding this comment

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

why use vpc_name to name nat gateway?

Copy link
Author

Choose a reason for hiding this comment

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

As there is one NAT Gateway per VPC, it could make sense to name it the same.
I am going to add a custom value decided by the user and as default value I propose to put the vpc_name. Does it work for you?

main.tf Outdated

# create one or more eips for NAT GW
resource "alicloud_eip" "nat" {
name = var.vpc_name
Copy link
Contributor

Choose a reason for hiding this comment

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

still applies

Copy link
Author

Choose a reason for hiding this comment

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

The goal of this module is to bootstrap the network, it is not meant to provision single resources. In any case, I add the option to customize the name

main.tf Outdated Show resolved Hide resolved
output "this_vpc_id" {
description = "The VPC id"
value = local.this_vpc_id
output "vpc_cidr_block" {
Copy link
Contributor

Choose a reason for hiding this comment

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

The other outputs of vpc also have a prefix this_

output "this_vpc_id" {
description = "The VPC id"
value = local.this_vpc_id
output "vpc_cidr_block" {
Copy link
Contributor

Choose a reason for hiding this comment

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

If not, I think them should be added.

outputs.tf Outdated Show resolved Hide resolved
description = "List of vswitch tags."
value = alicloud_vswitch.vswitches.*.tags
output "nat_gateway_dnat_table_ids" {
description = "The DNAT table of the NAT Gateway"
Copy link
Contributor

Choose a reason for hiding this comment

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

One nat gateway only has one dnat table. Please use nat_gateway_dnat_table_id instead.

Copy link
Author

Choose a reason for hiding this comment

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

I think it should be corrected also in the attributes of the resource because it returns forward_table_ids

https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/nat_gateway#attributes-reference

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, will do. Thanks.

description = "The vswitch cidr block"
value = alicloud_vswitch.vswitches.*.cidr_block
output "nat_gateway_snat_table_ids" {
description = "The SNAT table of the NAT Gateway"
Copy link
Contributor

Choose a reason for hiding this comment

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

One nat gateway only has one snat table. Please usenat_gateway_snat_table_idinstead.

Copy link
Author

Choose a reason for hiding this comment

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

I think it should be corrected also in the attributes of the resource because it returns snat_table_ids

https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/nat_gateway#attributes-reference

outputs.tf Outdated Show resolved Hide resolved
output "this_vpc_id" {
description = "The VPC id"
value = local.this_vpc_id
output "vpc_cidr_block" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please improve the outputs and set a prefix this_ for them.

description = "List of vswitch tags."
value = alicloud_vswitch.vswitches.*.tags
output "nat_gateway_dnat_table_ids" {
description = "The DNAT table of the NAT Gateway"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, will do. Thanks.

output "this_vpc_id" {
description = "The VPC id"
value = local.this_vpc_id
output "vpc_cidr_block" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think "The VPC id created by the Terraform module." is ok. But, I think there is no need to keep both. Other modules' outputs also need to be improved. The module https://github.com/terraform-alicloud-modules/terraform-alicloud-kubernetes/blob/master/outputs.tf has not improved yet. But most modules have had this prefix for each output.

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.

4 participants