0

I have a CloudFormation script that has the following:

"Parameters": {
   "optionalExistingEFSDrive": {
     "Description": "EFS drive to store client content. If left empty a new drive will be created automatically.",
     "Type": "String",
     "Default": ""
   }
},
"Conditions": {
   "CreateEFSDrive": { "Fn::Equals": [ { "Ref": "optionalExistingEFSDrive" }, "" ] },
},
"Resources": {
  "WebFileSystem": {
    "Type": "AWS::EFS::FileSystem",
    "Condition": "CreateEFSDrive",
    "DeletionPolicy": "Retain",
    "Properties": {
      "FileSystemTags": [
        {
          "Key": "Name",
          "Value": "WebFileSystem"
        }
      ],
      "PerformanceMode": "generalPurpose"
    }
  },
  "WebFileSystemMountTarget1": {
    "Type": "AWS::EFS::MountTarget",
    "Properties": {
      "SubnetId": {
        "Ref": "WebFileSystemSubnet1"
      },
      "SecurityGroups": [
        {
          "Ref": "WebFileSystemSecurityGroup"
        }
      ],
      "FileSystemId": {
        "Fn::If": [ "CreateEFSDrive", { "Ref": "WebFileSystem" }, { "Ref": "optionalExistingEFSDrive" } ]
      }
    }
  }
}

Passing in a value for optionalExistingEFSDrive that is the file system id of an existing file system, a new filesystem is created, but the mount target correctly mounts to the provided optionalExistingEFSDrive filesystem.

What am I missing? I don't want to create a new EFS, I want to re-use an existing one.

1 Answer 1

0

I can't reproduce the behavior you describe when using this template (minified version of your template and converted to YAML):

AWSTemplateFormatVersion: 2010-09-09
Parameters:
  WebFileSystemSubnet1:
    Type: String
  WebFileSystemSecurityGroup:
    Type: String
  OptionalExistingEFSDrive:
    Type: String
Conditions:
  CreateEFSDrive: !Equals 
    - !Ref OptionalExistingEFSDrive
    - ''
Resources:
  WebFileSystem:
    Type: 'AWS::EFS::FileSystem'
    Condition: CreateEFSDrive
    DeletionPolicy: Retain
    Properties:
      FileSystemTags:
        - Key: Name
          Value: WebFileSystem
      PerformanceMode: generalPurpose
  WebFileSystemMountTarget1:
    Type: 'AWS::EFS::MountTarget'
    Properties:
      SubnetId: !Ref WebFileSystemSubnet1
      SecurityGroups:
        - !Ref WebFileSystemSecurityGroup
      FileSystemId: !If 
        - CreateEFSDrive
        - !Ref WebFileSystem
        - !Ref OptionalExistingEFSDrive

So when I use this template and pass in an existing file system id, only the mount target is created, as expected.

2
  • Interesting. Of course, my template is only a slice of a larger pie, so it could be that something is getting set incorrectly, but the fact that the mount targets are attached correctly is slightly frustrating. Aug 18, 2017 at 20:15
  • 1
    Are you sure you are passing in the optionalExistingEFSDrive param and not relying on the default value "" by accident?
    – Jukka
    Aug 18, 2017 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .