简体   繁体   English

CloudFormation 是否可以跨嵌套堆栈共享条件定义?

[英]Is it possible in CloudFormation to share Conditions definition across nested stack?

Let's say I want to declare several conditions that are, actually, can be used across nested resources (in CloudFormation).假设我要声明几个条件,这些条件实际上可以跨嵌套资源(在 CloudFormation 中)使用。 Here is a very simple example:这是一个非常简单的例子:

Parameters:
  EnvType:
    Type: String
    Description: Environment type.
    Default: test
    AllowedValues: [test, dev]
    ConstraintDescription : Must specify test or dev.

Conditions:
  CreateTestEnvResources: !Equals [!Ref EnvType, test]
  CreateDevEnvResources: !Equals [!Ref EnvType, dev]

Is it possible somehow to pass through this declaration across nested stack resources ( AWS::CloudFormation::Stack )?是否有可能以某种方式跨嵌套堆栈资源( AWS::CloudFormation::Stack )传递此声明? Or the only way is to use EnvType and make declaration in every Stack?还是唯一的方法是使用EnvType并在每个堆栈中进行声明?

Or the only way is to use EnvType and make declaration in every Stack?还是唯一的方法是使用 EnvType 并在每个堆栈中进行声明?

Sadly, this is the only way.可悲的是,这是唯一的方法。 But if you really would like to eliminate this step, you could possibly develop a macro in CloudFormation for that.但是,如果您真的想消除这一步,您可以在 CloudFormation 中为此开发一个 Nevertheless, the re-declaration of EnvType in each nested stack is still the most readable and easiest to debug and implement way.尽管如此,在每个嵌套堆栈中重新声明EnvType仍然是最易读和最容易调试和实现的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM