provider/azurerm: Load Balancer resources#9199
Conversation
966b7b3 to
25d9730
Compare
e29038d to
dff6941
Compare
| return fmt.Errorf("Bad: Get on loadBalancerClient: %s", err) | ||
| } | ||
|
|
||
| if resp.StatusCode == http.StatusNotFound { |
There was a problem hiding this comment.
In my experience the ArmClients raise an err for 404 responses while also filling the resp object.
A 404 response will actually trigger at line 117 and these lines will never be executed. It's a common error I've seen in other AzureRM acceptance tests.
There was a problem hiding this comment.
We are in noway near ready to start reviewing this - give us another day yet :) I definitely take your point! I Just found the same issue elsewhere haha
P.
There was a problem hiding this comment.
Looks like these have been addressed now. Thanks @carinadigital!
| if err != nil { | ||
| return nil, false, fmt.Errorf("Error making Read request on Azure Loadbalancer %s: %s", name, err) | ||
| } | ||
| if resp.StatusCode == http.StatusNotFound { |
There was a problem hiding this comment.
See my previous comment about ArmClients and 404 responses raising errors. I suspect this will fail a _disappears() acceptance test if there was one present.
Moving the conditional inside the if err != nil check should work as intended.
There was a problem hiding this comment.
Looks like these have been addressed now. Thanks @carinadigital!
25cc001 to
f7c8bd0
Compare
| package azurerm | ||
|
|
||
| import ( | ||
| "fmt" |
There was a problem hiding this comment.
This needs goimports running on it.
|
|
||
| resGroup, name, err := resourceGroupAndLBNameFromId(loadBalancerId) | ||
| if err != nil { | ||
| return nil, false, errwrap.Wrapf("TODO: error message {{err}}", err) |
There was a problem hiding this comment.
This needs it's error message finishing :-)
| } | ||
|
|
||
| func validateLoadbalancerPrivateIpAddressAllocation(v interface{}, k string) (ws []string, errors []error) { | ||
| value := strings.ToLower(v.(string)) |
There was a problem hiding this comment.
This seems unnecessary complex for something that could be:
value := strings.ToLower(v.(string))
if value == "static" || value == "dynamic" {
// ok
} else {
// not ok
}
Even if we keep the map lookup pattern, it should be map[string]struct{} rather than map[string]bool.
There was a problem hiding this comment.
Looks like #8103 has been merged, we'll merge this as is (pending review) and then go back and fix it up to use the new bits.
| }, | ||
|
|
||
| "frontend_ip_configuration": { | ||
| Type: schema.TypeSet, |
There was a problem hiding this comment.
Do we strictly need this to be a Set? Is there any reason not to have it as a list?
| resGroup := id.ResourceGroup | ||
| name := id.Path["loadBalancers"] | ||
|
|
||
| _, err = loadBalancerClient.Delete(resGroup, name, make(chan struct{})) |
There was a problem hiding this comment.
Should we check for a 404 here and remove from state if so?
| } | ||
| if !exists { | ||
| d.SetId("") | ||
| log.Printf("[INFO] Loadbalancer %q not found. Refreshing from state", d.Get("name").(string)) |
|
|
||
| resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string)) | ||
| if err != nil { | ||
| return errwrap.Wrapf("TODO: {{err}}", err) |
| loadBalancer.Properties.InboundNatPools = &natPools | ||
| resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string)) | ||
| if err != nil { | ||
| return errwrap.Wrapf("TODO: {{err}}", err) |
|
|
||
| resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string)) | ||
| if err != nil { | ||
| return errwrap.Wrapf("TODO: {{err}}", err) |
|
|
||
| resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string)) | ||
| if err != nil { | ||
| return errwrap.Wrapf("TODO: {{err}}", err) |
|
@jen20 all changes made as requested. Also made the use of NAT and LoadBalancer consistent as well as wrapping errors from the API |
eacaeba to
463bd66
Compare
|
New test run post code review changes: |
aab5a95 to
2647571
Compare
| if resp.StatusCode == http.StatusNotFound { | ||
| return nil, false, nil | ||
| } | ||
| return nil, false, fmt.Errorf("Error making Read request on Azure Loadbalancer %s: %s", name, err) |
There was a problem hiding this comment.
Error string capitalisation inconsistent. Loadbalancer->LoadBalancer
| if err != nil { | ||
| return errwrap.Wrapf("Error Getting LoadBalancer {{err}}", err) | ||
| } | ||
| if read.ID == nil { |
There was a problem hiding this comment.
If the lbClient.Get() was successful, can read.ID ever be empty?
There was a problem hiding this comment.
Yes, a successful api call can still potentially return an empty result. This is a guard against a panic when dereferencing
2647571 to
79d6cc8
Compare
| func testAccAzureRMLoadbalancerBackEndAddressPool_basic(rInt int, addressPoolName string) string { | ||
| return fmt.Sprintf(` | ||
| resource "azurerm_resource_group" "test" { | ||
| name = "acctestrg-%d" |
There was a problem hiding this comment.
For some resources and regions, resource_group_name is returned from the API in mixed capitalisation. Adding capitalisation to name would extend the test to catch this error.
e.g. "acctestrg-%d" -> "acctestRG-%d"
This might be better fixed in a different PR, but I thought it's worth mentioning.
"West US" loadbalancer API does pass the capitalisation test.
There was a problem hiding this comment.
Hi @carinadigital yeah this is outside of the scope of this PR - there is another issue for this AFAICR
| location = "West US" | ||
| resource_group_name = "${azurerm_resource_group.test.name}" | ||
| loadbalancer_id = "${azurerm_lb.test.id}" | ||
| name = "LB Rule" |
There was a problem hiding this comment.
The example name for azurerm_lb_rule given here is invalid (whitespace is an invalid character).
Consider a validate function for azurerm_lb_rule.name in the schema. The validation rules are in the error output below.
It would also be nice if name was the first attribute listed of the resource, rather than in the middle.
* azurerm_lb_rule.hmrc: Error Creating/Updating LoadBalancer network.LoadBalancersClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidResourceName" Message="Resource name LB Rule is invalid. The name can be up to 80 characters long. It must begin with a word character, and it must end with a word character or with '_'. The name may contain word characters or '.', '-', '_'." Details=[]
There was a problem hiding this comment.
Looks like this one is resolved with a validation function.
Adds support for the elusive Azure LoadBalancer * [x] `azurerm_lb` * [x] `azurerm_lb_backend_address_pool` * [x] `azurerm_lb_rule` * [x] `azurerm_lb_nat_rule` * [x] `azurerm_lb_probe` * [x] `azurerm_lb_nat_pool` Test Results: ``` make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMLoadbalancer' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMLoadbalancer -timeout 120m === RUN TestAccAzureRMLoadbalancerBackEndAddressPool_basic --- PASS: TestAccAzureRMLoadbalancerBackEndAddressPool_basic (207.26s) === RUN TestAccAzureRMLoadbalancerBackEndAddressPool_removal --- PASS: TestAccAzureRMLoadbalancerBackEndAddressPool_removal (165.89s) === RUN TestAccAzureRMLoadbalancerNatRule_basic --- PASS: TestAccAzureRMLoadbalancerNatRule_basic (179.30s) === RUN TestAccAzureRMLoadbalancerNatRule_removal --- PASS: TestAccAzureRMLoadbalancerNatRule_removal (180.73s) === RUN TestAccAzureRMLoadbalancerRule_basic --- PASS: TestAccAzureRMLoadbalancerRule_basic (170.40s) === RUN TestAccAzureRMLoadbalancerRule_removal --- PASS: TestAccAzureRMLoadbalancerRule_removal (204.23s) === RUN TestAccAzureRMLoadbalancer_basic --- PASS: TestAccAzureRMLoadbalancer_basic (136.03s) === RUN TestAccAzureRMLoadbalancer_frontEndConfig --- PASS: TestAccAzureRMLoadbalancer_frontEndConfig (214.47s) === RUN TestAccAzureRMLoadbalancer_tags --- PASS: TestAccAzureRMLoadbalancer_tags (215.52s) === RUN TestAccAzureRMLoadbalancerProbe_basic --- PASS: TestAccAzureRMLoadbalancerProbe_basic (183.36s) === RUN TestAccAzureRMLoadbalancerProbe_removal --- PASS: TestAccAzureRMLoadbalancerProbe_removal (185.86s) === RUN TestAccAzureRMLoadbalancerNatPool_basic --- PASS: TestAccAzureRMLoadbalancerNatPool_basic (161.47s) === RUN TestAccAzureRMLoadbalancerNatPool_removal --- PASS: TestAccAzureRMLoadbalancerNatPool_removal (167.38s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 1673.852s ```
ef82f62 to
5444c27
Compare
|
Great work on this 👍
Maybe a TestAccAzureRMLoadbalancerRule_update() test. |
|
Thanks @carinadigital Good point about the update now - i can't see anything in the docs that says it can't be updated. So I think adding the update test will be a good addition! Adding this now P. |
| return errwrap.Wrapf("Error Getting LoadBalancer By ID {{err}}", err) | ||
| } | ||
| if !exists { | ||
| d.SetId("") |
There was a problem hiding this comment.
Is there another case where the LoadBalancer exists, but the LoadBalancer_rule does not?
I can't see another d.SetId("") in the resourceArmLoadbalancerRuleRead().
|
Apologies if I'm reviewing something before it's finished.
Looking up the probe object in the azure cli suggest this: |
|
I think I confirmed this is the problem by suffixing the string "/probes/jump-probe" and seeing it work correctly. |
45e0f62 to
7d3d707
Compare
jen20
left a comment
There was a problem hiding this comment.
Looks like this is good to merge. We should probably rebase it to squash the commits first though.
| package azurerm | ||
|
|
||
| import ( | ||
| "fmt" |
| } | ||
|
|
||
| func validateLoadbalancerPrivateIpAddressAllocation(v interface{}, k string) (ws []string, errors []error) { | ||
| value := strings.ToLower(v.(string)) |
There was a problem hiding this comment.
Looks like #8103 has been merged, we'll merge this as is (pending review) and then go back and fix it up to use the new bits.
|
Fantastic work on this! This is so appreciated. |
|
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. |
azurerm_lbazurerm_lb_backend_address_poolazurerm_lb_ruleazurerm_lb_nat_ruleazurerm_lb_probeazurerm_lb_nat_poolCurrent test status: