starting out small with creating the file system and replication and then using the “destination[0].file_system_id” output to then assign some tags. Once I have the format, I can then do it to assign file system policies, vpcs, subnets, security groups etc…
I cannot figure out how to use/reference the output of the replica file system id (destination id) in subsequent resource configs within the same module.
I am doing all of this in one tf script so I can use the base text as a template that I can replace the file name with the actual names I will create so I don’t need variables in this case as the requirements will vary from request to request.
resource "aws_efs_file_system" "efs" {
encrypted = true
tags = {
Name = "efs"
Team = "infra"
Environment = "mod"
Business = "enterprise"
}
}
resource "aws_efs_replication_configuration" "efs" {
source_file_system_id = aws_efs_file_system.efs.id
destination {
region = "us-east-2"
}
}
resource "aws_efs_file_system" "efs-dr" {
id = aws_efs_replication_configuration.efs.destination[0].file_system_id
depends_on = [aws_efs_replication_configuration.efs]
provider = aws.oh
tags = {
Name = "efs-dr"
Team = "infra"
Environment = "mod"
Business = "enterprise"
}
}
output "destination_file_system_id" {
value = aws_efs_replication_configuration.efs.destination[0].file_system_id
}
terraform apply returns the following;
│ Error: Invalid or unknown key
│
│ with aws_efs_file_system.efs-dr,
│ on efstemplate.tf line 59, in resource "aws_efs_file_system" "efs-dr":
│ 59: id = aws_efs_replication_configuration.efs.destination[0].file_system_id