RDS | DBSubnetGroup should be able to take SubnetIds as ParameterRef
See original GitHub issueCurrently, DBSubnetGroup expects users to pass in SubnetIds as Seq of ResourceRefs and hence does not support ParameterRef.
I attempted to make code changes to allow for this, but it seems like it’s hard to do this without breaking backward compatibility. The main issue is that the output JSON in case of ParameterRef needs to be like:
"SubnetIds": {"Ref": "subnets"}
instead of the usual (when subnets are passed as Seq of ResourceRef):
SubnetIds": [
{"Ref": "subnet1"},
{"Ref": "subnet2",
]
Here is what I tried:
-
Create a new AWS::EC2::Subnet_Parameter_List type that has AWS Type as ListAWS::EC2::Subnet::Id and Rep = Seq[
AWS::EC2::Subnet
]. -
Change the type of SubnetIds to Seq[Token[ResourceRef[
AWS::EC2::Subnet
]]] but this results in incorrect json.SubnetIds": [ {"Ref": "subnets"} ]
-
Change the type of SubnetIds to Token[Seq[ResourceRef[
AWS::EC2::Subnet
]]] but the implicit conversion from Resource to ResourceRef does not kick in (Token[Seq[Resource]] does not implicit convert to Token[Seq[ResourceRef]]). -
Introduce a new ResourcesRef type like:
case class ResourcesRef[R <: Resource[R]](rs: Seq[R]) { val arguments = rs.map(r => ResourceRef(r)) def serializeArguments = arguments.toJson } object ResourcesRef extends DefaultJsonProtocol { implicit def fromResourceRefs[R <: Resource[R]](rs: Seq[ResourceRef[R]]): ResourcesRef[R] = ResourcesRef(rs.map(_.r)) implicit def fromParameterRef[R <: Resource[R]](parameterRef: ParameterRef[Seq[R]]): ResourcesRef[R] = { ??? } implicit def format[R <: Resource[R]]: JsonFormat[ResourcesRef[R]] = new JsonFormat[ResourcesRef[R]] { def write(obj: ResourcesRef[R]) = obj.serializeArguments //TODO: Implement Readers, but this is necessary to get Seq[T] JsonFormat for ResourceRef's def read(json: JsValue) = ??? } }
but as you can see, I can’t figure out how to convert ParameterRef to ResourcesRef.
Any guidance on this will be much appreciated.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top GitHub Comments
I’ve got a few things going on right now but I’ll try and see if I can come up with something to help.
I took a fresh attempt while creating a test branch for you and ended up solving it 😃. PR submitted - https://github.com/MonsantoCo/cloudformation-template-generator/pull/84