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

New Resource/Data Source: azurerm_nat_gateway and azurerm_subnet_nat_gateway_association #4449

Merged
merged 24 commits into from
Dec 5, 2019

Conversation

ArcturusZhang
Copy link
Contributor

Added new resource and data source of nat-gateway.

@ArcturusZhang ArcturusZhang changed the title New Resource/Data Source: azurerm_nat_gateway and expose in azurerm_subnet New Resource/Data Source: azurerm_nat_gateway and azurerm_subnet_nat_gateway_association Oct 1, 2019
@ArcturusZhang ArcturusZhang force-pushed the nat-gateway branch 3 times, most recently from c1a79fd to 0e30cb4 Compare October 15, 2019 03:28
@WodansSon WodansSon added this to the v1.37.0 milestone Oct 16, 2019
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@ArcturusZhang , Thanks for the PR and it's looking really good. I left some comments asking a few questions and requesting a few, mostly minor, changes. Thanks for the PR again, this is great! 🐯

azurerm/data_source_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/data_source_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/internal/services/network/client.go Outdated Show resolved Hide resolved
azurerm/internal/services/network/client.go Show resolved Hide resolved
azurerm/internal/services/network/client.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway_test.go Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@ArcturusZhang thanks for the updates, looking really good! Very close, left a few more comments, mostly around documentation. 🚀

Comment on lines 103 to 120
func validateNameForNatGateway(i interface{}, k string) ([]string, []error) {
v, ok := i.(string)
if !ok {
return nil, []error{fmt.Errorf("expected type of %q to be string", k)}
}
// test length
if l := len(v); l < 1 || l > 80 {
return nil, []error{fmt.Errorf("length of field name must be between 1 and 80 characters")}
}
// regex test:
// The name must begin with a letter or number, end with a letter, number or underscore,
// and may contain only letters, numbers, underscores, periods, or hyphens.
regex := regexp.MustCompile(`^[a-zA-Z0-9](([\w-.]*)\w)?$`)
if ok := regex.MatchString(v); !ok {
return nil, []error{fmt.Errorf("the name must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens")}
}
return nil, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I too have implemented this validation function in my GenericRFC3986Compliance PR... While it's fine to put the validation code in the resource itself, I find it a bit nicer to create a validation.go file in the .\services\network directory. That way we keep all the package specific stuff in the same spot in the source tree. I would also pick another var for the length test as l and 1 look almost identical and makes it hard from a code readability point of view, maybe us a t for test instead? Maybe if the PR gets merged we can use the GenericRFC3986Compliance function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could rebase this pr to your branch, and then use the validation function there. Does this make sense?

website/docs/d/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/d/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/d/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
@ArcturusZhang
Copy link
Contributor Author

I made some changes, please have a look again

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks for the revisions @ArcturusZhang,

I've left some comments inline, nothing to major. I would like to see more whitespace and newlines in functions as when there is none it is much harder to read, review, and maintain. Thanks!

azurerm/data_source_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/data_source_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/data_source_nat_gateway.go Show resolved Hide resolved
azurerm/data_source_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/data_source_nat_gateway.go Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved

* `public_ip_prefix_ids` - (Optional) A list of existing `azurerm_public_ip_prefix` resource IDs.

* `resource_guid` - (Optional) The resource GUID property of the Nat Gateway.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add a little more details here what the property does, not just what it is?

Copy link
Contributor Author

@ArcturusZhang ArcturusZhang Oct 23, 2019

Choose a reason for hiding this comment

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

This field is computed, maybe I should remove this from this doc?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you have it as optional/computed?

then it should be moved down to attributes exported

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to Attributes Reference section

website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
@ArcturusZhang
Copy link
Contributor Author

Hi @WodansSon @katbyte I made some changes and left some comments, please have a look again.
And I may need some hint about the comment in data source doc, please see the comments for detail. Thanks!

@tombuildsstuff tombuildsstuff removed this from the v1.37.0 milestone Oct 31, 2019
@katbyte katbyte self-assigned this Oct 31, 2019
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Hi @ArcturusZhang,

Thank you for making those changes. I've re-reviewed and left some more comments inline. I also ran the tests which are failing with:

------- Stdout: -------
=== RUN   TestAccAzureRMNatGateway_basic
=== PAUSE TestAccAzureRMNatGateway_basic
=== CONT  TestAccAzureRMNatGateway_basic

------- Stderr: -------
2019/11/01 00:52:36 [DEBUG] Registering Data Sources for "Compute"..
2019/11/01 00:52:36 [DEBUG] Registering Resources for "Compute"..
panic: interface conversion: interface {} is *schema.Set, not []interface {}

azurerm/data_source_nat_gateway.go Show resolved Hide resolved
azurerm/data_source_nat_gateway.go Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved

* `public_ip_prefix_ids` - (Optional) A list of existing `azurerm_public_ip_prefix` resource IDs.

* `resource_guid` - (Optional) The resource GUID property of the Nat Gateway.
Copy link
Collaborator

Choose a reason for hiding this comment

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

you have it as optional/computed?

then it should be moved down to attributes exported

website/docs/r/nat_gateway.html.markdown Outdated Show resolved Hide resolved
website/docs/d/nat_gateway.html.markdown Show resolved Hide resolved
website/docs/r/nat_gateway.html.markdown Show resolved Hide resolved
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

I have made a few changes to the code, this LGTM now! Thanks! 🚀

@ArcturusZhang
Copy link
Contributor Author

I have made a few changes to the code, this LGTM now! Thanks! 🚀

hooray! thanks!

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @ArcturusZhang & @WodansSon. I've given this one final review and noticed a couple things left. It also appears there are no docs for the association resource?

azurerm/data_source_nat_gateway_test.go Outdated Show resolved Hide resolved
azurerm/data_source_nat_gateway_test.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway.go Outdated Show resolved Hide resolved
azurerm/resource_arm_nat_gateway_test.go Outdated Show resolved Hide resolved

Manages an Azure NAT Gateway instance.

-> **NOTE:** The Azure NAT Gateway service is currently in private preview. Your subscription must be on the NAT Gateway private preview whitelist for this resource to be provisioned correctly. If you attempt to provision this resource and receive an `InvalidResourceType` error that means that your subscription is not part of the NAT Gateway private preview whitelist and you will not be able to use this resource. The NAT Gateway private preview service is currently only available in the `East US 2` and `West Central US` regions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we include warnings about possible breaking changes & a note to contact azure support if a user wants to participate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some more information, please have a look

website/azurerm.erb Show resolved Hide resolved
@katbyte katbyte modified the milestones: v1.39.0, v1.38.0 Dec 4, 2019
@ArcturusZhang
Copy link
Contributor Author

Hi @katbyte I have made some changes, please have a look 🚀

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks for the revisions all, LGTM 👍

@katbyte katbyte merged commit ae2e3f8 into hashicorp:master Dec 5, 2019
katbyte added a commit that referenced this pull request Dec 5, 2019
@ArcturusZhang ArcturusZhang deleted the nat-gateway branch December 5, 2019 08:23
@ghost
Copy link

ghost commented Dec 7, 2019

This has been released in version 1.38.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 1.38.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Jan 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jan 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants