question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RDS | DBSubnetGroup should be able to take SubnetIds as ParameterRef

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
tjcorrcommented, 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.

0reactions
aniketbhatnagarcommented, Apr 8, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS::RDS::DBSubnetGroup - AWS CloudFormation
The AWS::RDS::DBSubnetGroup resource creates a database subnet group. Subnet groups must contain at least two subnets in two different Availability Zones in ...
Read more >
troposphere/RDS_VPC.py at main · cloudtools ... - GitHub
troposphere - Python library to create AWS CloudFormation descriptions - troposphere/RDS_VPC.py at main · cloudtools/troposphere.
Read more >
create-db-subnet-group — AWS CLI 2.9.6 Command Reference
Description¶. Creates a new DB subnet group. DB subnet groups must contain at least one subnet in at least two AZs in the...
Read more >
aws.rds.SubnetGroup - Pulumi
A list of VPC subnet IDs. description string. The description of the DB subnet group. Defaults to "Managed by Pulumi".
Read more >
AWS Cloudformation Value of property SubnetIds must be of ...
You should have a space between - and the intrinsic function !Ref in order to be parsed correctly. Sadly, CloudFormation detects this only ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found