Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.65k stars 844 forks source link

Communicate with the CosmosDB emulator #15275

Closed anttikes closed 3 years ago

anttikes commented 3 years ago

Feature Request

Microsoft provides a CosmosDB emulator, and it is possible to talk to this emulator with the .NET Azure SDK. The page even has samples on how to do it.

In the Azure SDK for Go, it seems that the Azure subscription identifier is a mandatory part for creating a database client. The CosmosDB emulator does not seem to have such a concept, only a hard-coded account name (localhost & port number) and the hard-coded primary key.

Is it possible to use the Azure SDK for Go to talk to the CosmosDB emulator? If so, how to accomplish it?

My final goal is (a probably futile attempt) to create a Terraform provider that is capable of reading the database & container configs from a HCL file intended for Azure deployment, and allow creating similar resources into the CosmosDB emulator. Using either the Azure SDK for Go, or the REST API of the emulator directly seem to be the alternatives.

Writing a HCL parser in any other language than Go adds a dependency that must be maintained and monitored, and the idea of this tool is to be as maintenance-free as possible. I am also aware of the CosmosDB free tier account, and the possibility of defining the CosmosDB resources in a JSON file instead of a HCL file, so they could be read by a C# application. These are also potential options.

anttikes commented 3 years ago

As an update to the matter, our team decided to put the CosmosDB resource definitions into a JSON file. So, fixing this issue is no longer any priority for us. But perhaps other Golang users might be interested in getting this feature?

ealsur commented 3 years ago

@anttikes @RickWinter This issue is for the ARM client, not the Data Plane SDK, I am not aware who owns or manages it.

The Data Plane SDK can work with the Emulator just fine, in fact, we do it in our pipeline CI: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/data/azcosmos/emulator_cosmos_item_test.go, it's just a matter of using the Emulator endpoint and key instead of the real account's endpoint and key, no difference for the Data Plane SDK.

anttikes commented 3 years ago

So, the error was that I just couldn't understand Golang sufficiently in order to determine how to construct a CosmosClient instance that communicates with an endpoint using predefined account and name and shared key.

Thanks @ealsur for the clarifying comment.