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

Let azurerm_storage_share_file re-create deleted files #13269

Merged
merged 3 commits into from
Sep 17, 2021
Merged

Let azurerm_storage_share_file re-create deleted files #13269

merged 3 commits into from
Sep 17, 2021

Conversation

heoelri
Copy link
Contributor

@heoelri heoelri commented Sep 8, 2021

azurerm_storage_share_file in plan/apply/destroy currently fails when a file created by azurerm_storage_share_file was deleted outside of Terraform. This behavior is, from my point of view, not consistent with how other resources deal with changes done outside of Terraform.

│ Error: retrieving Storage Share "" (File Share "fileshare" / Account "storageaccount" / Resource Group "resourcegroup"): files.Client#GetProperties: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: error response cannot be parsed: "" error: EOF

│   with azurerm_storage_share_file.usersfile,
│   on storage.tf line 23, in resource "azurerm_storage_share_file" "usersfile":
│   23: resource "azurerm_storage_share_file" "usersfile" {

This PR changes the behavior by switching from failing to recognizing and re-creating the file:

https://github.com/heoelri/terraform-provider-azurerm/blob/71e4c20d9e46a4aeed45d368f55c777542d26c94/internal/services/storage/storage_share_file_resource.go#L288-L293

instead of

props, err := client.GetProperties(ctx, id.AccountName, id.ShareName, id.DirectoryName, id.FileName)
if err != nil {
return fmt.Errorf("retrieving Storage Share %q (File Share %q / Account %q / Resource Group %q): %s", id.DirectoryName, id.ShareName, id.AccountName, account.ResourceGroup, err)
}

This will now result in re-creating the deleted file if needed:

azurerm_storage_share_file.deployment: Refreshing state... [id=https://tfstoragesample.file.core.windows.net/sample//sample.file]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # azurerm_storage_share_file.deployment has been deleted
  - resource "azurerm_storage_share_file" "deployment" {
      - content_type     = "application/octet-stream" -> null
      - id               = "https://tfstoragesample.file.core.windows.net/sample//sample.file" -> null
      - metadata         = {} -> null
      - name             = "sample.file" -> null
      - source           = "sample.file" -> null
      - storage_share_id = "https://tfstoragesample.file.core.windows.net/sample" -> null
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_storage_share_file.deployment will be created
  + resource "azurerm_storage_share_file" "deployment" {
      + content_type     = "application/octet-stream"
      + id               = (known after apply)
      + name             = "sample.file"
      + source           = "sample.file"
      + storage_share_id = "https://tfstoragesample.file.core.windows.net/sample"
    }

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

I've also updated the used giovanni sdk components from 2019-12-12 to 2020-08-04. @tombuildsstuff FYI

CC @sebader

@github-actions github-actions bot added size/S and removed size/XL labels Sep 8, 2021
@heoelri heoelri marked this pull request as ready for review September 8, 2021 11:14
@katbyte katbyte added this to the v2.78.0 milestone Sep 17, 2021
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 @heoelri - LGTM 🍔

@github-actions
Copy link

This functionality has been released in v2.78.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 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.

3 participants