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_extension #26929

Merged
merged 13 commits into from
Oct 29, 2024
Merged

Conversation

teowa
Copy link
Contributor

@teowa teowa commented Aug 5, 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

new resource azurerm_stack_hci_extension
azure doc: https://learn.microsoft.com/en-us/azure-stack/hci/manage/arc-extension-management?tabs=azureportal
rest api: https://github.com/Azure/azure-rest-api-specs/blob/c7b98b36e4023331545051284d8500adf98f02fe/specification/azurestackhci/resource-manager/Microsoft.AzureStackHCI/stable/2024-01-01/extensions.json

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)

Tests depends on Stack HCI Arc Setting resource generated during HCI deployment, the HCI deployment steps is included in PR #25646, my local tests can pass with a existing Arc Setting resource.

ARM_TEST_STACK_HCI_ARC_SETTING_ID='/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/acctest-hci-0804/providers/Microsoft.AzureStackHCI/clusters/hci0804-cl/arcSettings/default' make acctests SERVICE="azurestackhci" TESTARGS="-parallel 5 -run TestAccStackHCIExtension_" 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 TestAccStackHCIExtension_ -timeout 2h -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccStackHCIExtension_basic
=== PAUSE TestAccStackHCIExtension_basic
=== RUN   TestAccStackHCIExtension_complete
=== PAUSE TestAccStackHCIExtension_complete
=== RUN   TestAccStackHCIExtension_update
=== PAUSE TestAccStackHCIExtension_update
=== RUN   TestAccStackHCIExtension_requiresImport
=== PAUSE TestAccStackHCIExtension_requiresImport
=== CONT  TestAccStackHCIExtension_basic
=== CONT  TestAccStackHCIExtension_requiresImport
=== CONT  TestAccStackHCIExtension_update
=== CONT  TestAccStackHCIExtension_complete
--- PASS: TestAccStackHCIExtension_requiresImport (173.50s)
--- PASS: TestAccStackHCIExtension_complete (175.84s)
--- PASS: TestAccStackHCIExtension_basic (176.22s)
--- PASS: TestAccStackHCIExtension_update (400.56s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/azurestackhci 400.578s

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_extension

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 👍

existing, err := client.Get(ctx, *id)
if err != nil {
if response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("%s was not found", id)
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
return fmt.Errorf("%s was not found", id)
return metadata.MarkAsGone(*id)

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

if response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("reading %s: %+v", id, err)
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
return fmt.Errorf("reading %s: %+v", id, err)
return fmt.Errorf("retrieving %s: %+v", *id, err)

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

Copy link
Contributor

Choose a reason for hiding this comment

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

seems not changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for missing this one, updated


model := resp.Model
if model == nil || model.Properties == nil || model.Properties.ExtensionParameters == nil {
return fmt.Errorf("retrieving %s: `model` was nil", id)
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
return fmt.Errorf("retrieving %s: `model` was nil", id)
return fmt.Errorf("retrieving %s: `model` was nil", *id)

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

model.Properties.ExtensionParameters.TypeHandlerVersion = pointer.To(config.TypeHandlerVersion)
}

if err := client.CreateThenPoll(ctx, *id, *model); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

update should use UpdateThenPoll or CreateOrUpdateThenPoll

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

publisher = "Microsoft.EnterpriseCloud.Monitoring"
type = "MicrosoftMonitoringAgent"

protected_settings = <<PROTECTED_SETTINGS
Copy link
Contributor

Choose a reason for hiding this comment

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

basic should not contain optional properties: protected_settings and settings

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


* `type` - (Required) Specifies the type of the extension. For example `CustomScriptExtension` or `AzureMonitorLinuxAgent`. Changing this forces a new resource to be created.

* `auto_upgrade_minor_version_enabled` - (Optional) Indicates whether the extension should use a newer minor version if one is available at deployment time. Once deployed, however, the extension will not upgrade minor versions unless redeployed, even with this property set to true. Possible values are `true` and `false`.
Copy link
Contributor

Choose a reason for hiding this comment

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

what are the differences between auto_upgrade_minor_version_enabled and automatic_upgrade_enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The auto_upgrade_minor_version_enabled is about minor version, and it only works in creation stage. This two properties are available in similar resource like azurerm_virtual_machine_extension

-> **NOTE:** Possible values for `type_handler_version` can be found using the Azure CLI, e.g.:

```shell
az vm extension image list --publisher Microsoft.Azure.Monitor -n AzureMonitorWindowsAgent --location westus -o table
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we provide a link to this Azure CLI instead of directly providing the shell command?

Copy link
Contributor Author

@teowa teowa Aug 7, 2024

Choose a reason for hiding this comment

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

Removed because this cannot be found in doc, and it might be inaccurate.

@teowa
Copy link
Contributor Author

teowa commented Aug 12, 2024

Hi @ms-zhenhua , thanks for reviewing this, please kindly take another look.

ARM_TEST_LOCATION=australiaeast ARM_TEST_STACK_HCI_ARC_SETTING_ID='/subscriptions/XXX/resourceGroups/acctest-hci-0812/providers/Microsoft.AzureStackHCI/clusters/hci0812-cl/arcSettings/default' make acctests SERVICE="azurestackhci" TESTARGS="-parallel 5 -run TestAccStackHCIExtension" 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 TestAccStackHCIExtension -timeout 2h -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccStackHCIExtension_basic
=== PAUSE TestAccStackHCIExtension_basic
=== RUN   TestAccStackHCIExtension_complete
=== PAUSE TestAccStackHCIExtension_complete
=== RUN   TestAccStackHCIExtension_update
=== PAUSE TestAccStackHCIExtension_update
=== RUN   TestAccStackHCIExtension_requiresImport
=== PAUSE TestAccStackHCIExtension_requiresImport
=== CONT  TestAccStackHCIExtension_basic
=== CONT  TestAccStackHCIExtension_update
=== CONT  TestAccStackHCIExtension_requiresImport
=== CONT  TestAccStackHCIExtension_complete
--- PASS: TestAccStackHCIExtension_basic (120.85s)
--- PASS: TestAccStackHCIExtension_requiresImport (196.44s)
--- PASS: TestAccStackHCIExtension_complete (239.01s)
--- PASS: TestAccStackHCIExtension_update (251.42s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/azurestackhci 251.451s

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 ,

Thank you for your updates. LGTM~

@teowa teowa marked this pull request as ready for review August 12, 2024 06:49
@katbyte
Copy link
Collaborator

katbyte commented Oct 22, 2024

@teowa - could we fix up the merge conflicts please?

@teowa teowa requested review from katbyte and a team as code owners October 23, 2024 02:28
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.

LGTM 🌳

@katbyte katbyte merged commit 11945ff into hashicorp:main Oct 29, 2024
33 checks passed
katbyte added a commit that referenced this pull request Oct 29, 2024
@github-actions github-actions bot added this to the v4.8.0 milestone Oct 29, 2024
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.

4 participants