Skip to content

Azure Cosmos via CDK#2710

Merged
mitchdenny merged 8 commits intomainfrom
midenn/cosmos-cdk
Mar 8, 2024
Merged

Azure Cosmos via CDK#2710
mitchdenny merged 8 commits intomainfrom
midenn/cosmos-cdk

Conversation

@mitchdenny
Copy link
Copy Markdown
Member

@mitchdenny mitchdenny commented Mar 7, 2024

This PR adds Azure Cosmos via CDK usage is:

var cosmosdb = builder.AddAzureCosmosDBConstruct("cosmos").AddDatabase("cosmosdb");

Manifest output is:

    "cosmos": {
      "type": "azure.bicep.v0",
      "connectionString": "{cosmos.secretOutputs.connectionString}",
      "path": "cosmos.module.bicep",
      "params": {
        "keyVaultName": ""
      }
    },

Bicep produced is:

targetScope = 'resourceGroup'

@description('')
param location string = resourceGroup().location

@description('')
param keyVaultName string


resource keyVault_IeF8jZvXV 'Microsoft.KeyVault/vaults@2023-02-01' existing = {
  name: keyVaultName
}

resource cosmosDBAccount_5pKmb8KAZ 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {
  name: toLower(take(concat('cosmos', uniqueString(resourceGroup().id)), 24))
  location: location
  kind: 'GlobalDocumentDB'
  properties: {
    databaseAccountOfferType: 'Standard'
    consistencyPolicy: {
      defaultConsistencyLevel: 'Session'
    }
    locations: [
      {
        locationName: location
        failoverPriority: 0
      }
    ]
  }
}

resource cosmosDBSqlDatabase_q2Ny71tR3 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-05-15' = {
  parent: cosmosDBAccount_5pKmb8KAZ
  name: 'cosmosdb'
  location: location
  properties: {
    resource: {
      id: 'cosmosdb'
    }
  }
}

resource keyVaultSecret_Ddsc3HjrA 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = {
  parent: keyVault_IeF8jZvXV
  name: 'connectionString'
  location: location
  properties: {
    value: 'AccountEndpoint=${cosmosDBAccount_5pKmb8KAZ.properties.documentEndpoint};AccountKey=${cosmosDBAccount_5pKmb8KAZ.listKeys(cosmosDBAccount_5pKmb8KAZ.apiVersion).primaryMasterKey}
  }
}

Deploying successfully via both AZD and Azure Provisioner. Just needs some tests tuned.

Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 7, 2024
@mitchdenny mitchdenny marked this pull request as ready for review March 7, 2024 20:31

var keyVaultSecret = new KeyVaultSecret(construct, keyVault, "connectionString");
keyVaultSecret.AssignProperty(
x => x.Properties.Value,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mitchdenny mitchdenny merged commit 559f328 into main Mar 8, 2024
@mitchdenny mitchdenny deleted the midenn/cosmos-cdk branch March 8, 2024 07:37
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants