when trying to create an EFS resources and associa...
# aws
a
when trying to create an EFS resources and associated MountTargets, Pulumi always wants to recreate the MountTargets on every
pulumi up
, even though the resources are not changing. It then runs into a block, since MountTargets are already created in each subnet, and finally errors out. Does anyone know how to avoid this? (relevant code can be seen in the thread)
Copy code
# Create an EFS File System
shared_file_system = aws.efs.FileSystem(
    "shared_file_system",
    lifecycle_policy=aws.efs.FileSystemLifecyclePolicyArgs(
        transition_to_ia="AFTER_7_DAYS",
    ),
    encrypted=False,  # TODO: Add encryption
    performance_mode="generalPurpose",  # could also be: "maxIO"
    tags={
        "Environment": ENV,
        "Scope": PROJECT_SCOPE,
        "Name": f"{PROJECT_SCOPE}-shared-file-system-{ENV}",
    },
)

nfs_security_group = aws.ec2.SecurityGroup(
    "shared-file-system-security-group",
    vpc_id=vpc.id,
    description="Allow all NFS traffic",
    tags={
        "Name": f"{PROJECT_SCOPE}-nfs-sg-{ENV}",
        "Scope": PROJECT_SCOPE,
    },
    ingress=[
        aws.ec2.SecurityGroupIngressArgs(
            cidr_blocks=["0.0.0.0/0"],
            from_port=2049,
            to_port=2049,
            protocol="tcp",
            description="Allow NFS traffic",
        ),
    ],
)

shared_file_system_mount_targets = []
for subnet in subnets:
    mount_target = aws.efs.MountTarget(
        f"efs-mount-target-{subnet.id}",
        file_system_id=shared_file_system.id,
        subnet_id=subnet.id,
        security_groups=[nfs_security_group.id],
        # ip_address=ip,
        opts=pulumi.ResourceOptions(delete_before_replace=True),
    )
    shared_file_system_mount_targets.append(mount_target)