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

Postgres to Azure via CDK #2708

Merged
merged 10 commits into from
Mar 8, 2024
Merged

Postgres to Azure via CDK #2708

merged 10 commits into from
Mar 8, 2024

Conversation

mitchdenny
Copy link
Member

@mitchdenny mitchdenny commented Mar 7, 2024

This is a draft, here is the API usage:

var pgsqlAdministratorLogin = builder.AddParameter("pgsqlAdministratorLogin");
var pgsqlAdministratorLoginPassword = builder.AddParameter("pgsqlAdministratorLoginPassword", secret: true);
var pgsql = builder.AddPostgres("pgsql").AsAzurePostgresFlexibleServerConstruct(pgsqlAdministratorLogin, pgsqlAdministratorLoginPassword);

This produces this manifest:

    "pgsqlAdministratorLogin": {
      "type": "parameter.v0",
      "value": "{pgsqlAdministratorLogin.inputs.value}",
      "inputs": {
        "value": {
          "type": "string"
        }
      }
    },
    "pgsqlAdministratorLoginPassword": {
      "type": "parameter.v0",
      "value": "{pgsqlAdministratorLoginPassword.inputs.value}",
      "inputs": {
        "value": {
          "type": "string",
          "secret": true
        }
      }
    },
    "pgsql": {
      "type": "azure.bicep.v0",
      "connectionString": "{pgsql.secretOutputs.connectionString}",
      "path": "pgsql.module.bicep",
      "params": {
        "principalId": "",
        "keyVaultName": "",
        "administratorLogin": "{pgsqlAdministratorLogin.value}",
        "administratorLoginPassword": "{pgsqlAdministratorLoginPassword.value}"
      },
      "inputs": {
        "password": {
          "type": "string",
          "secret": true,
          "default": {
            "generate": {
              "minLength": 10
            }
          }
        }
      }
    },

There is a bug in the above manifest ... the inputs section in pgsql probably shouldn't be there but I think that this is from a recent change that @eerhardt made so maybe my change is conflicting.

Finally this is the Bicep that is being produced:

targetScope = 'resourceGroup'

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

@description('')
param administratorLogin string

@description('')
param administratorLoginPassword string

@description('')
param principalId string

@description('')
param keyVaultName string


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

resource postgreSqlFlexibleServer_NYWb9Nbel 'Microsoft.DBforPostgreSQL/flexibleServers@2021-06-01' = {
  name: toLower(take(concat('postgres', uniqueString(resourceGroup().id)), 24))
  location: location
  sku: {
    name: 'Standard_B1ms'
    tier: 'Burstable'
  }
  properties: {
    administratorLogin: administratorLogin
    administratorLoginPassword: administratorLoginPassword
    version: '16'
    storage: {
      storageSizeGB: 32
    }
    backup: {
      backupRetentionDays: 7
      geoRedundantBackup: 'Disabled'
    }
    highAvailability: {
      mode: 'Disabled'
    }
    availabilityZone: '1'
  }
}

resource keyVaultSecret_Ddsc3HjrA 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = {
  parent: keyVault_IeF8jZvXV
  name: 'connectionString'
  location: location
  properties: {
    value: 'Host=${postgreSqlFlexibleServer_NYWb9Nbel.properties.fullyQualifiedDomainName};Username=${administratorLogin};Password=${administratorLoginPassword}'
  }
}

There are a few outstanding issues blocking this PR:

Microsoft Reviewers: Open in CodeFlow

@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 7, 2024
@mitchdenny mitchdenny requested a review from davidfowl March 7, 2024 12:35
@mitchdenny mitchdenny self-assigned this Mar 7, 2024
@mitchdenny mitchdenny marked this pull request as ready for review March 8, 2024 00:37
@mitchdenny mitchdenny merged commit 98a0933 into main Mar 8, 2024
8 checks passed
@mitchdenny mitchdenny deleted the mitchdenny/cdk-postgres branch March 8, 2024 03:05
@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