Associating Resource Group to a Service

I am trying to associate a resource group to the service programatically.

I am creating a resource specification which has a reference to my resource group. I am pointing this resource specification to the service.The associations are made successfully , but inspite of resource group getting added to the service , only the resource present in the resource group gets added.

Please help to overcome this using some sample code.