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 .net aspire support on sql server and sql database #3226

Merged
merged 26 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7b7739d
add support on sql
hemarina Jan 25, 2024
8a06ef8
remove this case
hemarina Jan 25, 2024
635ee08
remove unwanted }}
hemarina Jan 25, 2024
3ac0428
remove
hemarina Jan 25, 2024
a387d66
debug
hemarina Jan 25, 2024
b993494
change function name and nest resources under sql/server
hemarina Jan 25, 2024
7045aaa
Merge branch 'sql' of https://github.com/hemarina/azure-dev into sql
hemarina Jan 25, 2024
42bad4e
use containerAppSecretConnectionString instead of directly output
hemarina Jan 26, 2024
c291bdf
debug
hemarina Jan 26, 2024
22b5a66
revert it
hemarina Jan 26, 2024
c289b0d
debug
hemarina Jan 26, 2024
b0cdfa1
lll
hemarina Jan 26, 2024
dbd2120
cspell
hemarina Jan 26, 2024
e8fbaf3
Merge branch 'main' of https://github.com/Azure/azure-dev into sql
hemarina Jan 26, 2024
e7f7022
add server
hemarina Jan 26, 2024
83f299e
lint
vhvb1989 Jan 26, 2024
4bb8557
Update cli/azd/pkg/project/service_target_dotnet_containerapp.go
hemarina Jan 26, 2024
99dfc33
simple the code based on feedback and merge
hemarina Jan 26, 2024
3675692
Merge branch 'sql' of https://github.com/hemarina/azure-dev into sql
hemarina Jan 26, 2024
025cb3d
remove v1 as bug fixed by aspire team
hemarina Jan 26, 2024
28eccf7
Merge branch 'main' of https://github.com/Azure/azure-dev into sql
hemarina Jan 26, 2024
dfbdf5e
run gofmt
hemarina Jan 26, 2024
70dfd87
add error check for each case in pointer
hemarina Jan 29, 2024
f81a4f1
apply nested resources
hemarina Jan 29, 2024
eed0f53
Update cli/azd/pkg/sqldb/sqldb.go
hemarina Jan 30, 2024
7fdaa09
Merge branch 'main' of https://github.com/Azure/azure-dev into sql
hemarina Jan 30, 2024
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
19 changes: 18 additions & 1 deletion cli/azd/pkg/apphost/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func newInfraGenerator() *infraGenerator {
ContainerApps: make(map[string]genContainerApp),
DaprComponents: make(map[string]genDaprComponent),
CosmosDbAccounts: make(map[string]genCosmosAccount),
SqlServers: make(map[string]genSqlServer),
},
containers: make(map[string]genContainer),
dapr: make(map[string]genDapr),
Expand Down Expand Up @@ -342,6 +343,10 @@ func (b *infraGenerator) LoadManifest(m *Manifest) error {
b.addCosmosDbAccount(name)
case "azure.cosmosdb.database.v0":
b.addCosmosDatabase(*comp.Parent, name)
case "azure.sql.v0", "sqlserver.server.v0", "sqlserver.server.v1":
b.addSqlServers(name)
case "azure.sql.database.v0", "sqlserver.database.v0", "sqlserver.database.v1":
b.addSqlDatabase(*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 All @@ -350,7 +355,7 @@ func (b *infraGenerator) LoadManifest(m *Manifest) error {
// resource type.
case "postgres.database.v0":
b.addContainerAppService(name, "postgres")
case "postgres.connection.v0", "rabbitmq.connection.v0", "azure.cosmosdb.connection.v0":
case "postgres.connection.v0", "rabbitmq.connection.v0", "azure.cosmosdb.connection.v0", "sqlserver.connection.v0":
// Only interesting thing about the connection resource is the connection string, which we handle above.

// We have the case statement here to ensure we don't error out on the resource type by treating it as an unknown
Expand Down Expand Up @@ -426,6 +431,18 @@ func (b *infraGenerator) addCosmosDatabase(cosmosDbAccount, dbName string) {
b.bicepContext.CosmosDbAccounts[cosmosDbAccount] = account
}

func (b *infraGenerator) addSqlServers(name string) {
if _, exists := b.bicepContext.SqlServers[name]; !exists {
b.bicepContext.SqlServers[name] = genSqlServer{}
}
}

func (b *infraGenerator) addSqlDatabase(sqlAccount, dbName string) {
account := b.bicepContext.SqlServers[sqlAccount]
account.Databases = append(account.Databases, dbName)
b.bicepContext.SqlServers[sqlAccount] = account
}

func (b *infraGenerator) addProject(
name string, path string, env map[string]string, bindings map[string]*Binding,
) {
Expand Down
5 changes: 5 additions & 0 deletions cli/azd/pkg/apphost/generate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ type genInput struct {
DefaultMinLength int
}

type genSqlServer struct {
Databases []string
}

type genBicepTemplateContext struct {
HasContainerRegistry bool
HasContainerEnvironment bool
Expand All @@ -101,6 +105,7 @@ type genBicepTemplateContext struct {
ContainerApps map[string]genContainerApp
DaprComponents map[string]genDaprComponent
CosmosDbAccounts map[string]genCosmosAccount
SqlServers map[string]genSqlServer
}

type genContainerAppManifestTemplateContext struct {
Expand Down
5 changes: 5 additions & 0 deletions cli/azd/resources/apphost/templates/main.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ output SERVICE_BINDING_{{alphaSnakeUpper $name}}_ENDPOINT string = resources.out
{{range $name, $value := .CosmosDbAccounts -}}
output SERVICE_BINDING_{{alphaSnakeUpper $name}}_NAME string = resources.outputs.SERVICE_BINDING_{{alphaSnakeUpper $name}}_NAME
{{end -}}
{{range $name, $value := .SqlServers -}}
{{range $cname := $value.Databases -}}
output SERVICE_BINDING_{{alphaSnakeUpper $name}}_CONNECTION_STRING string = resources.outputs.SERVICE_BINDING_{{alphaSnakeUpper $cname}}_CONNECTION_STRING
{{end -}}
{{end -}}
{{ end}}
44 changes: 44 additions & 0 deletions cli/azd/resources/apphost/templates/resources.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ resource {{bicepName $name}} 'Microsoft.DocumentDB/databaseAccounts@2023-04-15'
]
databaseAccountOfferType: 'Standard'
}
}
{{range $cname := $value.Databases}}
resource {{bicepName $cname}} 'sqlDatabases@2023-04-15' = {
name: '{{$cname}}'
Expand All @@ -337,7 +338,45 @@ resource {{bicepName $name}} 'Microsoft.DocumentDB/databaseAccounts@2023-04-15'
}
}
{{end -}}
{{end -}}
{{range $name, $value := .SqlServers}}
resource {{bicepName $name}} 'Microsoft.Sql/servers@2022-05-01-preview' = {
name: '{{$name}}-${resourceToken}'
location: location
tags: union(tags, {'aspire-resource-name': '{{$name}}'})
properties: {
minimalTlsVersion: '1.2'
publicNetworkAccess: 'Enabled'
administrators: {
administratorType: 'ActiveDirectory'
azureADOnlyAuthentication: true
login: managedIdentity.name
principalType: 'User'
sid: managedIdentity.properties.principalId
tenantId: subscription().tenantId
}
}
}

resource {{bicepName $name}}Firewall 'Microsoft.Sql/servers/firewallRules@2022-05-01-preview' = {
name: 'fw-{{$name}}-${resourceToken}'
parent: {{bicepName $name}}
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
}
{{range $cname := $value.Databases}}
resource {{bicepName $cname}} 'Microsoft.Sql/servers/databases@2022-05-01-preview' = {
name: '{{$cname}}'
parent: {{bicepName $name}}
location: location
sku: {
name: 'S0'
}
tags: union(tags, {'aspire-resource-name': '{{$cname}}'})
}
{{end -}}
{{end -}}
output MANAGED_IDENTITY_CLIENT_ID string = managedIdentity.properties.clientId
{{if .HasContainerRegistry -}}
Expand Down Expand Up @@ -371,4 +410,9 @@ output SERVICE_BINDING_{{alphaSnakeUpper $name}}_ENDPOINT string = {{bicepName $
{{range $name, $value := .CosmosDbAccounts -}}
output SERVICE_BINDING_{{alphaSnakeUpper $name}}_NAME string = {{bicepName $name}}.name
{{end -}}
{{range $name, $value := .SqlServers -}}
{{range $cname := $value.Databases -}}
output SERVICE_BINDING_{{alphaSnakeUpper $cname}}_CONNECTION_STRING string = 'Server=tcp:{{bicepName $name}}.Data.FullyQualifiedDomainName,1433;Initial Catalog={{bicepName $cname}};Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=\'Active Directory Default\';'
{{end -}}
{{end -}}
{{ end}}
Loading