Skip to content

Commit

Permalink
Merge pull request #24691 from ziyeqf/tengzh/vmware_fix_ci
Browse files Browse the repository at this point in the history
`azurerm_site_recovery_vmware_replicated_vm`: fix CI failure
  • Loading branch information
tombuildsstuff authored Jan 30, 2024
2 parents a0b10c3 + 44e2edb commit 5a7db34
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func resourceRecoveryServicesVaultCreate(d *pluginsdk.ResourceData, meta interfa
vault.Sku.Tier = utils.String("Standard")
}

requireAddtionalUpdate := false
requireAdditionalUpdate := false
updatePatch := vaults.PatchVault{
Properties: &vaults.VaultProperties{},
}
Expand All @@ -263,7 +263,7 @@ func resourceRecoveryServicesVaultCreate(d *pluginsdk.ResourceData, meta interfa
// Locked <- Unlocked <-> Disabled
if immutability == string(vaults.ImmutabilityStateLocked) {
updatePatch.Properties.SecuritySettings = expandRecoveryServicesVaultSecuritySettings(immutability)
requireAddtionalUpdate = true
requireAdditionalUpdate = true
immutability = string(vaults.ImmutabilityStateUnlocked)
}
vault.Properties.SecuritySettings = expandRecoveryServicesVaultSecuritySettings(immutability)
Expand All @@ -277,11 +277,11 @@ func resourceRecoveryServicesVaultCreate(d *pluginsdk.ResourceData, meta interfa
// `encryption` needs to be set before `cross_region_restore_enabled` is set. Or the service will return an error. "If CRR is enabled for the Vault, the storage state will be locked and it will interfere with further operations"
// recovery vault's encryption config cannot be set while creation, so a standalone update is required.
if _, ok := d.GetOk("encryption"); ok {
requireAddtionalUpdate = true
requireAdditionalUpdate = true
updatePatch.Properties.Encryption = expandEncryption(d)
}

if requireAddtionalUpdate {
if requireAdditionalUpdate {
err := client.UpdateThenPoll(ctx, id, updatePatch)
if err != nil {
return fmt.Errorf("updating Recovery Service %s: %+v, but recovery vault was created, a manually import might be required", id.String(), err)
Expand Down Expand Up @@ -448,7 +448,7 @@ func resourceRecoveryServicesVaultUpdate(d *pluginsdk.ResourceData, meta interfa
}

if model.Identity != nil && !validateIdentityUpdate(*existing.Model.Identity, *expandedIdentity) {
return fmt.Errorf("`Once `identity` sepcified, the managed identity must not be disabled (even temporarily). Disabling the managed identity may lead to inconsistent behavior. Details could be found on https://learn.microsoft.com/en-us/azure/backup/encryption-at-rest-with-cmk?tabs=portal#enable-system-assigned-managed-identity-for-the-vault")
return fmt.Errorf("`Once `identity` specified, the managed identity must not be disabled (even temporarily). Disabling the managed identity may lead to inconsistent behavior. Details could be found on https://learn.microsoft.com/en-us/azure/backup/encryption-at-rest-with-cmk?tabs=portal#enable-system-assigned-managed-identity-for-the-vault")
}

storageMode := d.Get("storage_mode_type").(string)
Expand Down Expand Up @@ -542,7 +542,7 @@ func resourceRecoveryServicesVaultUpdate(d *pluginsdk.ResourceData, meta interfa
}
}

requireAddtionalUpdate := false
requireAdditionalUpdate := false
additionalUpdatePatch := vaults.PatchVault{
Properties: &vaults.VaultProperties{},
}
Expand Down Expand Up @@ -579,7 +579,7 @@ func resourceRecoveryServicesVaultUpdate(d *pluginsdk.ResourceData, meta interfa
immutability := d.Get("immutability")
if currentImmutability != nil && string(*currentImmutability) == string(vaults.ImmutabilityStateDisabled) && immutability == string(vaults.ImmutabilityStateLocked) {
additionalUpdatePatch.Properties.SecuritySettings = expandRecoveryServicesVaultSecuritySettings(immutability)
requireAddtionalUpdate = true
requireAdditionalUpdate = true
immutability = string(vaults.ImmutabilityStateUnlocked)
}
vault.Properties.SecuritySettings = expandRecoveryServicesVaultSecuritySettings(immutability)
Expand All @@ -590,7 +590,7 @@ func resourceRecoveryServicesVaultUpdate(d *pluginsdk.ResourceData, meta interfa
return fmt.Errorf("updating %s: %+v", id, err)
}

if requireAddtionalUpdate {
if requireAdditionalUpdate {
err := client.UpdateThenPoll(ctx, id, additionalUpdatePatch)
if err != nil {
return fmt.Errorf("updating Recovery Service %s: %+v, but recovery vault was created, a manually import might be required", id.String(), err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/availabilitysets"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/proximityplacementgroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets"
vmwaremachines "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines"
vmwarerunasaccounts "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/recoveryservices/2022-10-01/vaults"
Expand Down Expand Up @@ -99,7 +97,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema {
ValidateFunc: validation.StringIsNotEmpty,
},

"recovery_vault_id": commonschema.ResourceIDReferenceRequired(vaults.VaultId{}),
"recovery_vault_id": commonschema.ResourceIDReferenceRequired(&vaults.VaultId{}),

"source_vm_name": {
Type: pluginsdk.TypeString,
Expand All @@ -115,7 +113,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema {
ValidateFunc: validation.StringIsNotEmpty,
},

"recovery_replication_policy_id": commonschema.ResourceIDReferenceRequired(replicationpolicies.ReplicationPolicyId{}),
"recovery_replication_policy_id": commonschema.ResourceIDReferenceRequired(&replicationpolicies.ReplicationPolicyId{}),

"physical_server_credential_name": {
Type: pluginsdk.TypeString,
Expand All @@ -131,7 +129,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema {
ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForLicenseType(), false),
},

"target_resource_group_id": commonschema.ResourceIDReferenceRequired(commonids.ResourceGroupId{}),
"target_resource_group_id": commonschema.ResourceIDReferenceRequired(&commonids.ResourceGroupId{}),

"target_vm_name": {
Type: pluginsdk.TypeString,
Expand All @@ -157,7 +155,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema {
"default_target_disk_encryption_set_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: diskencryptionsets.ValidateDiskEncryptionSetID,
ValidateFunc: commonids.ValidateDiskEncryptionSetID,
},

"multi_vm_group_name": {
Expand All @@ -166,7 +164,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema {
ValidateFunc: validation.StringIsNotEmpty,
},

"target_proximity_placement_group_id": commonschema.ResourceIDReferenceOptional(proximityplacementgroups.ProximityPlacementGroupId{}),
"target_proximity_placement_group_id": commonschema.ResourceIDReferenceOptional(&proximityplacementgroups.ProximityPlacementGroupId{}),

"target_vm_size": {
Type: pluginsdk.TypeString,
Expand All @@ -177,7 +175,7 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema {
"target_availability_set_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: availabilitysets.ValidateAvailabilitySetID,
ValidateFunc: commonids.ValidateAvailabilitySetID,
ConflictsWith: []string{
"target_zone",
},
Expand All @@ -199,9 +197,9 @@ func (s VMWareReplicatedVmResource) Arguments() map[string]*pluginsdk.Schema {
RequiredWith: []string{"network_interface"},
},

"test_network_id": commonschema.ResourceIDReferenceOptional(commonids.VirtualNetworkId{}),
"test_network_id": commonschema.ResourceIDReferenceOptional(&commonids.VirtualNetworkId{}),

"target_boot_diagnostics_storage_account_id": commonschema.ResourceIDReferenceOptional(commonids.StorageAccountId{}),
"target_boot_diagnostics_storage_account_id": commonschema.ResourceIDReferenceOptional(&commonids.StorageAccountId{}),

// managed disk is enabled only if mobility service is already installed. (in most cases, it's not installed)
"managed_disk": {
Expand Down Expand Up @@ -233,9 +231,9 @@ func resourceSiteRecoveryVMWareReplicatedVMManagedDiskSchema() *pluginsdk.Resour
ValidateFunc: validation.StringInSlice(replicationprotecteditems.PossibleValuesForDiskAccountType(), false),
},

"target_disk_encryption_set_id": commonschema.ResourceIDReferenceOptional(diskencryptionsets.DiskEncryptionSetId{}),
"target_disk_encryption_set_id": commonschema.ResourceIDReferenceOptional(&commonids.DiskEncryptionSetId{}),

"log_storage_account_id": commonschema.ResourceIDReferenceOptional(commonids.StorageAccountId{}),
"log_storage_account_id": commonschema.ResourceIDReferenceOptional(&commonids.StorageAccountId{}),
},
}
}
Expand Down Expand Up @@ -784,7 +782,7 @@ func (s VMWareReplicatedVmResource) Read() sdk.ResourceFunc {
if inMageRcm.RunAsAccountId != nil && *inMageRcm.RunAsAccountId != "" {
credential, err = fetchCredentialByRunAsAccountId(ctx, runAsAccountId, *inMageRcm.RunAsAccountId)
if err != nil {
return fmt.Errorf("retireving credential by run as account id %q: %+v", *inMageRcm.RunAsAccountId, err)
return fmt.Errorf("retrieving credential by run as account id %q: %+v", *inMageRcm.RunAsAccountId, err)
}
}
state.PhysicalServerCredentialName = credential
Expand Down Expand Up @@ -896,9 +894,9 @@ func fetchRunAsAccountsIdBySite(ctx context.Context, runAsAccountClient *vmwarer
return "", fmt.Errorf("parse %s: %+v", siteId, err)
}

hackedClinet := azuresdkhacks.RunAsAccountsClient{Client: runAsAccountClient.Client}
hackedClient := azuresdkhacks.RunAsAccountsClient{Client: runAsAccountClient.Client}
// GET on Site is not working, tracked on https://github.com/Azure/azure-rest-api-specs/issues/24711
resp, err := hackedClinet.GetAllRunAsAccountsInSiteComplete(ctx, *parsedSiteId)
resp, err := hackedClient.GetAllRunAsAccountsInSiteComplete(ctx, *parsedSiteId)
if err != nil {
return "", err
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a7db34

Please sign in to comment.