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

[MS] provider/azurerm: fixes for bug #8227 and bug #11226 #13877

Merged
merged 6 commits into from
Jun 1, 2017

Conversation

echuvyrov
Copy link
Contributor

This PR should partially fix #8227 and #11226 which I believe is a duplicate of #8227. The fix should preserve all of the subnet properties, including routeTable association, on vNet update.

@echuvyrov echuvyrov changed the title Fixes for bug #8227 and bug #11226 provider/azurerm fixes for bug #8227 and bug #11226 Apr 23, 2017
@echuvyrov echuvyrov changed the title provider/azurerm fixes for bug #8227 and bug #11226 provider/azurerm: fixes for bug #8227 and bug #11226 Apr 23, 2017
@tombuildsstuff tombuildsstuff self-assigned this Apr 24, 2017
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

Hi @echuvyrov

Thanks for this PR - apologies for the delay in reviewing this. I've reviewed and left some comments in-line :)

There's also a few remaining tasks which I couldn't find a place for in-line:

  • Add some extra tests:
    • An Import Test covering a Subnet with a Route Table
    • An Import Test covering a Virtual Network with a Route Table
    • An Acceptance Test covering updating a Virtual Network
    • An Acceptance Test covering adding/removing a Route Table from a Virtual network
  • Update the Documentation to reflect the new field on Virtual Network

However it otherwise looks good - I've run the acceptance tests and they pass:

$ envchain azurerm make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMSubnet'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/05/02 09:32:54 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMSubnet -timeout 120m
=== RUN   TestAccAzureRMSubnet_importBasic
--- PASS: TestAccAzureRMSubnet_importBasic (132.34s)
=== RUN   TestAccAzureRMSubnet_basic
--- PASS: TestAccAzureRMSubnet_basic (135.57s)
=== RUN   TestAccAzureRMSubnet_routeTable
--- PASS: TestAccAzureRMSubnet_routeTable (176.13s)
=== RUN   TestAccAzureRMSubnet_routeTable_subnetInline
--- PASS: TestAccAzureRMSubnet_routeTable_subnetInline (124.82s)
=== RUN   TestAccAzureRMSubnet_disappears
--- PASS: TestAccAzureRMSubnet_disappears (135.10s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	703.985s
$ envchain azurerm make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMVirtualNetwork'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/05/02 10:05:39 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMVirtualNetwork -timeout 120m
=== RUN   TestAccAzureRMVirtualNetworkPeering_importBasic
--- PASS: TestAccAzureRMVirtualNetworkPeering_importBasic (135.31s)
=== RUN   TestAccAzureRMVirtualNetwork_importBasic
--- PASS: TestAccAzureRMVirtualNetwork_importBasic (93.71s)
=== RUN   TestAccAzureRMVirtualNetworkPeering_basic
--- PASS: TestAccAzureRMVirtualNetworkPeering_basic (158.53s)
=== RUN   TestAccAzureRMVirtualNetworkPeering_disappears
--- PASS: TestAccAzureRMVirtualNetworkPeering_disappears (119.50s)
=== RUN   TestAccAzureRMVirtualNetworkPeering_update
--- PASS: TestAccAzureRMVirtualNetworkPeering_update (163.05s)
=== RUN   TestAccAzureRMVirtualNetwork_basic
--- PASS: TestAccAzureRMVirtualNetwork_basic (76.80s)
=== RUN   TestAccAzureRMVirtualNetwork_disappears
--- PASS: TestAccAzureRMVirtualNetwork_disappears (104.64s)
=== RUN   TestAccAzureRMVirtualNetwork_withTags
--- PASS: TestAccAzureRMVirtualNetwork_withTags (116.81s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	968.374s

Thanks! :)


ri := acctest.RandInt()
//initConfig := fmt.Sprintf(testAccAzureRMSubnet_routeTable_subnetInline, ri, ri, ri)
updatedConfig := fmt.Sprintf(testAccAzureRMSubnet_updatedRouteTable, ri, ri, ri)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be using the testAccAzureRMSubnet_routeTable_subnetInline config?

if resp.StatusCode == http.StatusNotFound {
return existingSubnet
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we raise this error if it's not a 404? (That way we should be able to return nil for the existingSubnet, and populate the SubnetPropertiesFormat/AddressPrefix below in the same call)

@@ -30,6 +32,55 @@ func TestAccAzureRMSubnet_basic(t *testing.T) {
})
}

