Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDS | DBSubnetGroup should be able to take SubnetIds as ParameterRef #81

Closed
aniketbhatnagar opened this issue Apr 4, 2016 · 5 comments

Comments

@aniketbhatnagar
Copy link

Currently, 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:

  1. Create a new AWS::EC2::Subnet_Parameter_List type that has AWS Type as ListAWS::EC2::Subnet::Id and Rep = Seq[AWS::EC2::Subnet].

  2. Change the type of SubnetIds to Seq[Token[ResourceRef[AWS::EC2::Subnet]]] but this results in incorrect json.
    SubnetIds": [ {"Ref": "subnets"} ]

  3. 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]]).

  4. 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.

@tjcorr
Copy link
Collaborator

tjcorr commented Apr 4, 2016

Can you help me understand why you would want to explicitly set the DBSubnetGroup as a parameter? If you wanted to be composing on top of an existing template I think you could use the pattern described at: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-cross-stack-ref.html . I'll work with the team here though and see if we can come up with any other ideas though.

@aniketbhatnagar
Copy link
Author

Here is why I need it - Our ops have created the subnets by hand in the VPC. Therefore, when launching resources using cloud formation, we need to ability for ops to select which subnet or subnets should the resources be deployed to. We cannot create subnets in the CF but can create a DBSubnetGroup that points to existing subnets. Therefore, its not the DBSubnetGroup that needs to be parameterized but the SubnetIds, that are part of DBSubnetGroup, need to be.

Similarly, I have submitted a PR #80 that allow for specifying VPC as parameter. Since, having the subnets parameterized doesn't seem like trivial for the API to support, the PR also contains a small change to allow for parameterizing DBSubnetGroup as a workaround. However, ideally, I would like SubnetIds to be parameterized (instead of DBSubnetGroup) and hence, this issue.

@tjcorr
Copy link
Collaborator

tjcorr commented Apr 5, 2016

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.

@tjcorr
Copy link
Collaborator

tjcorr commented Apr 6, 2016

Do you have any test code I could work against?

@aniketbhatnagar
Copy link
Author

I took a fresh attempt while creating a test branch for you and ended up solving it :-). PR submitted - #84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants