diff --git a/src/Stratosphere/Value.hs b/src/Stratosphere/Value.hs index f10b494da..6821c88f0 100644 --- a/src/Stratosphere/Value.hs +++ b/src/Stratosphere/Value.hs @@ -100,7 +100,8 @@ mkFunc key args = JSON.object [(key, JSON.Array $ fromList args)] -- @List@ then, you can use @RefList "SubnetIds"@ to -- reference it. data ValueList a - = GetAZs (Value Text) + = Cidr (Value Text) (Value Text) (Value Text) + | GetAZs (Value Text) | ImportValueList (Value Text) | RefList Text | Split Text (Value a) @@ -112,6 +113,7 @@ instance IsList (ValueList a) where fromList = ValueList toList = \case + (Cidr _ _ _) -> [] (GetAZs _) -> [] (ImportValueList _) -> [] (RefList _) -> [] @@ -122,11 +124,20 @@ instance IsList (ValueList a) where instance JSON.ToJSON a => JSON.ToJSON (ValueList a) where toJSON = \case - (GetAZs r) -> JSON.object [("Fn::GetAZs", JSON.toJSON r)] - (ImportValueList ref) -> importValueToJSON ref - (RefList ref) -> refToJSON ref - (Split d s) -> mkFunc "Fn::Split" [JSON.toJSON d, JSON.toJSON s] - (ValueList vals) -> JSON.toJSON vals + (Cidr ipBlock count cidrBits) -> JSON.object [("Fn::Cidr", cidrArray ipBlock count cidrBits)] + (GetAZs r) -> JSON.object [("Fn::GetAZs", JSON.toJSON r)] + (ImportValueList ref) -> importValueToJSON ref + (RefList ref) -> refToJSON ref + (Split d s) -> mkFunc "Fn::Split" [JSON.toJSON d, JSON.toJSON s] + (ValueList vals) -> JSON.toJSON vals + where + cidrArray :: Value Text -> Value Text -> Value Text -> JSON.Value + cidrArray ipBlock count cidrBits + = JSON.Array + [ JSON.toJSON ipBlock + , JSON.toJSON count + , JSON.toJSON cidrBits + ] -- | Class used to create a 'Ref' from another type. class ToRef a b where diff --git a/test/Stratosphere/ValuesSpec.hs b/test/Stratosphere/ValuesSpec.hs index c58ca1551..0bcd257c7 100644 --- a/test/Stratosphere/ValuesSpec.hs +++ b/test/Stratosphere/ValuesSpec.hs @@ -17,3 +17,6 @@ spec = do it "ImportValue and ImportValueList produce the same JSON" $ do JSON.toJSON (ImportValue "MyVal" :: Value Text) `shouldBe` JSON.toJSON (ImportValueList "MyVal" :: ValueList Text) + + it "Cidr produces expected JSON" $ do + JSON.toJSON @(ValueList Text) (Cidr "192.168.0.0/24" "6" "5") `shouldBe` JSON.object [("Fn::Cidr", JSON.Array ["192.168.0.0/24", "6", "5"])]