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

Changes to timeouts only should also be detected and result into an apply #963

Open
magodo opened this issue May 11, 2022 · 3 comments
Open
Labels
enhancement New feature or request terraform-plugin-framework Resolved in terraform-plugin-framework

Comments

@magodo
Copy link

magodo commented May 11, 2022

SDK version

v2.16.0

Use-cases

Deploy following config:

resource "azurerm_resource_group" "test" {
  name     = "mgd-test123"
  location = "eastus2"
}

The default timeouts are set:

$ cat terraform.tfstate | jq '.resources | .[] | select(.type == "azurerm_resource_group") | .instances[0].private' | tr -d '"' | base64 -d | jq '.["e2bfb730-ecaa-11e6-8f88-34363bc7c4c0"]'
{
  "create": 5400000000000,
  "delete": 5400000000000,
  "read": 300000000000,
  "update": 5400000000000
}

Adding the timeouts for read = "10m", and refresh, the stored meta in state is not changed for the read timeout:

$ tf refresh
azurerm_resource_group.test: Refreshing state... [id=/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/mgd-test123]
$ cat terraform.tfstate | jq '.resources | .[] | select(.type == "azurerm_resource_group") | .instances[0].private' | tr -d '"' | base64 -d | jq '.["e2bfb730-ecaa-11e6-8f88-34363bc7c4c0"]'
{
  "create": 5400000000000,
  "delete": 5400000000000,
  "read": 300000000000,
  "update": 5400000000000
}

Also, the terraform plan shows no diff.

The only way to update the timeout is to change something in the resource to trigger an apply:

$ tf apply -auto-approve
...
Terraform will perform the following actions:

  # azurerm_resource_group.test will be updated in-place
  ~ resource "azurerm_resource_group" "test" {
        id       = "/subscriptions/0000/resourceGroups/mgd-test123"
        name     = "mgd-test123"
      ~ tags     = {
          + "foo" = "bar"
        }
        # (1 unchanged attribute hidden)

      + timeouts {
          + read = "10m"
        }
    }

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

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

$ cat terraform.tfstate | jq '.resources | .[] | select(.type == "azurerm_resource_group") | .instances[0].private' | tr -d '"' | base64 -d | jq '.["e2bfb730-ecaa-11e6-8f88-34363bc7c4c0"]'
{
  "create": 5400000000000,
  "delete": 5400000000000,
  "read": 600000000000,
  "update": 5400000000000
}

This is fine in most cases, as simply updating the timeout for the resource is meaningless, until any operation happens to the resource, i.e. when applying.

However, there is an unfortunate fact that the new timeout only takes effect after the plan stage (PlanResourceChange in context of the proto) during apply, but not before, i.e. the read (ReadResource in context of the proto) during refresh is still using the old read timeout. This causes issues like hashicorp/terraform-provider-azurerm#14213, where users are managing a collection of same typed resources, the default timeout of it is not long enough to finish the read. In that case, changing the timeout for read doesn't work for the terraform apply/terraform plan as the refresh part will still use the old timeout, results into timeout.

The workaround for this is:

  1. Either make a dummy change for all these resources to trigger an apply (with -fresh=false to avoid refreshing)
  2. Or recreate all these resources with timeout set before apply

Both solutions seem not ideal, it would be cool if we can detect the diff for timeouts and make an apply to update it.

@bflad
Copy link
Member

bflad commented Oct 26, 2022

Drive-by note: I'm guessing the framework's handling for this wouldn't have this issue as it does not treat the timeouts configuration different from any other attribute. The framework allows customization of no-change plans, if necessary.

If you want to try it out, here's some information:

@bflad bflad added the terraform-plugin-framework Resolved in terraform-plugin-framework label Oct 26, 2022
@lyderichti59
Copy link

I can confirm I'm facing the same issue and my timeout only changes were never picked up, at least until I forced a dummy change to the resource, but it's not always that easy to do.

@vc-lijup-nandana
Copy link

I am also facing the same issue. Increasing time out does noy fix my issue and I am CAF module for private dns zone and azurerm_private_dns_zone_virtual_network_link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request terraform-plugin-framework Resolved in terraform-plugin-framework
Projects
None yet
Development

No branches or pull requests

4 participants