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

Data source refresh causes unwanted/unneeded recreation of resource #20303

Closed
1 task done
karloefd95 opened this issue Feb 3, 2023 · 3 comments
Closed
1 task done

Comments

@karloefd95
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

1.1.7

AzureRM Provider Version

3.40.0

Affected Resource(s)/Data Source(s)

azurerm_subscription, azurerm_client_config

Terraform Configuration Files

data "azurerm_subscription" "current" {}

resource "azurerm_role_assignment" "rg_reader" {
  principal_id                     = var.principal_id
  role_definition_name             = "Reader"
  scope = format(
    "/subscriptions/%s/resourcegroups/%s",
    data.azurerm_subscription.current.subscription_id,
    var.rg_name
  )
  skip_service_principal_aad_check = true
}

Debug Output/Panic Output

data "azurerm_subscription" "current"  {
      ~ display_name          = "DUMMY-SUBSCRIPTION-NAME" -> (known after apply)
      ~ id                    = "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -> (known after apply)
      ~ location_placement_id = "Public_XXX" -> (known after apply)
      ~ quota_id              = "XXX" -> (known after apply)
      ~ spending_limit        = "Off" -> (known after apply)
      ~ state                 = "Enabled" -> (known after apply)
      ~ subscription_id       = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -> (known after apply)
      ~ tags                  = {} -> (known after apply)
      ~ tenant_id             = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" -> (known after apply)

      + timeouts {
          + read = (known after apply)
        }
    }

Expected Behaviour

After the first creation, the azurerm_role_assignment should not be recreated as nothing changed in resource definition.

Actual Behaviour

On every run of terraform plan/apply azurerm_role_assignment is recreated because azurerm_subscription.current data source is unkown/known after apply but none of Attributes References aren't changed. This forces recreation of azurerm_role_assignment resource and makes terraform plan output hard to read and understand what will actually change.

Steps to Reproduce

  1. paste terraform configuration file
  2. create resource with terraform apply
  3. don't change anything in terrafrom configuration
  4. run terraform plan again

Important Factoids

No response

References

No response

@ms-zhenhua
Copy link
Contributor

Hi @karloefd95, I tried to reproduce this issue with your configuration and do not meet the data source refresh issue.
This issue is very similar with another one, which says the issue may be caused by some configuration dependency. Could you try to replace the 2 variables(principal_id and scope) with constant values and try it again?

@karloefd95
Copy link
Author

Hi @ms-zhenhua , thanks for your reply. Yes, I was using data source in module which is depended on another module.
I switched data source to main.tf file and I'm now passing value of subscription from data source through variable into module and everything seems to work like it should.
Thanks for your reply and help.

@github-actions
Copy link

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 have found a problem that seems similar to this, 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 Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants