Skip to content

Commit

Permalink
Merge pull request #5 from jcouyang/cond-fn
Browse files Browse the repository at this point in the history
add Condition functions
  • Loading branch information
jcouyang authored Apr 4, 2022
2 parents 671bc78 + ae63f73 commit 63e70dd
Show file tree
Hide file tree
Showing 1,965 changed files with 12,274 additions and 360 deletions.
93 changes: 93 additions & 0 deletions Fn.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ let _Pi =
, Select : Natural Fn Fn
, FindInMap : Fn Fn Fn
, Transform : Text Map.Type Text Fn Fn
, Condition : Text Fn
, Equals : Fn Fn Fn
, And : Fn Fn Fn
, If : Text Fn Fn Fn
, Not : Fn Fn
, Or : Fn Fn Fn
}

let Fn/Type
Expand Down Expand Up @@ -112,6 +118,41 @@ let Transform =
name
(Map.map Text Fn/Type Fn (λ(x : Fn/Type) x Fn fn) param)

let Condition
: (name : Text) Fn/Type
= λ(x : Text) λ(Fn : Type) λ(fn : _Pi Fn) fn.Condition x

let Equals =
λ(a : Fn/Type)
λ(b : Fn/Type)
λ(Fn : Type)
λ(fn : _Pi Fn)
fn.Equals (a Fn fn) (b Fn fn)

let And =
λ(a : Fn/Type)
λ(b : Fn/Type)
λ(Fn : Type)
λ(fn : _Pi Fn)
fn.And (a Fn fn) (b Fn fn)

let If =
λ(cond : Text)
λ(a : Fn/Type)
λ(b : Fn/Type)
λ(Fn : Type)
λ(fn : _Pi Fn)
fn.If cond (a Fn fn) (b Fn fn)

let Not = λ(a : Fn/Type) λ(Fn : Type) λ(fn : _Pi Fn) fn.Not (a Fn fn)

let Or =
λ(a : Fn/Type)
λ(b : Fn/Type)
λ(Fn : Type)
λ(fn : _Pi Fn)
fn.Or (a Fn fn) (b Fn fn)

let toJSON =
λ(x : Fn/Type)
x
Expand Down Expand Up @@ -182,6 +223,29 @@ let toJSON =
)
}
)
, Condition =
λ(x : Text) JSON.object (toMap { Condition = JSON.string x })
, Equals =
λ(a : JSON.Type)
λ(b : JSON.Type)
JSON.object (toMap { `Fn::Equals` = JSON.array [ a, b ] })
, And =
λ(a : JSON.Type)
λ(b : JSON.Type)
JSON.object (toMap { `Fn::And` = JSON.array [ a, b ] })
, If =
λ(cname : Text)
λ(a : JSON.Type)
λ(b : JSON.Type)
JSON.object
(toMap { `Fn::If` = JSON.array [ JSON.string cname, a, b ] })
, Not =
λ(a : JSON.Type)
JSON.object (toMap { `Fn::Not` = JSON.array [ a ] })
, Or =
λ(a : JSON.Type)
λ(b : JSON.Type)
JSON.object (toMap { `Fn::Or` = JSON.array [ a, b ] })
}

let exampleImportValue =
Expand Down Expand Up @@ -328,6 +392,29 @@ let exampleTransform =
}
''

let exampleCondition =
assert
: JSON.render
( toJSON
( Or
(Equals (Ref (String "EnvironmentType")) (String "prod"))
(Condition "CreateProdResource")
)
)
''
{
"Fn::Or": [
{
"Fn::Equals": [
{ "Ref": "EnvironmentType" },
"prod"
]
},
{ "Condition": "CreateProdResource" }
]
}
''

in { Ref
, Base64
, Cidr
Expand All @@ -342,6 +429,12 @@ in { Ref
, GetAZs
, Join
, Select
, Condition
, Equals
, If
, Not
, And
, Or
, Type = Fn/Type
, CfnText = JSON.Type
, render = toJSON
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ generates
The following intrinsic functions are implemented, you can find examples of using intrinsic function in [Fn.dhall document](https://oyanglul.us/dhall-aws-cloudformation/Fn.dhall.html)
- [x] Fn::Base64
- [x] Fn::Cidr
- [ ] Condition functions
- [x] Condition functions
- [x] Fn::FindInMap
- [x] Fn::GetAtt
- [x] Fn::GetAZs
Expand Down
2 changes: 2 additions & 0 deletions cloudformation/AWS::ACMPCA::Certificate.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cloudformation/AWS::ACMPCA::Certificate/CustomAttribute.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cloudformation/AWS::ACMPCA::Certificate/CustomExtension.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cloudformation/AWS::ACMPCA::Certificate/Extensions.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cloudformation/AWS::ACMPCA::Certificate/Resources.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cloudformation/AWS::ACMPCA::Certificate/Subject.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cloudformation/AWS::ACMPCA::CertificateAuthority.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cloudformation/AWS::ACMPCA::Permission.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cloudformation/AWS::ACMPCA::Permission/Properties.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions cloudformation/AWS::ACMPCA::Permission/Resources.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cloudformation/AWS::APS::RuleGroupsNamespace.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cloudformation/AWS::APS::RuleGroupsNamespace/Properties.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions cloudformation/AWS::APS::RuleGroupsNamespace/Resources.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cloudformation/AWS::APS::Workspace.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cloudformation/AWS::APS::Workspace/Properties.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions cloudformation/AWS::APS::Workspace/Resources.dhall

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 63e70dd

Please sign in to comment.