func TestAccAzureRMSubnet_routeTable(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this is updating, can we rename this TestAccAzureRMSubnet_routeTableUpdate?

@@ -171,3 +278,145 @@ resource "azurerm_route" "test" {
next_hop_in_ip_address = "10.10.1.1"
}
`

var testAccAzureRMSubnet_routeTable = `
resource "azurerm_resource_group" "rtTable2" {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: we tend to use test as the resource name within tests, unless there's multiple of the resource (e.g. when testing the creation of 3 subnets) - could we update these to match?

}`

var testAccAzureRMSubnet_routeTable_subnetInline = `
resource "azurerm_resource_group" "rtTable2" {
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

}`

var testAccAzureRMSubnet_updatedRouteTable = `
resource "azurerm_resource_group" "rtTable2" {
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

@@ -268,6 +293,40 @@ func resourceAzureSubnetHash(v interface{}) int {
}
return hashcode.String(subnet)
}
func getExistingSubnet(resGroup string, vnetName string, subnetName string, meta interface{}) network.Subnet {
Copy link
Contributor

Choose a reason for hiding this comment

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

In order to raise an error, can we update this to return a (*network.Subnet, error)?

@tombuildsstuff tombuildsstuff added the waiting-response An issue/pull request is waiting for a response from the community label May 2, 2017
@echuvyrov
Copy link
Contributor Author

echuvyrov commented May 10, 2017

@tombuildsstuff I made the changes requested and removed the route_table definition from the vNet - additional tests revealed that there was a collision between this way of adding a route table to subnet and the other, more preferred way as a root-level resource. Please review and let me know if the changes address all the comments you've raised.

@tombuildsstuff tombuildsstuff removed the waiting-response An issue/pull request is waiting for a response from the community label May 16, 2017
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

Hi @echuvyrov

Thanks for pushing those updates - I've taken another look and left some comments in-line, but this otherwise looks good :)

Thanks!

}

resource "azurerm_route_table" "test" {
name = "test-RT"
Copy link
Contributor

Choose a reason for hiding this comment

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

can we rename this acctest-%d, to ensure it's unique across test runs?

}

resource "azurerm_route" "route_a" {
name = "TestRouteA"
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

}

resource "azurerm_network_security_group" "test_secgroup" {
name = "acceptanceTestSecurityGroup1"
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

}

resource "azurerm_route" "route_a" {
name = "TestRouteA"
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

}

resource "azurerm_route_table" "test" {
name = "test-RT"
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

@@ -257,16 +278,55 @@ func getVirtualNetworkProperties(d *schema.ResourceData) *network.VirtualNetwork
DNSServers: &dnses,
},
Subnets: &subnets,
}
}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

given we're returning two objects here, IMO this would read cleaner if we assigned this to a variable and then returned those, e.g.:

properties := &network....
return properties, nil

if m["security_group"] != nil {
buf.WriteString(fmt.Sprintf("%s-", m["security_group"].(string)))
}
return hashcode.String(buf.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

given a - has been added at the end of each value this hash code is going to be different, and thus a change will show up as required on the plan. To avoid this, we can either increment the Schema Version and write a State Migration - or just remove the - from these strings (which I would suggest here :))

subnet = subnet + securityGroup.(string)
buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["address_prefix"].(string)))
if m["security_group"] != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we can make this cleaner by using:

