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

Add schema support for cosmos db #4780

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/azd/internal/cmd/add/add_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Metadata(r *project.ResourceConfig) resourceMeta {
case project.ResourceTypeDbCosmos:
res.AzureResourceType = "Microsoft.DocumentDB/databaseAccounts"
res.UseEnvVars = []string{
"AZURE_COSMOSDB_ENDPOINT",
"AZURE_COSMOS_ENDPOINT",
}
case project.ResourceTypeMessagingEventHubs:
res.AzureResourceType = "Microsoft.EventHub/namespaces"
Expand Down
3 changes: 3 additions & 0 deletions cli/azd/internal/scaffold/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func TestExecInfra(t *testing.T) {
DbCosmosMongo: &DatabaseCosmosMongo{
DatabaseName: "appdb",
},
DbCosmos: &DatabaseCosmos{
DatabaseName: "cosmos",
},
DbRedis: &DatabaseRedis{},
ServiceBus: &ServiceBus{},
EventHubs: &EventHubs{},
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/pkg/project/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ type CosmosDBProps struct {
}

type CosmosDBContainerProps struct {
ContainerName string `yaml:"containerName,omitempty"`
PartitionKeyPaths []string `yaml:"partitionKeyPaths,omitempty"`
Name string `yaml:"containerName,omitempty"`
PartitionKeys []string `yaml:"partitionKeyPaths,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the YAML schema, does name and partitionKeys feel nicer?

}

type ServiceBusProps struct {
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/pkg/project/scaffold_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func infraSpec(projectConfig *ProjectConfig) (*scaffold.InfraSpec, error) {
containers := make([]scaffold.CosmosSqlDatabaseContainer, 0)
for _, c := range props.Containers {
containers = append(containers, scaffold.CosmosSqlDatabaseContainer{
ContainerName: c.ContainerName,
PartitionKeyPaths: c.PartitionKeyPaths,
ContainerName: c.Name,
PartitionKeyPaths: c.PartitionKeys,
})
}
infraSpec.DbCosmos = &scaffold.DatabaseCosmos{
Expand Down
4 changes: 3 additions & 1 deletion cli/azd/resources/scaffold/templates/resources.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ module cosmos 'br/public:avm/res/document-db/database-account:0.8.1' = {
{{- range .Services}}
{{bicepName .Name}}Identity.outputs.principalId
{{- end}}
weikanglim marked this conversation as resolved.
Show resolved Hide resolved
principalId
]
sqlRoleDefinitions: [
{
name: 'service-access-cosmos-sql-role'
}
]
capabilitiesToAdd: [ 'EnableServerless' ]
}
}
{{- end}}
Expand Down Expand Up @@ -459,7 +461,7 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
{{- end}}
{{- if .DbCosmos}}
{
name: 'AZURE_COSMOSDB_ENDPOINT'
name: 'AZURE_COSMOS_ENDPOINT'
value: cosmos.outputs.endpoint
}
{{- end}}
Expand Down
Loading