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

adds support for tables and queue - aspire #2998

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions cli/azd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features Added

- [[2998]](https://github.com/Azure/azure-dev/pull/2998) Adds support for Azure Storage Tables and Queues on Aspire projects.

### Breaking Changes

### Bugs Fixed
Expand Down
27 changes: 23 additions & 4 deletions cli/azd/pkg/apphost/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ func (b *infraGenerator) LoadManifest(m *Manifest) error {
case "azure.storage.v0":
b.addStorageAccount(name)
case "azure.storage.blob.v0":
b.addStorageBlobContainer(*comp.Parent, name)
b.addStorageBlob(*comp.Parent, name)
case "azure.storage.queue.v0":
b.addStorageQueue(*comp.Parent, name)
case "azure.storage.table.v0":
b.addStorageTable(*comp.Parent, name)
case "postgres.server.v0":
// We currently use a ACA Postgres Service per database. Because of this, we don't need to retain any
// information from the server resource.
Expand Down Expand Up @@ -320,13 +324,25 @@ func (b *infraGenerator) addKeyVault(name string) {
b.bicepContext.KeyVaults[name] = genKeyVault{}
}

func (b *infraGenerator) addStorageBlobContainer(storageAccount, containerName string) {
func (b *infraGenerator) addStorageBlob(storageAccount, blobName string) {
// TODO(ellismg): We have to handle the case where we may visit the blob resource before the storage account resource.
// But this implementation means that if the parent storage account is not in the manifest, we will not detect that
// as an error. We probably should.

account := b.bicepContext.StorageAccounts[storageAccount]
account.Containers = append(account.Containers, containerName)
account.Blobs = append(account.Blobs, blobName)
b.bicepContext.StorageAccounts[storageAccount] = account
}

func (b *infraGenerator) addStorageQueue(storageAccount, queueName string) {
account := b.bicepContext.StorageAccounts[storageAccount]
account.Queues = append(account.Queues, queueName)
b.bicepContext.StorageAccounts[storageAccount] = account
}

func (b *infraGenerator) addStorageTable(storageAccount, tableName string) {
account := b.bicepContext.StorageAccounts[storageAccount]
account.Tables = append(account.Tables, tableName)
b.bicepContext.StorageAccounts[storageAccount] = account
}

Expand Down Expand Up @@ -546,7 +562,10 @@ func (b *infraGenerator) Compile() error {
default:
return errUnsupportedProperty(targetType, prop)
}
case targetType == "azure.keyvault.v0" || targetType == "azure.storage.blob.v0":
case targetType == "azure.keyvault.v0" ||
targetType == "azure.storage.blob.v0" ||
targetType == "azure.storage.queue.v0" ||
targetType == "azure.storage.table.v0":
switch prop {
case "connectionString":
projectTemplateCtx.Env[k] = fmt.Sprintf(
Expand Down
4 changes: 3 additions & 1 deletion cli/azd/pkg/apphost/generate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package apphost
type genAppInsight struct{}

type genStorageAccount struct {
Containers []string
Blobs []string
Tables []string
Queues []string
}

type genServiceBus struct {
Expand Down
8 changes: 7 additions & 1 deletion cli/azd/resources/apphost/templates/main.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ output SERVICE_BINDING_{{alphaSnakeUpper $name}}_ENDPOINT string = resources.out
output SERVICE_BINDING_{{alphaSnakeUpper $name}}_CONNECTION_STRING string = resources.outputs.SERVICE_BINDING_{{alphaSnakeUpper $name}}_CONNECTION_STRING
{{end -}}
{{range $name, $value := .StorageAccounts -}}
{{range $cname := $value.Containers -}}
{{range $cname := $value.Blobs -}}
output SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT string = resources.outputs.SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT
{{end -}}
{{range $cname := $value.Tables -}}
output SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT string = resources.outputs.SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT
{{end -}}
{{range $cname := $value.Queues -}}
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
output SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT string = resources.outputs.SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT
{{end -}}
{{end -}}
Expand Down
37 changes: 35 additions & 2 deletions cli/azd/resources/apphost/templates/resources.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ resource {{bicepName $name}} 'Microsoft.Storage/storageAccounts@2022-05-01' = {
}
}

resource {{bicepName $name}}RoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
{{if gt (len $value.Blobs) 0 -}}
resource {{bicepName $name}}BlobsRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid({{bicepName $name}}.id, managedIdentity.id, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'))
scope: {{bicepName $name}}
properties: {
Expand All @@ -182,6 +183,32 @@ resource {{bicepName $name}}RoleAssignment 'Microsoft.Authorization/roleAssignme
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')
}
}
{{end -}}

{{if gt (len $value.Queues) 0 -}}
resource {{bicepName $name}}QueuesRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid({{bicepName $name}}.id, managedIdentity.id, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '974c5e8b-45b9-4653-ba55-5f855dd0fb88'))
scope: {{bicepName $name}}
properties: {
principalId: managedIdentity.properties.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '974c5e8b-45b9-4653-ba55-5f855dd0fb88')
}
}
{{end -}}

{{if gt (len $value.Tables) 0 -}}
resource {{bicepName $name}}TablesRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid({{bicepName $name}}.id, managedIdentity.id, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3'))
scope: {{bicepName $name}}
properties: {
principalId: managedIdentity.properties.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3')
}
}
{{end -}}

{{end -}}
{{range $name, $value := .KeyVaults}}
resource {{bicepName $name}} 'Microsoft.KeyVault/vaults@2023-07-01' = {
Expand Down Expand Up @@ -225,9 +252,15 @@ output SERVICE_BINDING_{{alphaSnakeUpper $name}}_ENDPOINT string = {{bicepName $
output SERVICE_BINDING_{{alphaSnakeUpper $name}}_CONNECTION_STRING string = {{bicepName $name}}.properties.ConnectionString
{{end -}}
{{range $name, $value := .StorageAccounts -}}
{{range $cname := $value.Containers -}}
{{range $cname := $value.Blobs -}}
output SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT string = {{bicepName $name}}.properties.primaryEndpoints.blob
{{end -}}
{{range $cname := $value.Tables -}}
output SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT string = {{bicepName $name}}.properties.primaryEndpoints.table
{{end -}}
{{range $cname := $value.Queues -}}
output SERVICE_BINDING_{{alphaSnakeUpper $cname}}_ENDPOINT string = {{bicepName $name}}.properties.primaryEndpoints.queue
{{end -}}
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
{{end -}}
{{range $name, $value := .KeyVaults -}}
output SERVICE_BINDING_{{alphaSnakeUpper $name}}_ENDPOINT string = {{bicepName $name}}.properties.vaultUri
Expand Down