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

Api consistency question #550

Open
aorlenko83 opened this issue Feb 6, 2021 · 4 comments
Open

Api consistency question #550

aorlenko83 opened this issue Feb 6, 2021 · 4 comments

Comments

@aorlenko83
Copy link

Hi, I have a question regarding the SqlAzure and WebApp api semantics.
The WebApp (AppService) should be assigned to some AppServicePlan in Azure. And so in Farmer, there is a "link_service_plan" that gives ability to attach the new appService to the appservice plan, either new or existing.
However, in AzureSql I see some different api. The individual database is added to the "parent" sql server using the "add_database" syntax inside the sqlServer builder. So if I have already existing sql server, it seems like I cannot just "attach" the sql database to this server. It looks like I always need to create the sqlServer, and add all needed databases in one script.
In general, it seems like AppservicePlan and SqlServer both have similar behavior, because they act as a "container" for the appService and sqlDatabase respectively. But the api semantics is different.
Maybe I'm just overlooking something?
In general, in the current project, I have a need to have single sql server and multiple databases assigned to it. But I cannot create all databases in once, I rather want to separately create the sqlServer, and then have separate deployment for each database. What is the best way to accomplish this?
Thanks

@isaacabraham
Copy link
Member

Yes, this is correct. We started with the approach of "everything is owned by the builder" model, but as people request the ability to extend the capabilities of each builder to have more flexibility, we can add it.

In your case, I suppose what you would like is the ability to create an arbitrary database value (that's no problem, the expression is already there) but to attach it to an already existing server (that was created outside of Farmer)? Or is this more you would like to define a server separately in Farmer and then add items to it over item?

@aorlenko83
Copy link
Author

Yeah, I think my question boils down to how would I create the database if the server already exists. Could you provide some example? Because from samples and documentation, I see all cases where the database should be created only as a child item of the sqlServer builder, via add_database.
Thanks

@isaacabraham
Copy link
Member

As I said - currently this isn't supported, you can only create a DB on an existing SQL instance. Our position initially has always been to create both server and db through Farmer, although as you point out, with the App Service people came back to us saying that they wanted to attach child resources to parents.

It wouldn't be a massive undertaking to do - probably it would be something like this:

let theServer = ResourceId.create(Arm.Sql.servers, ResourceName "my-external-sql-server", "my-resource-group")

let db = sqlDb {
    name "poolDb1"
    sku DtuSku.S1
    db_size (1024<Mb> * 128)
    attach_to_server theServer
}

I'm not sure though whether you can deploy a SQL Database to a separate resource group than the Server - probably not - so you would need to ensure that you deploy your Farmer template to the same RG that the server exists in.

@aorlenko83
Copy link
Author

I think that'd be great and it would give the most flexibility.
In general, my point is that the Api should be consistent, so that the consumers of Farmer would know what to expect. And so, if there is "link_service_plan" for app service, I'd expect to have something similar for sql database. And at the same time, if there is "add_databases" for sql server, I'd expect appServicePlan with "add_services" operation.
I'm not saying of course that all this is needed and it's redundant probably ;)
In any case, thanks for the help and your feedback!

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

No branches or pull requests

2 participants