1

I am trying to add a condition to the ManagedPolicyArns based on the environment, it has to run a specify policy

Here's my code:

Conditions:
      IsEnvProd: Fn::Equals [!Ref Env, 'prod']

 ManagedPolicyArns:
        - Fn::If:
           - IsEnvProd:
             - "arn:aws:iam::111111111111:policy/prod_policy"
             - "arn:aws:iam::111111111111:policy/stage_policy"

Getting the following error: ValidateTemplate operation: Template error: Fn::If requires a list argument with three elements

rk123
  • 85
  • 2
  • 12

2 Answers2

3

Try this:

Conditions:
      IsEnvProd: Fn::Equals [!Ref Env, 'prod']

 ManagedPolicyArns:
        - Fn::If:
           - IsEnvProd
           - "arn:aws:iam::111111111111:policy/prod_policy"
           - "arn:aws:iam::111111111111:policy/stage_policy"

Fn::If takes three parameters. The first one is the condition name, the second is the value if true, and the third is the value if false. You passed a map instead.

kichik
  • 33,220
  • 7
  • 94
  • 114
0

Ok that makes sense , thank you:

But I keep getting this error now:

Template format error: Conditions can only be boolean operations on parameters and other conditions
rk123
  • 85
  • 2
  • 12