阅读背景:

如何知道通过Cloudformation创建的Mount目标数量

来源:互联网 

I create by cloudformation an EFS in a VPC, this VPC contains few EC2 instances.

我通过cloudformation在VPC中创建了一个EFS,这个VPC包含很少的EC2实例。

I need to create as well mount targets for each subnet.

我需要为每个子网创建安装目标。

This cloudformation template can be executed in different AWS accounts. How to know how meny Mount targets resources to create?

此云信息模板可以在不同的AWS账户中执行。如何知道Meny如何创建目标资源?

I can have a vpc in account 1 with 3 subnets, another vpc in account 2 with 2 subnets...

我可以在帐户1中拥有一个带有3个子网的vpc,另一个带有2个子网的帐户2中的vpc ...

How to make the template generic so that it's going according to every account environment ?

如何使模板通用,以便它根据每个帐户环境进行?

 "FileSystem" : {
       "Type" : "AWS::EFS::FileSystem",
       "Properties" : {
         "FileSystemTags" : [
           {
             "Key" : "Name",
             "Value" : "FileSystem"
           }
         ]
       }
     },

     "MountTarget1": {
       "Type": "AWS::EFS::MountTarget",
       "Properties": {
         "FileSystemId": { "Ref": "FileSystem" },
         "SubnetId": { "Ref": "Subnet1" },
         "SecurityGroups": [ { "Ref": "MountTargetSecurityGroup" } ]
       }
     },

     "MountTarget2": {
       "Type": "AWS::EFS::MountTarget",
       "Properties": {
         "FileSystemId": { "Ref": "FileSystem" },
         "SubnetId": { "Ref": "Subnet2" },
         "SecurityGroups": [ { "Ref": "MountTargetSecurityGroup" } ]
       }
     },

1 个解决方案

#1


0  

As I understand, you want to be able to re-use this same template across accounts and create the appropriate number of MountTargets based on the number of subnets required by an account.

据我了解,您希望能够跨帐户重复使用相同的模板,并根据帐户所需的子网数创建适当数量的MountTargets。

There are many variables and conditions that would apply depending on the number of subnets (ACL, Routetables, etc). You could perhaps accomplish it with a large number of conditions and parameters, but the template would get quite messy. Although that's not an elegant solution.

根据子网的数量(ACL,Routetables等),有许多变量和条件可供应用。您可以使用大量条件和参数来完成它,但模板会变得非常混乱。虽然这不是一个优雅的解决方案。

The better approach would be creating your template using Troposphere. Here's an example for EFS to get you started. https://github.com/cloudtools/troposphere/blob/master/examples/EFS.py

更好的方法是使用Troposphere创建模板。以下是EFS帮助您入门的示例。 https://github.com/cloudtools/troposphere/blob/master/examples/EFS.py


分享到: