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 azurerm_stack_hci_logical_network #26473

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

teowa
Copy link
Contributor

@teowa teowa commented Jun 26, 2024

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

swagger: https://github.com/Azure/azure-rest-api-specs/blob/1c63635d66ae38cff18045ab416a6572d3e15f6e/specification/azurestackhci/resource-manager/Microsoft.AzureStackHCI/stable/2024-01-01/logicalNetworks.json

Azure doc: https://learn.microsoft.com/en-us/azure-stack/hci/manage/create-logical-networks?tabs=azurecli#prerequisites

The acctest is based on existing custom location, the custom location is generated during HCI deployment which can take more than 3 hours. How to test HCI deployment from scratch is included in PR #25646

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)
ARM_TEST_STACK_HCI_CUSTOM_LOCATION_ID=/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/acctest-hci-0626/providers/Microsoft.ExtendedLocation/customLocations/customlocation0626 make acctests SERVICE="azurestackhci" TESTARGS="-parallel 5 -run TestAccStackHCILogicalNetwork_" TESTTIMEOUT=2h
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/azurestackhci -parallel 5 -run TestAccStackHCILogicalNetwork_ -timeout 2h -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccStackHCILogicalNetwork_basic
=== PAUSE TestAccStackHCILogicalNetwork_basic
=== RUN   TestAccStackHCILogicalNetwork_update
=== PAUSE TestAccStackHCILogicalNetwork_update
=== RUN   TestAccStackHCILogicalNetwork_requiresImport
=== PAUSE TestAccStackHCILogicalNetwork_requiresImport
=== RUN   TestAccStackHCILogicalNetwork_complete
=== PAUSE TestAccStackHCILogicalNetwork_complete
=== CONT  TestAccStackHCILogicalNetwork_basic
=== CONT  TestAccStackHCILogicalNetwork_complete
=== CONT  TestAccStackHCILogicalNetwork_update
=== CONT  TestAccStackHCILogicalNetwork_requiresImport
--- PASS: TestAccStackHCILogicalNetwork_complete (291.39s)
--- PASS: TestAccStackHCILogicalNetwork_requiresImport (297.44s)
--- PASS: TestAccStackHCILogicalNetwork_basic (297.79s)
--- PASS: TestAccStackHCILogicalNetwork_update (355.81s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/azurestackhci 355.868s

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • new resource azurerm_stack_hci_logical_network [GH-00000]

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #0000

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

Copy link
Contributor

@ms-zhenhua ms-zhenhua left a comment

Choose a reason for hiding this comment

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

Hi @teowa, Thanks for this PR - I've taken a look through and left some comments inline. If we can fix those up, this should be good to go 👍

Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
Copy link
Contributor

Choose a reason for hiding this comment

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

does name have max length and special characters limitation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

validation added.

ForceNew: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"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 name is not required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to requred

t.Skipf("skip the test as one or more of below environment variables are not specified: %q", customLocationIdEnv)
}

data.ResourceTest(t, r, []acceptance.TestStep{
Copy link
Contributor

Choose a reason for hiding this comment

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

please use basic -> complete -> update -> basic to also test add/remove tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test updated


* `custom_location_id` - (Required) The ID of Custom Location where the Azure Stack HCI Logical Network should exist. Changing this forces a new resource to be created.

* `vm_switch_name` - (Required) The name of the network switch used to associate with the Azure Stack HCI Logical Network. Possible switch name can be retrieved following the [Azure documents](https://learn.microsoft.com/azure-stack/hci/manage/create-logical-networks?tabs=azurecli#prerequisites). Changing this forces a new resource to be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

from the description, it seems should be named as network_switch_name ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to virtual_switch_name and the description to Name of the external virtual switch


A `subnet` block supports the following:

* `ip_allocation_method` - (Required) IP address allocation method for the subnet. Possible value is `Dynamic` or `Static`. Changing this forces a new resource to be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `ip_allocation_method` - (Required) IP address allocation method for the subnet. Possible value is `Dynamic` or `Static`. Changing this forces a new resource to be created.
* `ip_allocation_method` - (Required) IP address allocation method for the subnet. Possible values are `Dynamic` and `Static`. Changing this forces a new resource to be created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


* `address_prefix` - (Optional) The address prefix in CIDR notation. Changing this forces a new resource to be created.

* `ip_pool` - (Optional) One or more `ip_pool` block as defined above. Changing this forces a new resource to be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

why not define the description of ip_pool and route after subnet ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all the blocks are ranked in alphabetical order

…hange vm_switch_name to virtual_switch_name; update doc
@teowa
Copy link
Contributor Author

teowa commented Jul 3, 2024

Hi @ms-zhenhua , thanks for reviewing this, I have changed the code, please kindly take another look.

--- PASS: TestAccStackHCILogicalNetwork_complete (229.63s)
--- PASS: TestAccStackHCILogicalNetwork_dynamic (294.78s)
--- PASS: TestAccStackHCILogicalNetwork_requiresImport (439.81s)
--- PASS: TestAccStackHCILogicalNetwork_update (504.71s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/azurestackhci 504.757s

@ms-zhenhua
Copy link
Contributor

Hi @teowa, thank you for your updates. LGTM~

@teowa
Copy link
Contributor Author

teowa commented Jul 3, 2024

--- PASS: TestAccStackHCILogicalNetwork_dynamic (238.51s)
--- PASS: TestAccStackHCILogicalNetwork_complete (295.82s)
--- PASS: TestAccStackHCILogicalNetwork_requiresImport (443.56s)
--- PASS: TestAccStackHCILogicalNetwork_update (647.05s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/azurestackhci 647.094s

@teowa teowa marked this pull request as ready for review July 3, 2024 08:28
Comment on lines +243 to +252
future, err := client.CreateOrUpdate(ctx, id, payload)
if err != nil {
return fmt.Errorf("performing create %s: %+v", id, err)
}

metadata.SetID(id)

if err := future.Poller.PollUntilDone(ctx); err != nil {
return fmt.Errorf("polling after create %s: %+v", id, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Why aren't we using the combined CreateOrUpdateThenPoll here?


parameters := resp.Model
if parameters == nil {
return fmt.Errorf("retrieving %s: model was nil", *id)
Copy link
Member

Choose a reason for hiding this comment

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

We put the object or property name between back ticks in the error message

Suggested change
return fmt.Errorf("retrieving %s: model was nil", *id)
return fmt.Errorf("retrieving %s: `model` was nil", *id)

r := StackHCILogicalNetworkResource{}

if os.Getenv(customLocationIdEnv) == "" {
t.Skipf("skip the test as one or more of below environment variables are not specified: %q", customLocationIdEnv)
Copy link
Member

Choose a reason for hiding this comment

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

I only see one required environment variable for the test:

Suggested change
t.Skipf("skip the test as one or more of below environment variables are not specified: %q", customLocationIdEnv)
t.Skipf("skipping since %q has not been specified", customLocationIdEnv)

r := StackHCILogicalNetworkResource{}

if os.Getenv(customLocationIdEnv) == "" {
t.Skipf("skip the test as one or more of below environment variables are not specified: %q", customLocationIdEnv)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Skipf("skip the test as one or more of below environment variables are not specified: %q", customLocationIdEnv)
t.Skipf("skipping since %q has not been specified", customLocationIdEnv)

return nil, fmt.Errorf("retrieving %s: %+v", *id, err)
}

return utils.Bool(resp.Model != nil), nil
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return utils.Bool(resp.Model != nil), nil
return pointer.To(resp.Model != nil), nil

Comment on lines +124 to +126
if response.WasNotFound(resp.HttpResponse) {
return utils.Bool(false), nil
}
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a typical pattern in the Exists check for tests? If we get any error kind of error from getting the resource here we should just return it

Suggested change
if response.WasNotFound(resp.HttpResponse) {
return utils.Bool(false), nil
}


* `custom_location_id` - (Required) The ID of Custom Location where the Azure Stack HCI Logical Network should exist. Changing this forces a new resource to be created.

* `virtual_switch_name` - (Required) The name of the virtual switch on the cluster used to associate with the Azure Stack HCI Logical Network. Possible switch name can be retrieved following the [Azure documents](https://learn.microsoft.com/azure-stack/hci/manage/create-logical-networks?tabs=azurecli#prerequisites). Changing this forces a new resource to be created.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `virtual_switch_name` - (Required) The name of the virtual switch on the cluster used to associate with the Azure Stack HCI Logical Network. Possible switch name can be retrieved following the [Azure documents](https://learn.microsoft.com/azure-stack/hci/manage/create-logical-networks?tabs=azurecli#prerequisites). Changing this forces a new resource to be created.
* `virtual_switch_name` - (Required) The name of the virtual switch on the cluster used to associate with the Azure Stack HCI Logical Network. Possible switch names can be retrieved by following this [Azure guide](https://learn.microsoft.com/azure-stack/hci/manage/create-logical-networks?tabs=azurecli#prerequisites). Changing this forces a new resource to be created.


* `route` - (Optional) One or more `route` block as defined above. Changing this forces a new resource to be created.

* `vlan_id` - (Optional) VLAN ID for the Logical Network. Changing this forces a new resource to be created.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `vlan_id` - (Optional) VLAN ID for the Logical Network. Changing this forces a new resource to be created.
* `vlan_id` - (Optional) The VLAN ID for the Logical Network. Changing this forces a new resource to be created.

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

Successfully merging this pull request may close these issues.

None yet

3 participants