Skip to content

Commit

Permalink
easy-init: Switch to avm (Azure Verified Modules) (#4455)
Browse files Browse the repository at this point in the history
With this change, we switch easy-init's generated infrastructure to use avm (Azure Verified Modules).

Since AVM allows us to express resource definitions in a more condensed form, we employ the strategy of having a single ` resources.bicep` that uses all the different modules available is employed.

Notable behavioral changes introduced:

**Postgres**
- Server version upgraded from version 13 to version 15.
- Storage size reduced from 128GB to 32GB (AVM default).

**MongoDB**
 - Server version upgraded from 4.0 to 4.2.

**Redis**
- Redis is now implemented as an Azure Cache for Redis instance instead of previously as a container app image.

Environment variables are also standardized:
- POSTGRES_URL, MONGODB_URL, REDIS_URL all serves as the full connection string URI to the respective instances.

Contributes to: Azure/azure-dev-pr#1682
  • Loading branch information
weikanglim authored Oct 24, 2024
1 parent 09cd9c4 commit 7511467
Show file tree
Hide file tree
Showing 17 changed files with 520 additions and 1,928 deletions.
4 changes: 3 additions & 1 deletion cli/azd/internal/repository/infra_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func (i *Initializer) infraSpecFromDetect(
detect detectConfirm) (scaffold.InfraSpec, error) {
spec := scaffold.InfraSpec{}
for database := range detect.Databases {
if database == appdetect.DbRedis { // no configuration needed for redis
if database == appdetect.DbRedis {
spec.DbRedis = &scaffold.DatabaseRedis{}
// no further configuration needed for redis
continue
}

Expand Down
26 changes: 5 additions & 21 deletions cli/azd/internal/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,16 @@ func ExecInfra(
return err
}

if spec.DbCosmosMongo != nil {
err = Execute(t, "db-cosmos-mongo.bicep", spec.DbCosmosMongo, filepath.Join(infraApp, "db-cosmos-mongo.bicep"))
if err != nil {
return fmt.Errorf("scaffolding cosmos mongodb: %w", err)
}
}

if spec.DbPostgres != nil {
err = Execute(t, "db-postgres.bicep", spec.DbPostgres, filepath.Join(infraApp, "db-postgres.bicep"))
if err != nil {
return fmt.Errorf("scaffolding postgres: %w", err)
}
}

for _, svc := range spec.Services {
err = Execute(t, "host-containerapp.bicep", svc, filepath.Join(infraApp, svc.Name+".bicep"))
if err != nil {
return fmt.Errorf("scaffolding containerapp: %w", err)
}
}

err = Execute(t, "main.bicep", spec, filepath.Join(infraRoot, "main.bicep"))
if err != nil {
return fmt.Errorf("scaffolding main.bicep: %w", err)
}

err = Execute(t, "resources.bicep", spec, filepath.Join(infraRoot, "resources.bicep"))
if err != nil {
return fmt.Errorf("scaffolding resources.bicep: %w", err)
}

err = Execute(t, "main.parameters.json", spec, filepath.Join(infraRoot, "main.parameters.json"))
if err != nil {
return fmt.Errorf("scaffolding main.parameters.json: %w", err)
Expand Down
46 changes: 46 additions & 0 deletions cli/azd/internal/scaffold/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,51 @@ func TestExecInfra(t *testing.T) {
},
},
},
{
"All",
InfraSpec{
DbPostgres: &DatabasePostgres{
DatabaseName: "appdb",
},
DbCosmosMongo: &DatabaseCosmosMongo{
DatabaseName: "appdb",
},
DbRedis: &DatabaseRedis{},
Services: []ServiceSpec{
{
Name: "api",
Port: 3100,
Backend: &Backend{
Frontends: []ServiceReference{
{
Name: "web",
},
},
},
DbCosmosMongo: &DatabaseReference{
DatabaseName: "appdb",
},
DbRedis: &DatabaseReference{
DatabaseName: "redis",
},
DbPostgres: &DatabaseReference{
DatabaseName: "appdb",
},
},
{
Name: "web",
Port: 3101,
Frontend: &Frontend{
Backends: []ServiceReference{
{
Name: "api",
},
},
},
},
},
},
},
{
"API with Postgres",
InfraSpec{
Expand Down Expand Up @@ -114,6 +159,7 @@ func TestExecInfra(t *testing.T) {
{
"API with Redis",
InfraSpec{
DbRedis: &DatabaseRedis{},
Services: []ServiceSpec{
{
Name: "api",
Expand Down
4 changes: 4 additions & 0 deletions cli/azd/internal/scaffold/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type InfraSpec struct {
// Databases to create
DbPostgres *DatabasePostgres
DbCosmosMongo *DatabaseCosmosMongo
DbRedis *DatabaseRedis
}

type Parameter struct {
Expand All @@ -30,6 +31,9 @@ type DatabaseCosmosMongo struct {
DatabaseName string
}

type DatabaseRedis struct {
}

type ServiceSpec struct {
Name string
Port int
Expand Down
29 changes: 29 additions & 0 deletions cli/azd/resources/scaffold/base/modules/set-redis-conn.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
param name string
param keyVaultName string
param passwordSecretName string
param urlSecretName string

resource redisConn 'Microsoft.Cache/redis@2024-03-01' existing = {
name: name
}

resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
name: keyVaultName
}

resource passwordSecret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
name: passwordSecretName
parent: keyVault
properties: {
value: redisConn.listKeys().primaryKey
}
}

resource urlSecret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
name: urlSecretName
parent: keyVault
properties: {
value: 'rediss://:${redisConn.listKeys().primaryKey}@${redisConn.properties.hostName}:${redisConn.properties.sslPort}'
}
}

33 changes: 0 additions & 33 deletions cli/azd/resources/scaffold/base/shared/apps-env.bicep

This file was deleted.

Loading

0 comments on commit 7511467

Please sign in to comment.