Skip to content

Commit

Permalink
revert changes to other resources
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Dec 30, 2024
1 parent cab84b5 commit 15f5b43
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package azurestackhci
import (
"context"
"fmt"
"log"
"regexp"
"time"

Expand Down Expand Up @@ -194,11 +193,6 @@ func (r StackHCIMarketplaceGalleryImageResource) Create() sdk.ResourceFunc {
return fmt.Errorf("performing create %s: %+v", id, err)
}

// https://github.com/Azure/azure-rest-api-specs/issues/31876
if err := resourceMarketplaceGalleryImageWaitForCreated(ctx, *client, id); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
}

metadata.SetID(id)

return nil
Expand Down Expand Up @@ -336,42 +330,3 @@ func flattenStackHCIMarketplaceGalleryImageIdentifier(input *marketplacegalleryi
},
}
}

func resourceMarketplaceGalleryImageWaitForCreated(ctx context.Context, client marketplacegalleryimages.MarketplaceGalleryImagesClient, id marketplacegalleryimages.MarketplaceGalleryImageId) error {
deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("internal error: context had no deadline")
}

state := &pluginsdk.StateChangeConf{
MinTimeout: 10 * time.Second,
ContinuousTargetOccurence: 3,
Pending: []string{"NotFound"},
Target: []string{"Found"},
Refresh: resourceMarketplaceGalleryImageRefreshFunc(ctx, client, id),
Timeout: time.Until(deadline),
}

if _, err := state.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
}

return nil
}

func resourceMarketplaceGalleryImageRefreshFunc(ctx context.Context, client marketplacegalleryimages.MarketplaceGalleryImagesClient, id marketplacegalleryimages.MarketplaceGalleryImageId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking status for %s ..", id)

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return resp, "NotFound", nil
}

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

return resp, "Found", nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ resource "azurerm_stack_hci_marketplace_gallery_image" "test" {
sku = "2022-datacenter-azure-edition-core"
}
lifecycle {
ignore_changes = [storage_path_id]
}
depends_on = [azurerm_role_assignment.test]
}
`, template, data.RandomString, os.Getenv(customLocationIdEnv), r.imageVersion)
Expand All @@ -193,10 +189,6 @@ resource "azurerm_stack_hci_marketplace_gallery_image" "import" {
offer = azurerm_stack_hci_marketplace_gallery_image.test.identifier.0.offer
sku = azurerm_stack_hci_marketplace_gallery_image.test.identifier.0.sku
}
lifecycle {
ignore_changes = [storage_path_id]
}
}
`, config)
}
Expand Down Expand Up @@ -232,8 +224,6 @@ resource "azurerm_stack_hci_marketplace_gallery_image" "test" {
offer = "WindowsServer"
sku = "2022-datacenter-azure-edition-core"
}
depends_on = [azurerm_role_assignment.test]
}
`, template, data.RandomString, os.Getenv(customLocationIdEnv), r.imageVersion)
}
Expand Down Expand Up @@ -272,8 +262,6 @@ resource "azurerm_stack_hci_marketplace_gallery_image" "test" {
tags = {
foo = "bar"
}
depends_on = [azurerm_role_assignment.test]
}
`, template, data.RandomString, os.Getenv(customLocationIdEnv), r.imageVersion)
}
Expand Down Expand Up @@ -313,8 +301,6 @@ resource "azurerm_stack_hci_marketplace_gallery_image" "test" {
foo = "bar"
env = "test"
}
depends_on = [azurerm_role_assignment.test]
}
`, template, data.RandomString, os.Getenv(customLocationIdEnv), r.imageVersion)
}
Expand All @@ -326,6 +312,8 @@ resource "azurerm_resource_group" "test" {
location = "%s"
}
data "azurerm_client_config" "test" {}
// service principal of 'Microsoft.AzureStackHCI Resource Provider'
data "azuread_service_principal" "hciRp" {
client_id = "1412d89f-b8a8-4111-b4fd-e82905cbd85d"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package azurestackhci
import (
"context"
"fmt"
"log"
"regexp"
"time"

Expand Down Expand Up @@ -182,11 +181,6 @@ func (r StackHCINetworkInterfaceResource) Create() sdk.ResourceFunc {
return fmt.Errorf("performing create %s: %+v", id, err)
}

// https://github.com/Azure/azure-rest-api-specs/issues/31876
if err := resourceNetworkInterfaceWaitForCreated(ctx, *client, id); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
}

metadata.SetID(id)

return nil
Expand Down Expand Up @@ -358,42 +352,3 @@ func flattenStackHCINetworkInterfaceIPConfiguration(input *[]networkinterfaces.I

return results, nil
}

func resourceNetworkInterfaceWaitForCreated(ctx context.Context, client networkinterfaces.NetworkInterfacesClient, id networkinterfaces.NetworkInterfaceId) error {
deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("internal error: context had no deadline")
}

state := &pluginsdk.StateChangeConf{
MinTimeout: 10 * time.Second,
ContinuousTargetOccurence: 4,
Pending: []string{"NotFound"},
Target: []string{"Found"},
Refresh: resourceNetworkInterfaceRefreshFunc(ctx, client, id),
Timeout: time.Until(deadline),
}

if _, err := state.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
}

return nil
}

func resourceNetworkInterfaceRefreshFunc(ctx context.Context, client networkinterfaces.NetworkInterfacesClient, id networkinterfaces.NetworkInterfaceId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking status for %s ..", id)

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return resp, "NotFound", nil
}

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

return resp, "Found", nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ resource "azurerm_stack_hci_network_interface" "test" {
}
lifecycle {
ignore_changes = [mac_address, ip_configuration.0.private_ip_address]
ignore_changes = [mac_address]
}
}
`, template, data.RandomString, os.Getenv(customLocationIdEnv))
Expand All @@ -184,10 +184,6 @@ resource "azurerm_stack_hci_network_interface" "import" {
ip_configuration {
subnet_id = azurerm_stack_hci_network_interface.test.ip_configuration.0.subnet_id
}
lifecycle {
ignore_changes = [mac_address, ip_configuration.0.private_ip_address]
}
}
`, config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package azurestackhci
import (
"context"
"fmt"
"log"
"regexp"
"time"

Expand Down Expand Up @@ -210,11 +209,6 @@ func (r StackHCIVirtualHardDiskResource) Create() sdk.ResourceFunc {
return fmt.Errorf("performing create %s: %+v", id, err)
}

// https://github.com/Azure/azure-rest-api-specs/issues/31876
if err := resourceVirtualHardDiskWaitForCreated(ctx, *client, id); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
}

metadata.SetID(id)

return nil
Expand Down Expand Up @@ -325,42 +319,3 @@ func (r StackHCIVirtualHardDiskResource) Delete() sdk.ResourceFunc {
},
}
}

func resourceVirtualHardDiskWaitForCreated(ctx context.Context, client virtualharddisks.VirtualHardDisksClient, id virtualharddisks.VirtualHardDiskId) error {
deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("internal error: context had no deadline")
}

state := &pluginsdk.StateChangeConf{
MinTimeout: 10 * time.Second,
ContinuousTargetOccurence: 4,
Pending: []string{"NotFound"},
Target: []string{"Found"},
Refresh: resourceVirtualHardDiskRefreshFunc(ctx, client, id),
Timeout: time.Until(deadline),
}

if _, err := state.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
}

return nil
}

func resourceVirtualHardDiskRefreshFunc(ctx context.Context, client virtualharddisks.VirtualHardDisksClient, id virtualharddisks.VirtualHardDiskId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking status for %s ..", id)

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return resp, "NotFound", nil
}

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

return resp, "Found", nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ resource "azurerm_stack_hci_marketplace_gallery_image" "example" {
foo = "bar"
env = "example"
}
depends_on = [azurerm_role_assignment.example]
}
```