if v, ok := m["security_group"]; ok {
 buf.WriteString(v.(string))
}

@@ -171,3 +257,108 @@ resource "azurerm_route" "test" {
next_hop_in_ip_address = "10.10.1.1"
}
`

var testAccAzureRMSubnet_routeTable = `
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI for newer test config's we're tending to make these functions which take an Int and handle formatting the string, rather than spreading the string format throughout the test functions (given we're now using them in multiple places), i.e.

func testAccAzureRMSubnet_routeTable(rInt int) string {
 return fmt.Sprintf(....., rInt,rInt)
}

@tombuildsstuff tombuildsstuff added the waiting-response An issue/pull request is waiting for a response from the community label May 17, 2017
@echuvyrov
Copy link
Contributor Author

@tombuildsstuff I made the changes requested, I think those will definitely improve code - thanks so much!

@echuvyrov echuvyrov changed the title provider/azurerm: fixes for bug #8227 and bug #11226 [MS] provider/azurerm: fixes for bug #8227 and bug #11226 May 19, 2017
@tombuildsstuff tombuildsstuff removed the waiting-response An issue/pull request is waiting for a response from the community label Jun 1, 2017
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

Hi @echuvyrov

Thanks for pushing the latest changes - I've taken another look and this LGTM :)

The tests pass:

$ envchain azurerm make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMVirtualNetwork'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/06/01 16:19:48 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMVirtualNetwork -timeout 120m
=== RUN   TestAccAzureRMVirtualNetworkPeering_importBasic
--- PASS: TestAccAzureRMVirtualNetworkPeering_importBasic (141.83s)
=== RUN   TestAccAzureRMVirtualNetwork_importBasic
--- PASS: TestAccAzureRMVirtualNetwork_importBasic (85.22s)
=== RUN   TestAccAzureRMVirtualNetworkPeering_basic
--- PASS: TestAccAzureRMVirtualNetworkPeering_basic (142.01s)
=== RUN   TestAccAzureRMVirtualNetworkPeering_disappears
--- PASS: TestAccAzureRMVirtualNetworkPeering_disappears (130.45s)
=== RUN   TestAccAzureRMVirtualNetworkPeering_update
--- PASS: TestAccAzureRMVirtualNetworkPeering_update (194.56s)
=== RUN   TestAccAzureRMVirtualNetwork_basic
--- PASS: TestAccAzureRMVirtualNetwork_basic (66.86s)
=== RUN   TestAccAzureRMVirtualNetwork_disappears
--- PASS: TestAccAzureRMVirtualNetwork_disappears (82.76s)
=== RUN   TestAccAzureRMVirtualNetwork_withTags
--- PASS: TestAccAzureRMVirtualNetwork_withTags (92.87s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	936.588s
$ envchain azurerm make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMSubnet'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/06/01 16:23:03 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMSubnet -timeout 120m
=== RUN   TestAccAzureRMSubnet_importBasic
--- PASS: TestAccAzureRMSubnet_importBasic (142.12s)
=== RUN   TestAccAzureRMSubnet_importWithRouteTable
--- PASS: TestAccAzureRMSubnet_importWithRouteTable (131.49s)
=== RUN   TestAccAzureRMSubnet_basic
--- PASS: TestAccAzureRMSubnet_basic (144.82s)
=== RUN   TestAccAzureRMSubnet_routeTableUpdate
--- PASS: TestAccAzureRMSubnet_routeTableUpdate (159.74s)
=== RUN   TestAccAzureRMSubnet_disappears
--- PASS: TestAccAzureRMSubnet_disappears (176.57s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/azurerm	754.753s

Thanks!

@tombuildsstuff tombuildsstuff merged commit acd586a into hashicorp:master Jun 1, 2017
tombuildsstuff added a commit that referenced this pull request Jun 1, 2017
@ghost
Copy link

ghost commented Apr 11, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 11, 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.

azurerm_subnet does not track route_table_id association.
2 participants