hashicorp/terraform-provider-aws

aws_storagegateway_smb_file_share: cache_stale_timeout_in_seconds validation rejects 0, but the AWS API accepts it (blocks disabling cache refresh)

Open

#48,876 opened on Jul 9, 2026

 (4 comments) (0 reactions) (0 assignees)Go (10,310 forks)github user discovery
buggood first issueservice/storagegateway

Repository metrics

Stars
 (11,045 stars)
PR merge metrics
 (PR metrics pending)

Description

Terraform and AWS Provider Version

Terraform / Provider versions: Terraform 1.14.x; hashicorp/aws - reproduced on both v5.100.0 and v6.53.0.

Affected Resource(s) or Data Source(s)

aws_storagegateway_smb_file_share

Expected Behavior

cache_attributes.cache_stale_timeout_in_seconds should accept 0 on aws_storagegateway_smb_file_share. The AWS Storage Gateway API documents 0 as a valid value meaning "cache refresh turned off" (Valid Values: 0 or 300-2,592,000), and it's what the console sets when "Automatic cache refresh from S3" is set to None. Terraform should be able to both create and update a share with this value so that cache refresh can be disabled, and so that shares already set to 0 (via console/CLI) can be managed without a permanent diff.

Actual Behavior

The provider validates the field as IntBetween(300, 2592000), so 0 is rejected at plan time and Terraform cannot set it - even though the AWS API accepts it. This has two consequences:

  1. A share's cache refresh cannot be disabled through Terraform (there is no accepted value that means "off").
  2. Shares set to 0 out-of-band (console/CLI) never converge: the provider can't write 0, and omitting the cache_attributes block is a no-op at the API (AWS leaves the existing value unchanged), so the block-present 0 is read back on every refresh. The result is a permanent, non-convergent 0 -> null plan diff.

Reproduced on hashicorp/aws v5.100.0 and v6.53.0.

That the API accepts 0 is easily confirmed outside Terraform:

aws storagegateway update-smb-file-share --file-share-arn <arn> \
  --cache-attributes CacheStaleTimeoutInSeconds=0
aws storagegateway describe-smb-file-shares --file-share-arn-list <arn> \
  --query 'SMBFileShareInfoList[].CacheAttributes'
# => [ { "CacheStaleTimeoutInSeconds": 0 } ]

The resource docs also state only "300 to 2,592,000", which should be updated to include 0.

Relevant Error/Panic Output

Error: expected cache_attributes.0.cache_stale_timeout_in_seconds to be in the range (300 - 2592000), got 0

  with aws_storagegateway_smb_file_share.example,
  on main.tf line 16, in resource "aws_storagegateway_smb_file_share" "example":
  16:     cache_stale_timeout_in_seconds = 0

Sample Terraform Configuration

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "6.53.0" # also reproduces on 5.100.0
    }
  }
}

provider "aws" {
  region = "eu-central-1"
}

resource "aws_storagegateway_smb_file_share" "example" {
  gateway_arn  = "arn:aws:storagegateway:eu-central-1:111122223333:gateway/sgw-12345678"
  location_arn = "arn:aws:s3:::example-bucket"
  role_arn     = "arn:aws:iam::111122223333:role/example"

  cache_attributes {
    cache_stale_timeout_in_seconds = 0 # AWS API accepts 0 ("off"); provider rejects it
  }
}

Steps to Reproduce

  1. Save the configuration above.
  2. Run terraform init.
  3. Run terraform plan.

The plan fails immediately with the range-validation error - the value never reaches AWS, confirming this is provider-side validation, not an API rejection. (For contrast, the equivalent value set directly through the AWS CLI - update-smb-file-share --cache-attributes CacheStaleTimeoutInSeconds=0 -- succeeds.)

Debug Logging

No response

GenAI / LLM Assisted Development

n/a

Important Facts and References

No response

Would you like to implement a fix?

No

Contributor guide