terraform-plugin-sdk icon indicating copy to clipboard operation
terraform-plugin-sdk copied to clipboard

Timeouts are not applied to a Data Source read during apply

Open crhino opened this issue 3 years ago • 3 comments

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2 v2.21.0

Relevant provider source code

func dataSourceAzurePeeringConnection() *schema.Resource {
	return &schema.Resource{
		Description: "The Azure peering connection data source provides information about a peering connection between an HVN and a peer Azure VNet.",
		ReadContext: dataSourceAzurePeeringConnectionRead,
		Timeouts: &schema.ResourceTimeout{
			Read: 35 * time.Minute,
		},
...

Github link

Terraform Configuration Files

data "hcp_azure_peering_connection" "peering" {
  hvn_link              = var.hvn.self_link
  peering_id            = hcp_azure_peering_connection.peering.peering_id
  wait_for_active_state = true
  timeouts {
    read = "1m"
  }
}

Debug Output

Expected Behavior

I expect that the Read timeout value is correctly applied to the data source read (35 minutes in the Go code, 1 minute in the HCL example).

Actual Behavior

For all data source reads, the default 20 minutes timeout appears to be applied.

Steps to Reproduce

References

I attempted to dig a bit into the SDK code, and found the ReadDataApply function, which does not set the data.timeouts field before calling read(), unlike similar functions such as RefreshWithoutUpgrade.

If I am reading that correctly, then we are not correctly sourcing the timeouts set on the Resource.Timeouts field into the ResourceData struct?

crhino avatar Aug 22 '22 20:08 crhino

Thanks for investigating this! We'll work with the plugin team to get that upstream fix.

bcmdarroch avatar Aug 23 '22 22:08 bcmdarroch

Hi @crhino 👋 Thank you for raising this and sorry you ran into trouble here.

While we can likely bake in data source support for the timeouts mechanism at some point, I did want to mention one workaround here that can be applied today, where the data source is setup to use ReadWithoutTimeout instead of ReadContext.

For example:

func dataSourceAzurePeeringConnection() *schema.Resource {
	return &schema.Resource{
		Description: "The Azure peering connection data source provides information about a peering connection between an HVN and a peer Azure VNet.",
		ReadWithoutTimeout: dataSourceAzurePeeringConnectionRead,

This will remove the automatic 20 minute timeout that the SDK is applying to the operation. You can of course still setup your own 35 minute timeout within the read logic, if necessary.

bflad avatar Aug 29 '22 16:08 bflad

We just released a new version of the HCP Terraform Provider which includes the workaround mentioned: https://github.com/hashicorp/terraform-provider-hcp/releases/tag/v0.44.0

itsjaspermilan avatar Sep 09 '22 19:09 itsjaspermilan