AWS Cloudformation create resource conditionally

Viewed 11471

I was looking at the Condition Function Fn::If: to create or provision a resource only if a condition is evaluated to true. In my case, created a policy if the environment is prod.

Parameters:
  Env:
    Description: Environment
    Type: String

Conditions:
  IsProd: !Equals [!Ref Env, 'prod']

I know how to do it for a property, but not for the entire resource block.

Type: 'AWS::IAM::Policy'
Properties:
  PolicyName: root
  PolicyDocument:
    Version: 2012-10-17
    Statement:
      - Effect: Allow
        Action: '*'
        Resource: '*'
  Roles:
    - !Ref RootRole

Is this something possible?

1 Answers
Related