Esempio n. 1
0
    def test_validateThroughputMode(self):
        with self.assertRaises(ValueError):
            file_system = efs.FileSystem(
                "Efs", ThroughputMode="UndefinedThroughputMode")
            file_system.to_dict()

        file_system = efs.FileSystem("Efs", ThroughputMode=efs.Bursting)

        result = file_system.to_dict()
        self.assertEqual(result["Type"], "AWS::EFS::FileSystem")
Esempio n. 2
0
    def test_validateProvisionedThroughputInMibps(self):
        with self.assertRaises(TypeError):
            file_system = efs.FileSystem("Efs",
                                         ProvisionedThroughputInMibps="512")
            file_system.to_dict()

        with self.assertRaises(TypeError):
            file_system = efs.FileSystem("Efs",
                                         ProvisionedThroughputInMibps=512)
            file_system.to_dict()

        file_system = efs.FileSystem("Efs", ProvisionedThroughputInMibps=512.0)

        result = file_system.to_dict()
        self.assertEqual(result["Type"], "AWS::EFS::FileSystem")
Esempio n. 3
0
    def add_resources(self):

        t = self.template

        self.FileSystem = t.add_resource(
            efs.FileSystem("FileSystem",
                           PerformanceMode=Ref(self.PerformanceMode),
                           FileSystemTags=Tags(
                               Name=Join("-", [Ref(self.Project), "efs"]),
                               Environment=Ref(self.Environment),
                               Project=Ref(self.Project),
                           )))

        self.MountTarget1 = t.add_resource(
            efs.MountTarget(
                "MountTarget1",
                SubnetId=Ref(self.Subnet1),
                FileSystemId=Ref(self.FileSystem),
                SecurityGroups=[Ref(self.EfsSecurityGroup)],
            ))

        self.MountTarget2 = t.add_resource(
            efs.MountTarget(
                "MountTarget2",
                SubnetId=Ref(self.Subnet2),
                FileSystemId=Ref(self.FileSystem),
                SecurityGroups=[Ref(self.EfsSecurityGroup)],
            ))
Esempio n. 4
0
    def create_efs_filesystem(self):
        t = self.template
        v = self.get_variables()

        fs = t.add_resource(
            efs.FileSystem('EfsFileSystem',
                           FileSystemTags=Tags(v['Tags']),
                           PerformanceMode=v['PerformanceMode']))

        t.add_output(Output('EfsFileSystemId', Value=Ref(fs)))

        return fs
Esempio n. 5
0
    def test_validateProvisionedThroughputInMibps(self):
        result = efs.FileSystem("Efs", ProvisionedThroughputInMibps=512.0).to_dict()
        self.assertEqual(result["Type"], "AWS::EFS::FileSystem")

        efs.FileSystem("Efs", ProvisionedThroughputInMibps=512).to_dict()
        efs.FileSystem("Efs", ProvisionedThroughputInMibps=512.0).to_dict()

        with self.assertRaises(TypeError):
            efs.FileSystem("Efs", ProvisionedThroughputInMibps="512").to_dict()
        with self.assertRaises(ValueError):
            efs.FileSystem("Efs", ProvisionedThroughputInMibps=-512.0).to_dict()
        with self.assertRaises(ValueError):
            efs.FileSystem("Efs", ProvisionedThroughputInMibps=-512).to_dict()
Esempio n. 6
0
def EFS_FileStorage(key):
    for n, v in getattr(cfg, key).items():
        resname = f"{key}{n}"  # Ex. EFSFileSystemWordPress
        sgservername = f"SecurityGroupEFSServer{n}"
        sgclientname = f"SecurityGroupEFS{n}"
        sginame = f"SecurityGroupIngressEFS{n}"
        for i in range(cfg.AZones["MAX"]):
            mountname = f"EFSMountTarget{n}{i}"
            # conditions
            add_obj({
                mountname:
                And(
                    Condition(resname),
                    Equals(
                        FindInMap("AvabilityZones", Ref("AWS::Region"),
                                  f"Zone{i}"),
                        "True",
                    ),
                )
            })

            # resources
            r_Mount = EFSMountTarget(mountname,
                                     index=i,
                                     sgname=sgservername,
                                     efsresname=resname)

            add_obj(r_Mount)
        # conditions
        add_obj(get_condition(resname, "equals", "yes", f"{resname}Enabled"))

        # resources
        r_File = efs.FileSystem(resname)
        auto_get_props(r_File, indexname=n)

        r_SGServer = SecurityGroup(
            sgservername,
            Condition=resname,
            GroupDescription=f"Rule to access EFS FileSystem {n}",
        )

        r_SGClient = SecurityGroup(
            sgclientname,
            Condition=resname,
            GroupDescription=f"Enable access to EFS FileSystem {n}",
        )

        SGIExtra = {
            "Name": sginame,
            "Condition": resname,
            "FromPort": 2049,
            "GroupId": "Sub('${%s.GroupId}')" % sgservername,
            "SourceSecurityGroupId": "Ref('%s')" % sgclientname,
            "ToPort": 2049,
        }

        r_SGI = SecurityGroupIngress(sginame)
        auto_get_props(r_SGI, rootdict=SGIExtra)

        # outputs
        o_SGClient = Output(
            sgclientname,
            Condition=resname,
            Value=GetAtt(sgclientname, "GroupId"),
            Export=Export(sgclientname),
        )

        add_obj([r_File, r_SGServer, r_SGClient, r_SGI, o_SGClient])
Esempio n. 7
0
 def test_bucket_template(self):
     template = Template()
     title = "Efs"
     efs.FileSystem(title, template)
     self.assertIn(title, template.resources)
Esempio n. 8
0
 def test_validData(self):
     file_system = efs.FileSystem("Efs")
     file_system.to_dict()
Esempio n. 9
0
    Equals(Ref(param_encrypted), 'true'),
)

t.add_condition('DefaultKmsCondition', Equals(Ref(param_kms_key), ''))
t.add_condition('CreateSecurityGroupCondition', Equals(Ref(param_sg), ''))

#
# Resources
#

file_system = t.add_resource(
    efs.FileSystem(
        'FileSystem',
        Encrypted=Ref(param_encrypted),
        KmsKeyId=If(
            'StorageEncryptedCondition',
            If('DefaultKmsCondition', Ref(AWS_NO_VALUE), Ref(param_kms_key)),
            Ref(AWS_NO_VALUE),
        ),
        PerformanceMode=Ref(param_performance_mode),
    ))

efs_sg = t.add_resource(
    ec2.SecurityGroup(
        'EfsSecurityGroup',
        Condition='CreateSecurityGroupCondition',
        VpcId=Ref(param_vpcid),
        GroupDescription='Enable local postgres access',
        SecurityGroupIngress=[
            ec2.SecurityGroupRule(
                IpProtocol='tcp',
                FromPort='2049',