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

Fix azurerm_backup_protected_file_share #9015

Merged
merged 9 commits into from
Jan 14, 2021

Conversation

aristosvo
Copy link
Collaborator

@aristosvo aristosvo commented Oct 24, 2020

Context

azurerm_backup_protected_file_share was broken due to a backward incompatible change of the Azure Backup backend, using system names instead of user defined names.

Fixes #9368

Solution

The solution is implemented based on Azure Docs for the REST API, where protectable (and in our case also protected) fileshares' system names can be fetched.

Acceptance Tests

--- PASS: TestAccAzureRMBackupProtectedFileShare_basic (435.24s)
--- PASS: TestAccAzureRMBackupProtectedFileShare_requiresImport (450.48s)
--- PASS: TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId (534.66s)

Done

  • Resource azurerm_backup_protected_file_share fixed
  • Update documentation
    • Explain where the user unfriendly id/Azure Backup fileshare system name can be found
    • Resource is GA
    • Resource is locked when it contains backups

@aristosvo
Copy link
Collaborator Author

@tombuildsstuff What are we waiting for here? Should I rebase?

@aristosvo
Copy link
Collaborator Author

aristosvo commented Dec 8, 2020

Rebased:

AccTests
TF_ACC=1 go test -v ./azurerm/internal/services/recoveryservices/ -run=TestAccAzureRMBackupProtectedFileShare -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccAzureRMBackupProtectedFileShare_basic
=== PAUSE TestAccAzureRMBackupProtectedFileShare_basic
=== RUN   TestAccAzureRMBackupProtectedFileShare_requiresImport
=== PAUSE TestAccAzureRMBackupProtectedFileShare_requiresImport
=== RUN   TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId
=== PAUSE TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId
=== CONT  TestAccAzureRMBackupProtectedFileShare_basic
=== CONT  TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId
=== CONT  TestAccAzureRMBackupProtectedFileShare_requiresImport
--- PASS: TestAccAzureRMBackupProtectedFileShare_requiresImport (392.57s)
--- PASS: TestAccAzureRMBackupProtectedFileShare_basic (429.63s)
--- PASS: TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId (469.61s)
PASS

@nkiraly
Copy link

nkiraly commented Dec 20, 2020

Thank you very much for this improvement. I have been hitting this same problem.

I have tested this change in a locally built provisioner binary and determined that there is an Azure side issue which needs to be mitigated client side at least in the near term.

I suggest in the short term we do client side filtering of the List operations' return values for the desired friendlyName until the oData filtering in the REST API gets sorted out.

Fundamentally:
Backup ProtectedableItems and ProtectedItems List operations on Vaults with one or more registered Storage Accounts having more than one AzureStorage File Share in total always return all of the items -- oData filter expressions match examples from REST API docs such as backupManagementType eq 'AzureStorage' and friendlyName eq 'my-fileshare' are having no effect on the returned list, but tokens are being validated, since a garbage filter expression results in a 400 response. I would love to understand what is wrong with the OData expression if that is the issue here.

My use case:
I am managing Azure Machine Learning Workspaces with Terraform and while setting up backups of the Jupyter Notebooks code Azure File Share, and my terraform apply results in a validation error when provisioning a azurerm_backup_protected_file_share because the StorageAccount backing my ML workspace has, at a minimum, 2 FileShares created by the workspace: azureml-filestore-5ae8cb11-91cd-45d8-a243-957449454055 and code-391ff5ac-6576-460f-ba4d-7e03433c68b6.

resourceArmBackupProtectedFileShareCreateUpdate rightfully so checks that the List with oData filter only returned 1 item between the protectable and protected items responses.

I have confirmed this behavior is the REST API and not really anything to do with the provisioner List operation implementation:

The state of these file shares prior the the apply is that the StorageAccount is registered to the Vault with azurerm_backup_container_storage_account but no share backups have been set up yet.

selected terraformy apply output

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

2020/12/20 15:07:38 [DEBUG] command: asking for input: "Do you want to perform these actions?"
  # azurerm_backup_protected_file_share.machine_learning_11_filestore_code will be created
  + resource "azurerm_backup_protected_file_share" "machine_learning_11_filestore_code" {
      + backup_policy_id          = "/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupPolicies/daily-45"
      + id                        = (known after apply)
      + recovery_vault_name       = "nkiralyuseamlrecovery11"
      + resource_group_name       = "nkiraly-dev-usea-machine-learning-backups"
      + source_file_share_name    = "code-391ff5ac-6576-460f-ba4d-7e03433c68b6"
      + source_storage_account_id = "/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

.....


2020/12/20 15:09:03 [TRACE] <root>: eval: *terraform.EvalApplyPre
2020/12/20 15:09:03 [TRACE] <root>: eval: *terraform.EvalApply
azurerm_backup_protected_file_share.machine_learning_11_filestore_code: Creating...
2020/12/20 15:09:03 [DEBUG] azurerm_backup_protected_file_share.machine_learning_11_filestore_code: applying the planned Create change
2020/12/20 15:09:03 [TRACE] GRPCProvider: ApplyResourceChange
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: [DEBUG] AzureRM Request: 
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: GET /Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectableItems?%24filter=backupManagementType+eq+%27AzureStorage%27+and+friendlyName+eq+%27code-391ff5ac-6576-460f-ba4d-7e03433c68b6%27&api-version=2016-12-01 HTTP/1.1
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Host: management.azure.com
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: User-Agent: Go/go1.15.5 (amd64-linux) go-autorest/v14.2.1 Azure-SDK-For-Go/v48.1.0 backup/2019-05-13 HashiCorp Terraform/0.12.26 (+https://www.terraform.io) Terraform Plugin SDK/1.13.1 terraform-provider-azurerm/dev pid-222c6c49-1b0a-5959-a213-6608f9eb8820
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Correlation-Request-Id: 85f25c42-6f28-78d3-8cfb-27778ad78d77
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Accept-Encoding: gzip
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: 
2020-12-20T15:09:03.247-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: 
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: [DEBUG] AzureRM Response for https://management.azure.com/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectableItems?%24filter=backupManagementType+eq+%27AzureStorage%27+and+friendlyName+eq+%27code-391ff5ac-6576-460f-ba4d-7e03433c68b6%27&api-version=2016-12-01: 
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: HTTP/2.0 200 OK
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Cache-Control: no-cache
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Content-Type: application/json
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Date: Sun, 20 Dec 2020 20:09:03 GMT
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Expires: -1
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Pragma: no-cache
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Server: Microsoft-IIS/10.0
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Strict-Transport-Security: max-age=31536000; includeSubDomains
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Vary: Accept-Encoding
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Content-Type-Options: nosniff
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Client-Request-Id: ac9e8e65-05b0-434c-a8a2-3a4c4f747d2d
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Client-Request-Id: ac9e8e65-05b0-434c-a8a2-3a4c4f747d2d
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Correlation-Request-Id: 85f25c42-6f28-78d3-8cfb-27778ad78d77
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Ratelimit-Remaining-Subscription-Resource-Requests: 149
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Request-Id: 85f25c42-6f28-78d3-8cfb-27778ad78d77
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Routing-Request-Id: CANADACENTRAL:20201220T200903Z:5877559f-cf56-4fa4-8516-48c9d67c991c
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Powered-By: ASP.NET
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: 
2020-12-20T15:09:03.983-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: {"value":[{"id":"/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867","name":"azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867","type":"Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems","properties":{"parentContainerFabricId":"/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11","parentContainerFriendlyName":"nkiralyuseaml11","azureFileShareType":"XSMB","backupManagementType":"AzureStorage","workloadType":"AzureFileShare","protectableItemType":"AzureFileShare","friendlyName":"code-391ff5ac-6576-460f-ba4d-7e03433c68b6","protectionState":"NotProtected"}},{"id":"/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf","name":"azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf","type":"Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems","properties":{"parentContainerFabricId":"/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11","parentContainerFriendlyName":"nkiralyuseaml11","azureFileShareType":"XSMB","backupManagementType":"AzureStorage","workloadType":"AzureFileShare","protectableItemType":"AzureFileShare","friendlyName":"azureml-filestore-5ae8cb11-91cd-45d8-a243-957449454055","protectionState":"NotProtected"}}]}
2020-12-20T15:09:03.984-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: [DEBUG] AzureRM Request: 
2020-12-20T15:09:03.984-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: GET /Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectedItems?%24filter=backupManagementType+eq+%27AzureStorage%27+and+friendlyName+eq+%27code-391ff5ac-6576-460f-ba4d-7e03433c68b6%27&api-version=2019-05-13 HTTP/1.1
2020-12-20T15:09:03.984-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Host: management.azure.com
2020-12-20T15:09:03.984-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: User-Agent: Go/go1.15.5 (amd64-linux) go-autorest/v14.2.1 Azure-SDK-For-Go/v48.1.0 backup/2019-05-13 HashiCorp Terraform/0.12.26 (+https://www.terraform.io) Terraform Plugin SDK/1.13.1 terraform-provider-azurerm/dev pid-222c6c49-1b0a-5959-a213-6608f9eb8820
2020-12-20T15:09:03.984-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Correlation-Request-Id: 85f25c42-6f28-78d3-8cfb-27778ad78d77
2020-12-20T15:09:03.984-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Accept-Encoding: gzip
2020-12-20T15:09:03.985-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: 
2020-12-20T15:09:03.985-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: 
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: [DEBUG] AzureRM Response for https://management.azure.com/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectedItems?%24filter=backupManagementType+eq+%27AzureStorage%27+and+friendlyName+eq+%27code-391ff5ac-6576-460f-ba4d-7e03433c68b6%27&api-version=2019-05-13: 
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: HTTP/2.0 200 OK
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Cache-Control: no-cache
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Content-Type: application/json
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Date: Sun, 20 Dec 2020 20:09:04 GMT
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Expires: -1
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Pragma: no-cache
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Server: Microsoft-IIS/10.0
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Strict-Transport-Security: max-age=31536000; includeSubDomains
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: Vary: Accept-Encoding
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Content-Type-Options: nosniff
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Client-Request-Id: 9feb39dd-2da0-4a40-9801-4c3c048c6705
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Client-Request-Id: 9feb39dd-2da0-4a40-9801-4c3c048c6705
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Correlation-Request-Id: 85f25c42-6f28-78d3-8cfb-27778ad78d77
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Ratelimit-Remaining-Subscription-Resource-Requests: 149
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Request-Id: 85f25c42-6f28-78d3-8cfb-27778ad78d77
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Ms-Routing-Request-Id: CANADACENTRAL:20201220T200904Z:ca480f11-0b2c-443b-adda-8d2390bb3489
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: X-Powered-By: ASP.NET
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: 
2020-12-20T15:09:04.397-0500 [DEBUG] plugin.terraform-provider-azurerm_v2.41.0_x5: {"value":[]}
2020/12/20 15:09:04 [DEBUG] azurerm_backup_protected_file_share.machine_learning_11_filestore_code: apply errored, but we're indicating that via the Error pointer rather than returning it: [ERROR] multiple fileshares found after filtering protectable or protected fileshares where only one is expected
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/12/20 15:09:04 [TRACE] EvalMaybeTainted: azurerm_backup_protected_file_share.machine_learning_11_filestore_code encountered an error during creation, so it is now marked as tainted
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/12/20 15:09:04 [TRACE] EvalWriteState: removing state object for azurerm_backup_protected_file_share.machine_learning_11_filestore_code
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalApplyProvisioners
2020/12/20 15:09:04 [TRACE] EvalApplyProvisioners: azurerm_backup_protected_file_share.machine_learning_11_filestore_code has no state, so skipping provisioners
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/12/20 15:09:04 [TRACE] EvalMaybeTainted: azurerm_backup_protected_file_share.machine_learning_11_filestore_code encountered an error during creation, so it is now marked as tainted
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/12/20 15:09:04 [TRACE] EvalWriteState: removing state object for azurerm_backup_protected_file_share.machine_learning_11_filestore_code
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalIf
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalIf
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalWriteDiff
2020/12/20 15:09:04 [TRACE] <root>: eval: *terraform.EvalApplyPost
2020/12/20 15:09:04 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: [ERROR] multiple fileshares found after filtering protectable or protected fileshares where only one is expected
2020/12/20 15:09:04 [ERROR] <root>: eval: *terraform.EvalSequence, err: [ERROR] multiple fileshares found after filtering protectable or protected fileshares where only one is expected
2020/12/20 15:09:04 [TRACE] [walkApply] Exiting eval tree: azurerm_backup_protected_file_share.machine_learning_11_filestore_code
2020/12/20 15:09:04 [TRACE] vertex "azurerm_backup_protected_file_share.machine_learning_11_filestore_code": visit complete
2020/12/20 15:09:04 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2020/12/20 15:09:04 [TRACE] dag/walk: upstream of "provider.azurerm (close)" errored, so skipping
2020/12/20 15:09:04 [TRACE] dag/walk: upstream of "root" errored, so skipping
2020/12/20 15:09:04 [TRACE] statemgr.Filesystem: creating backup snapshot at terraform.tfstate.backup
2020/12/20 15:09:04 [TRACE] statemgr.Filesystem: no state changes since last snapshot
2020/12/20 15:09:04 [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate

2020/12/20 15:09:04 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2020/12/20 15:09:04 [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
Error: [ERROR] multiple fileshares found after filtering protectable or protected fileshares where only one is expected

  on recovery_services.tf line 31, in resource "azurerm_backup_protected_file_share" "machine_learning_11_filestore_code":
  31: resource "azurerm_backup_protected_file_share" "machine_learning_11_filestore_code" {


2020-12-20T15:09:04.443-0500 [DEBUG] plugin: plugin process exited: path=/home/nicholas/go/bin/terraform-provider-azurerm_v2.41.0_x5 pid=4165
2020-12-20T15:09:04.443-0500 [DEBUG] plugin: plugin exited

Here are four az rest commands used to check List operation output, since az backup protectable-item does not currently have support for FileShares

list operations, filtering AuzureStorage types

$ export ODATA_FILTER="backupManagementType eq %27AzureStorage%27"
$ az rest --method GET --verbose --url "https://management.azure.com/Subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AZURE_RESOURCE_GROUP_NAME}/providers/Microsoft.RecoveryServices/vaults/${AZ_RSV_NAME}/backupProtectableItems?api-version=${AZ_BPI_API_VERSION}&\$filter=${ODATA_FILTER}"
Request URL: 'https://management.azure.com/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectableItems?api-version=2019-06-15&$filter=backupManagementType%20eq%20%27AzureStorage%27'
Request method: 'GET'
Request headers:
    'User-Agent': 'python/3.6.10 (Linux-4.15.0-128-generic-x86_64-with-debian-buster-sid) AZURECLI/2.16.0 (DEB)'
    'Accept-Encoding': 'gzip, deflate'
    'Accept': '*/*'
    'Connection': 'keep-alive'
    'x-ms-client-request-id': '6b6716bf-b340-4417-8b2a-c431451d6771'
    'CommandName': 'rest'
    'ParameterSetName': '--method --verbose --url'
    'Authorization': 'Bearer eyJ0eXAiOiJKV...'
Request body:
None
Response status: 200
Response headers:
    'Cache-Control': 'no-cache'
    'Pragma': 'no-cache'
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Content-Encoding': 'gzip'
    'Expires': '-1'
    'Vary': 'Accept-Encoding'
    'X-Content-Type-Options': 'nosniff'
    'x-ms-request-id': 'c84a7603-4cd0-46e3-9321-94d94eb9ee52'
    'x-ms-client-request-id': '6b6716bf-b340-4417-8b2a-c431451d6771, 6b6716bf-b340-4417-8b2a-c431451d6771'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
    'Server': 'Microsoft-IIS/10.0'
    'X-Powered-By': 'ASP.NET'
    'x-ms-ratelimit-remaining-subscription-resource-requests': '148'
    'x-ms-correlation-request-id': 'c84a7603-4cd0-46e3-9321-94d94eb9ee52'
    'x-ms-routing-request-id': 'CANADACENTRAL:20201220T201849Z:c84a7603-4cd0-46e3-9321-94d94eb9ee52'
    'Date': 'Sun, 20 Dec 2020 20:18:49 GMT'
Response content:
{"value":[{"id":"/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867","name":"azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867","type":"Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems","properties":{"parentContainerFabricId":"/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11","parentContainerFriendlyName":"nkiralyuseaml11","azureFileShareType":"XSMB","backupManagementType":"AzureStorage","workloadType":"AzureFileShare","protectableItemType":"AzureFileShare","friendlyName":"code-391ff5ac-6576-460f-ba4d-7e03433c68b6","protectionState":"NotProtected"}},{"id":"/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf","name":"azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf","type":"Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems","properties":{"parentContainerFabricId":"/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11","parentContainerFriendlyName":"nkiralyuseaml11","azureFileShareType":"XSMB","backupManagementType":"AzureStorage","workloadType":"AzureFileShare","protectableItemType":"AzureFileShare","friendlyName":"azureml-filestore-5ae8cb11-91cd-45d8-a243-957449454055","protectionState":"NotProtected"}}]}
{
  "value": [
    {
      "id": "/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867",
      "name": "azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867",
      "properties": {
        "azureFileShareType": "XSMB",
        "backupManagementType": "AzureStorage",
        "friendlyName": "code-391ff5ac-6576-460f-ba4d-7e03433c68b6",
        "parentContainerFabricId": "/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11",
        "parentContainerFriendlyName": "nkiralyuseaml11",
        "protectableItemType": "AzureFileShare",
        "protectionState": "NotProtected",
        "workloadType": "AzureFileShare"
      },
      "resourceGroup": "nkiraly-dev-usea-machine-learning-backups",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems"
    },
    {
      "id": "/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf",
      "name": "azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf",
      "properties": {
        "azureFileShareType": "XSMB",
        "backupManagementType": "AzureStorage",
        "friendlyName": "azureml-filestore-5ae8cb11-91cd-45d8-a243-957449454055",
        "parentContainerFabricId": "/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11",
        "parentContainerFriendlyName": "nkiralyuseaml11",
        "protectableItemType": "AzureFileShare",
        "protectionState": "NotProtected",
        "workloadType": "AzureFileShare"
      },
      "resourceGroup": "nkiraly-dev-usea-machine-learning-backups",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems"
    }
  ]
}
Command ran in 1.767 seconds (init: 0.116, invoke: 1.651)


$ export ODATA_FILTER="backupManagementType eq %27AzureStorage%27"
$ az rest --method GET --verbose --url "https://management.azure.com/Subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AZURE_RESOURCE_GROUP_NAME}/providers/Microsoft.RecoveryServices/vaults/${AZ_RSV_NAME}/backupProtectedItems?api-version=${AZ_BPI_API_VERSION}&\$filter=${ODATA_FILTER}"
Request URL: 'https://management.azure.com/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectedItems?api-version=2019-06-15&$filter=backupManagementType%20eq%20%27AzureStorage%27'
Request method: 'GET'
Request headers:
    'User-Agent': 'python/3.6.10 (Linux-4.15.0-128-generic-x86_64-with-debian-buster-sid) AZURECLI/2.16.0 (DEB)'
    'Accept-Encoding': 'gzip, deflate'
    'Accept': '*/*'
    'Connection': 'keep-alive'
    'x-ms-client-request-id': '3c2bea95-8ae9-4e23-a27e-da3da4c3ee54'
    'CommandName': 'rest'
    'ParameterSetName': '--method --verbose --url'
    'Authorization': 'Bearer eyJ0eXAiOiJKV...'
Request body:
None
Response status: 200
Response headers:
    'Cache-Control': 'no-cache'
    'Pragma': 'no-cache'
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Content-Encoding': 'gzip'
    'Expires': '-1'
    'Vary': 'Accept-Encoding'
    'X-Content-Type-Options': 'nosniff'
    'x-ms-request-id': 'c13d5dec-794c-4432-b845-46847039c260'
    'x-ms-client-request-id': '3c2bea95-8ae9-4e23-a27e-da3da4c3ee54, 3c2bea95-8ae9-4e23-a27e-da3da4c3ee54'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
    'Server': 'Microsoft-IIS/10.0'
    'X-Powered-By': 'ASP.NET'
    'x-ms-ratelimit-remaining-subscription-resource-requests': '149'
    'x-ms-correlation-request-id': 'c13d5dec-794c-4432-b845-46847039c260'
    'x-ms-routing-request-id': 'CANADACENTRAL:20201220T201857Z:c13d5dec-794c-4432-b845-46847039c260'
    'Date': 'Sun, 20 Dec 2020 20:18:57 GMT'
Response content:
{"value":[]}
{
  "value": []
}
Command ran in 0.728 seconds (init: 0.115, invoke: 0.612)

request protectable items while specifying friendlyName in filter expression

$ export ODATA_FILTER="backupManagementType eq %27AzureStorage%27 and friendlyName eq %27code-391ff5ac-6576-460f-ba4d-7e03433c68b6%27"
$ az rest --method GET --verbose --url "https://management.azure.com/Subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AZURE_RESOURCE_GROUP_NAME}/providers/Microsoft.RecoveryServices/vaults/${AZ_RSV_NAME}/backupProtectableItems?api-version=${AZ_BPI_API_VERSION}&\$filter=${ODATA_FILTER}"
Request URL: 'https://management.azure.com/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectableItems?api-version=2019-06-15&$filter=backupManagementType%20eq%20%27AzureStorage%27%20and%20friendlyName%20eq%20%27code-391ff5ac-6576-460f-ba4d-7e03433c68b6%27'
Request method: 'GET'
Request headers:
    'User-Agent': 'python/3.6.10 (Linux-4.15.0-128-generic-x86_64-with-debian-buster-sid) AZURECLI/2.16.0 (DEB)'
    'Accept-Encoding': 'gzip, deflate'
    'Accept': '*/*'
    'Connection': 'keep-alive'
    'x-ms-client-request-id': 'f6184668-343f-42c0-b807-065c1ba69bf6'
    'CommandName': 'rest'
    'ParameterSetName': '--method --verbose --url'
    'Authorization': 'Bearer eyJ0eXAiOiJKV...'
Request body:
None
Response status: 200
Response headers:
    'Cache-Control': 'no-cache'
    'Pragma': 'no-cache'
    'Transfer-Encoding': 'chunked'
    'Content-Type': 'application/json'
    'Content-Encoding': 'gzip'
    'Expires': '-1'
    'Vary': 'Accept-Encoding'
    'X-Content-Type-Options': 'nosniff'
    'x-ms-request-id': 'cf574c6e-220c-485c-bfb8-dbb59908f215'
    'x-ms-client-request-id': 'f6184668-343f-42c0-b807-065c1ba69bf6, f6184668-343f-42c0-b807-065c1ba69bf6'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
    'Server': 'Microsoft-IIS/10.0'
    'X-Powered-By': 'ASP.NET'
    'x-ms-ratelimit-remaining-subscription-resource-requests': '149'
    'x-ms-correlation-request-id': 'cf574c6e-220c-485c-bfb8-dbb59908f215'
    'x-ms-routing-request-id': 'CANADACENTRAL:20201220T201908Z:cf574c6e-220c-485c-bfb8-dbb59908f215'
    'Date': 'Sun, 20 Dec 2020 20:19:08 GMT'
Response content:
{"value":[{"id":"/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867","name":"azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867","type":"Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems","properties":{"parentContainerFabricId":"/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11","parentContainerFriendlyName":"nkiralyuseaml11","azureFileShareType":"XSMB","backupManagementType":"AzureStorage","workloadType":"AzureFileShare","protectableItemType":"AzureFileShare","friendlyName":"code-391ff5ac-6576-460f-ba4d-7e03433c68b6","protectionState":"NotProtected"}},{"id":"/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf","name":"azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf","type":"Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems","properties":{"parentContainerFabricId":"/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11","parentContainerFriendlyName":"nkiralyuseaml11","azureFileShareType":"XSMB","backupManagementType":"AzureStorage","workloadType":"AzureFileShare","protectableItemType":"AzureFileShare","friendlyName":"azureml-filestore-5ae8cb11-91cd-45d8-a243-957449454055","protectionState":"NotProtected"}}]}
{
  "value": [
    {
      "id": "/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867",
      "name": "azurefileshare;04381412d4fc473317feaa5d387f73497135dd9e3624ca57715208be75cc7867",
      "properties": {
        "azureFileShareType": "XSMB",
        "backupManagementType": "AzureStorage",
        "friendlyName": "code-391ff5ac-6576-460f-ba4d-7e03433c68b6",
        "parentContainerFabricId": "/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11",
        "parentContainerFriendlyName": "nkiralyuseaml11",
        "protectableItemType": "AzureFileShare",
        "protectionState": "NotProtected",
        "workloadType": "AzureFileShare"
      },
      "resourceGroup": "nkiraly-dev-usea-machine-learning-backups",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems"
    },
    {
      "id": "/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupFabrics/Azure/protectionContainers/storagecontainer;storage;nkiraly-dev-usea-machine-learning;nkiralyuseaml11/protectableItems/azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf",
      "name": "azurefileshare;cfc060810b6ac202f131a70b3fd39b25f5ca3ae66d3e71eade31947faf1775bf",
      "properties": {
        "azureFileShareType": "XSMB",
        "backupManagementType": "AzureStorage",
        "friendlyName": "azureml-filestore-5ae8cb11-91cd-45d8-a243-957449454055",
        "parentContainerFabricId": "/subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning/providers/Microsoft.Storage/storageAccounts/nkiralyuseaml11",
        "parentContainerFriendlyName": "nkiralyuseaml11",
        "protectableItemType": "AzureFileShare",
        "protectionState": "NotProtected",
        "workloadType": "AzureFileShare"
      },
      "resourceGroup": "nkiraly-dev-usea-machine-learning-backups",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems"
    }
  ]
}
Command ran in 0.855 seconds (init: 0.115, invoke: 0.739)

request protectable items with maimed search term

$ export ODATA_FILTER="friendlyName eq %27${AZML_FS_NAME}%27 and backupManagType eq %27AzureStorage%27"
$ az rest --method GET --verbose --url "https://management.azure.com/Subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AZURE_RESOURCE_GROUP_NAME}/providers/Microsoft.RecoveryServices/vaults/${AZ_RSV_NAME}/backupProtectableItems?api-version=${AZ_BPI_API_VERSION}&\$filter=${ODATA_FILTER}"
Request URL: 'https://management.azure.com/Subscriptions/NKIRALY_AZSUBID/resourceGroups/nkiraly-dev-usea-machine-learning-backups/providers/Microsoft.RecoveryServices/vaults/nkiralyuseamlrecovery11/backupProtectableItems?api-version=2019-06-15&$filter=friendlyName%20eq%20%27code-391ff5ac-6576-460f-ba4d-7e03433c68b6%27%20and%20backupManagType%20eq%20%27AzureStorage%27'
Request method: 'GET'
Request headers:
    'User-Agent': 'python/3.6.10 (Linux-4.15.0-128-generic-x86_64-with-debian-buster-sid) AZURECLI/2.16.0 (DEB)'
    'Accept-Encoding': 'gzip, deflate'
    'Accept': '*/*'
    'Connection': 'keep-alive'
    'x-ms-client-request-id': '31fe151c-608e-4a16-a14f-646e096f4ea8'
    'CommandName': 'rest'
    'ParameterSetName': '--method --verbose --url'
    'Authorization': 'Bearer eyJ0eXAiOiJKV...'
Request body:
None
Response status: 400
Response headers:
    'Cache-Control': 'no-cache'
    'Pragma': 'no-cache'
    'Content-Length': '179'
    'Content-Type': 'application/json'
    'X-Content-Type-Options': 'nosniff'
    'x-ms-request-id': '9aa51ed0-e788-4eab-af5a-2f80c2b30587'
    'x-ms-client-request-id': '31fe151c-608e-4a16-a14f-646e096f4ea8, 31fe151c-608e-4a16-a14f-646e096f4ea8'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
    'Server': 'Microsoft-IIS/10.0'
    'X-Powered-By': 'ASP.NET'
    'x-ms-ratelimit-remaining-subscription-resource-requests': '149'
    'x-ms-correlation-request-id': '9aa51ed0-e788-4eab-af5a-2f80c2b30587'
    'x-ms-routing-request-id': 'CANADACENTRAL:20201220T201922Z:9aa51ed0-e788-4eab-af5a-2f80c2b30587'
    'Date': 'Sun, 20 Dec 2020 20:19:21 GMT'
Response content:
{"error":{"code":"BMSUserErrorInvalidInput","message":"Input provided for the call is invalid\r\nPlease check the required inputs","target":null,"details":null,"innerError":null}}
Bad Request({"error":{"code":"BMSUserErrorInvalidInput","message":"Input provided for the call is invalid\r\nPlease check the required inputs","target":null,"details":null,"innerError":null}})
Command ran in 0.968 seconds (init: 0.115, invoke: 0.853)

@aristosvo
Copy link
Collaborator Author

aristosvo commented Dec 21, 2020

@nkiraly Thanks for your investigation! This is indeed a case which is not properly tested (and implemented in the Azure REST API). I'll add a Acceptance test to show the problem and consider implementing a workaround:

AccTests
$ make acctests SERVICE='recoveryservices' TESTARGS='-run=TestAccAzureRMBackupProtectedFileShare'
...
=== CONT  TestAccAzureRMBackupProtectedFileShare_multiple
    testing.go:684: Step 0 error: errors during apply:
        
        Error: [ERROR] multiple fileshares found after filtering protectable or protected fileshares where only one is expected
        
          on /var/folders/wt/rn76884977bfp0dcqr7g1l7w0000gn/T/tf-test701927038/main.tf line 71:
          (source code not available)
        
        
--- FAIL: TestAccAzureRMBackupProtectedFileShare_multiple (293.61s)
--- PASS: TestAccAzureRMBackupProtectedFileShare_basic (437.03s)
--- PASS: TestAccAzureRMBackupProtectedFileShare_requiresImport (452.35s)
--- PASS: TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId (638.34s)
FAIL
FAIL    github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices   639.665s
FAIL
make: *** [acctests] Error 1

@aristosvo aristosvo force-pushed the fix-fileshare-backup branch from ef28da2 to b0bde1e Compare December 21, 2020 10:40
@ghost ghost added size/L and removed size/M labels Dec 21, 2020
@aristosvo aristosvo force-pushed the fix-fileshare-backup branch from b0bde1e to ccaf783 Compare December 22, 2020 09:43
@aristosvo
Copy link
Collaborator Author

aristosvo commented Dec 22, 2020

Rebased for the test shim changes, still the problem with multiple shares

@aristosvo
Copy link
Collaborator Author

aristosvo commented Dec 22, 2020

Multiple protected/protectable shares issue solved! @nkiraly, does this fix your problems?

> make acctests SERVICE='recoveryservices' TESTARGS='-run=TestAccBackupProtectedFileShare'
...
--- PASS: TestAccBackupProtectedFileShare_requiresImport (421.30s)
--- PASS: TestAccBackupProtectedFileShare_basic (438.75s)
--- PASS: TestAccBackupProtectedFileShare_multiple (444.50s)
--- PASS: TestAccBackupProtectedFileShare_updateBackupPolicyId (541.35s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices    542.744s

@aristosvo aristosvo force-pushed the fix-fileshare-backup branch 2 times, most recently from 656990a to d3bdc7f Compare December 22, 2020 16:44
@aristosvo
Copy link
Collaborator Author

aristosvo commented Dec 22, 2020

Tests seem to be a bit flaky due to the resource azurerm_backup_container_storage_account being unstable. The azurerm_backup_protected_file_share acctests are therefore taking turns to fail:

First run: 1 failure, 3 succeeding🤨
=== CONT  TestAccBackupProtectedFileShare_multiple
    testing.go:684: Step 0 error: errors during apply:
        
        Error: Recovery Service Protection Container operation status failed with status "Failed" (Vault "acctest-VAULT-201222180015351534" Resource Group "acctestRG-backup-201222180015351534" Operation ID "9228bfd2-6412-4f83-a9dd-8bd458635fc3"): Microsoft Azure Backup encountered an internal error.
        
          on /var/folders/wt/rn76884977bfp0dcqr7g1l7w0000gn/T/tf-test573120173/main.tf line 99:
          (source code not available)
        
        
--- FAIL: TestAccBackupProtectedFileShare_multiple (294.94s)
Second run: 2 failures (different ones), 2 succeeding (of which one failed previously)🤨
=== CONT  TestAccBackupProtectedFileShare_updateBackupPolicyId
    testing.go:684: Step 0 error: errors during apply:
        
        Error: Recovery Service Protection Container operation status failed with status "Failed" (Vault "acctest-VAULT-201223172215125572" Resource Group "acctestRG-backup-201223172215125572" Operation ID "c68b1f18-e9ca-4b99-9d46-6d09ac37685f"): Microsoft Azure Backup encountered an internal error.
        
          on /var/folders/wt/rn76884977bfp0dcqr7g1l7w0000gn/T/tf-test034810285/main.tf line 59:
          (source code not available)
--- FAIL: TestAccBackupProtectedFileShare_updateBackupPolicyId (110.37s)

and

=== CONT  TestAccBackupProtectedFileShare_requiresImport
    testing.go:684: Step 0 error: errors during apply:
        
        Error: Recovery Service Protection Container operation status failed with status "Failed" (Vault "acctest-VAULT-201223172215121802" Resource Group "acctestRG-backup-201223172215121802" Operation ID "56b011cb-b8de-4835-b549-a7d654e48e3b"): Microsoft Azure Backup encountered an internal error.
        
          on /var/folders/wt/rn76884977bfp0dcqr7g1l7w0000gn/T/tf-test034254120/main.tf line 59:
          (source code not available)
--- FAIL: TestAccBackupProtectedFileShare_requiresImport (110.38s)

When looking at the acctests for azurerm_backup_container_storage_account:

First run: failure🤨
$ make acctests SERVICE='recoveryservices' TESTARGS='-run=TestAccBackupProtectionContainerStorageAccount'
=== CONT  TestAccBackupProtectionContainerStorageAccount_basic
    testing.go:745: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: errors during apply: Error issuing delete request for Storage Account "unlikely23exst2acctzgvds" (Resource Group "acctestRG-backup-201223173455339359"): storage.AccountsClient#Delete: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="StorageAccountOperationInProgress" Message="An operation is currently performing on this storage account that requires exclusive access."

...
--- FAIL: TestAccBackupProtectionContainerStorageAccount_basic (343.86s)
Second run: success🤨
$ make acctests SERVICE='recoveryservices' TESTARGS='-run=TestAccBackupProtectionContainerStorageAccount'
=== CONT  TestAccBackupProtectionContainerStorageAccount_basic
--- PASS: TestAccBackupProtectionContainerStorageAccount_basic (300.72s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices       302.140s

Is this something which could be solved by upgrading API versions or should this be raised as a problem at Azure level?

@aristosvo aristosvo force-pushed the fix-fileshare-backup branch from d3bdc7f to 246290a Compare December 22, 2020 17:10
@aristosvo aristosvo force-pushed the fix-fileshare-backup branch from 246290a to fd5eda1 Compare December 22, 2020 17:19
@aristosvo aristosvo force-pushed the fix-fileshare-backup branch from a365d3d to d12e8d9 Compare December 23, 2020 16:19
@nkiraly
Copy link

nkiraly commented Dec 23, 2020

Nice @aristosvo ! I successfully planned and applied the previously tested file share backup with a build of the provider at d12e8d9

@aristosvo
Copy link
Collaborator Author

aristosvo commented Dec 29, 2020

Last improvement of test stability included change of toggle to soft_delete_enabled = true, acctests for both azurerm_backup_container_storage_account and azurerm_backup_protected_file_share adjusted:

AccTests azurerm_backup_container_storage_account
❯ make acctests SERVICE='recoveryservices' TESTARGS='-run=TestAccBackupProtectionContainerStorageAccount'
==> 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 ./azurerm/internal/services/recoveryservices/ -run=TestAccBackupProtectionContainerStorageAccount -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccBackupProtectionContainerStorageAccount_basic
=== PAUSE TestAccBackupProtectionContainerStorageAccount_basic
=== CONT  TestAccBackupProtectionContainerStorageAccount_basic
--- PASS: TestAccBackupProtectionContainerStorageAccount_basic (304.55s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices 306.009s
AccTests azurerm_backup_protected_file_share
❯ make acctests SERVICE='recoveryservices' TESTARGS='-run=TestAccBackupProtectedFileShare'
==> 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 ./azurerm/internal/services/recoveryservices/ -run=TestAccBackupProtectedFileShare -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccBackupProtectedFileShare_basic
=== PAUSE TestAccBackupProtectedFileShare_basic
=== RUN   TestAccBackupProtectedFileShare_multiple
=== PAUSE TestAccBackupProtectedFileShare_multiple
=== RUN   TestAccBackupProtectedFileShare_requiresImport
=== PAUSE TestAccBackupProtectedFileShare_requiresImport
=== RUN   TestAccBackupProtectedFileShare_updateBackupPolicyId
=== PAUSE TestAccBackupProtectedFileShare_updateBackupPolicyId
=== CONT  TestAccBackupProtectedFileShare_basic
=== CONT  TestAccBackupProtectedFileShare_updateBackupPolicyId
=== CONT  TestAccBackupProtectedFileShare_multiple
=== CONT  TestAccBackupProtectedFileShare_requiresImport
--- PASS: TestAccBackupProtectedFileShare_multiple (426.75s)
--- PASS: TestAccBackupProtectedFileShare_basic (435.87s)
--- PASS: TestAccBackupProtectedFileShare_requiresImport (438.79s)
--- PASS: TestAccBackupProtectedFileShare_updateBackupPolicyId (519.21s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices520.592s

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.

Thanks @aristosvo - this LGTM 👍

GNUmakefile Outdated Show resolved Hide resolved
@katbyte katbyte merged commit d15e39f into hashicorp:master Jan 14, 2021
katbyte added a commit that referenced this pull request Jan 14, 2021
@ghost
Copy link

ghost commented Jan 21, 2021

This has been released in version 2.44.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.44.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Feb 14, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

backup_protected_file_share is broken
5 participants