Expand Down Expand Up @@ -76,8 +75,6 @@ The following arguments are supported:

* `storage_path_id` - (Optional) The ID of the Azure Stack HCI Storage Path used for this Marketplace Gallery Image. Changing this forces a new Azure Stack HCI Virtual Hard Disk to be created.

-> **Note:** If `storage_path_id` is not specified, it will be assigned by the server. If you experience a diff you may need to add this to `ignore_changes`.

* `tags` - (Optional) A mapping of tags which should be assigned to the Azure Stack HCI Marketplace Gallery Image.

---
Expand All @@ -92,7 +89,7 @@ An `identifier` block supports the following:

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Azure Stack HCI Marketplace Gallery Image.

Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/stack_hci_network_interface.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ An `ip_configuration` block supports the following:

* `private_ip_address` - (Optional) The IPv4 address of the IP configuration. Changing this forces a new resource to be created.

-> **Note:** If `private_ip_address` is not specified, it will be assigned by the server. If you experience a diff you may need to add this to `ignore_changes`.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/stack_hci_virtual_hard_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ The following arguments are supported:

* `storage_path_id` - (Optional) The ID of the Azure Stack HCI Storage Path used for this Virtual Hard Disk. Changing this forces a new Azure Stack HCI Virtual Hard Disk to be created.

-> **Note:** If `storage_path_id` is not specified, it will be assigned by the server. If you experience a diff you may need to add this to `ignore_changes`.
-> **Note:** If `storage_path_id` is not specified, the Virtual Hard Disk will be placed in a high availability Storage Path. If you experience a diff you may need to add this to `ignore_changes`.

* `tags` - (Optional) A mapping of tags which should be assigned to the Azure Stack HCI Virtual Hard Disk.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Azure Stack HCI Virtual Hard Disk.

Expand Down

0 comments on commit 15f5b43

Please sign in to comment.