What happens to imported resources on terraform destroy


I need to import an existing EFS filesystem into my terraform scripts, but I wonder what would happen to those imported resources when terraform destroy is run. Documentation isn’t very clear on to up to what point an imported resource is managed by terraform, will it be deleted ? or just the mount target will be dettached from the terraform managed instances ?


Once terraform import succeeds, Terraform treats the imported object the same as if Terraform had itself created it, and so terraform destroy would destroy it.

If you wish to use an existing EFS filesystem without having Terraform manage it, you can use the aws_efs_file_system data source to read information about the filesystem for use elsewhere in your configuration.

1 Like

Hi Martin,

Thanks for your answer, I was not aware of those data sources. Using them will I be able to associate a security group created by terraform, so ec2 instances can access the EFS file system ?

Data sources allow you to retrieve information about objects that already exist. You can use the values they return in whatever way you need. I can’t help with exact details around EC2 instances and EFS file systems (I work on Terraform Core, not on the AWS provider) but if the data you need for creating that security group and/or EC2 instance is included in the “Attributes Reference” of the aws_efs_file_system data source then in principle it should be possible.

Excellent, I will look into the data sources and do my tests.