Terraform aws_security_group data timeouts

Hi,

I’m using the data resource aws_security_group to lookup an SG ID. However I require a read timeout as the SG will not be available for a few minutes. By default it seems to timeout after 2 mins. According to the documentation I can add a read timeout like below:

data “aws_security_group” “this” {
vpc_id = module.vpc.vpc_id
tags = {
Name = “some-sg”
}

timeouts {
read = “10m”
}

}

Yet it still times out after 2 mins.

I am using:
Terraform v1.7.4
hashicorp/aws v5.58.0

For anyone wondering why I need a timeout… The code deploys an EC2 & VPC. The EC2 requires a SG. But the SG is created via an AWS firewall manager policy (handled outside of this code). And hence the delay, as it takes several minutes for FW manage to create the SG when a new VPC is created.

I think I see the issue. The timeout does not allow the data lookup to constantly check for the SG. Instead it is waiting until the VCP has been created. So times out as soon as that is created. If I take the data lookup into a separate piece of code and hardcode an available VPC ID in, the lookup fails instantly.

You could perhaps use the time_sleep resource, which is part of the time provider, to introduce some external wait time. The RAM example in the documentation is a similar scenario in concept.