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

Azure Redis via CDK #2635

Merged
merged 3 commits into from
Mar 6, 2024
Merged

Azure Redis via CDK #2635

merged 3 commits into from
Mar 6, 2024

Conversation

mitchdenny
Copy link
Member

@mitchdenny mitchdenny commented Mar 5, 2024

This PR introduces support for deploying Azure Redis via CDK. The usage is as follows:

builder.AddRedis("cache").PublishAsAzureRedisConstruct();
builder.AddRedis("cache").AsAzureRedisConstruct();

This will produce the following manifest:

{
  "resources": {
    "storagesku": {
      "type": "parameter.v0",
      "value": "{storagesku.inputs.value}",
      "inputs": {
        "value": {
          "type": "string"
        }
      }
    },
    "locationOverride": {
      "type": "parameter.v0",
      "value": "{locationOverride.inputs.value}",
      "inputs": {
        "value": {
          "type": "string"
        }
      }
    },
    "signaturesecret": {
      "type": "parameter.v0",
      "value": "{signaturesecret.inputs.value}",
      "inputs": {
        "value": {
          "type": "string"
        }
      }
    },
    "storage": {
      "type": "azure.bicep.v0",
      "path": "storage.module.bicep",
      "params": {
        "principalId": "",
        "principalType": "",
        "storagesku": "{storagesku.value}",
        "locationOverride": "{locationOverride.value}"
      }
    },
    "blobs": {
      "type": "value.v0",
      "connectionString": "{storage.outputs.blobEndpoint}"
    },
    "sql": {
      "type": "azure.bicep.v0",
      "connectionString": "Server=tcp:{sql.outputs.sqlServerFqdn},1433;Encrypt=True;Authentication=\u0022Active Directory Default\u0022",
      "path": "sql.module.bicep",
      "params": {
        "principalId": "",
        "principalName": ""
      }
    },
    "sqldb": {
      "type": "value.v0",
      "connectionString": "{sql.connectionString};Database=sqldb"
    },
    "mykv": {
      "type": "azure.bicep.v0",
      "connectionString": "{mykv.outputs.vaultUri}",
      "path": "mykv.module.bicep",
      "params": {
        "principalId": "",
        "principalType": "",
        "signaturesecret": "{signaturesecret.value}"
      }
    },
    "cache": {
      "type": "azure.bicep.v0",
      "connectionString": "{cache.secretOutputs.connectionString}",
      "path": "cache.module.bicep",
      "params": {
        "principalId": "",
        "keyVaultName": ""
      }
    },
    "api": {
      "type": "project.v0",
      "path": "../CdkSample.ApiService/CdkSample.ApiService.csproj",
      "env": {
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
        "ConnectionStrings__blobs": "{blobs.connectionString}",
        "ConnectionStrings__sqldb": "{sqldb.connectionString}",
        "ConnectionStrings__mykv": "{mykv.connectionString}",
        "ConnectionStrings__cache": "{cache.connectionString}"
      },
      "bindings": {
        "http": {
          "scheme": "http",
          "protocol": "tcp",
          "transport": "http"
        },
        "https": {
          "scheme": "https",
          "protocol": "tcp",
          "transport": "http"
        }
      }
    }
  }
}

And the following Bicep (for the Redis module):

targetScope = 'resourceGroup'

@description('')
param principalId string

@description('')
param keyVaultName string

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


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

resource redisCache_p9fE6TK3F 'Microsoft.Cache/Redis@2020-06-01' = {
  name: toLower(take(concat('cache', uniqueString(resourceGroup().id)), 24))
  location: location
  properties: {
    enableNonSslPort: false
    minimumTlsVersion: '1.2'
    sku: {
      name: 'Basic'
      family: 'C'
      capacity: 1
    }
  }
}

resource keyVaultSecret_Ddsc3HjrA 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = {
  parent: keyVault_IeF8jZvXV
  name: 'connectionString'
  location: location
  properties: {
    value: '${redisCache_p9fE6TK3F.properties.hostName},ssl=true,password=${redisCache_p9fE6TK3F.listKeys(redisCache_p9fE6TK3F.apiVersion).primaryKey}'
  }
}

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 5, 2024
@mitchdenny mitchdenny self-assigned this Mar 5, 2024
@mitchdenny mitchdenny added this to the preview 5 (Apr) milestone Mar 5, 2024
@mitchdenny mitchdenny marked this pull request as ready for review March 6, 2024 05:29

@description('')
param principalType string
param locationOverride string
Copy link
Member

Choose a reason for hiding this comment

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

What is this jank

Copy link
Member Author

Choose a reason for hiding this comment

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

This is to test that we can override default values for location with something we pass in.

@mitchdenny mitchdenny merged commit 100e391 into main Mar 6, 2024
8 checks passed
@mitchdenny mitchdenny deleted the mitchdenny/cdk-redis-take2 branch March 6, 2024 20:31
@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.

2 participants