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

easy-init: Switch to avm (Azure Verified Modules) #4455

Merged
merged 8 commits into from
Oct 24, 2024
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
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 @@ -24,7 +24,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
Loading