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

Add recipes required for eshop #24

Merged
merged 9 commits into from
Aug 10, 2023
13 changes: 7 additions & 6 deletions aws/rediscaches.bicep
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import aws as aws

@description('Radius-provided object containing information about the resouce calling the Recipe')
@description('Radius-provided object containing information about the resource calling the Recipe')
param context object

@description('Name of the EKS cluster used for app deployment')
Expand All @@ -16,16 +16,16 @@ resource eksCluster 'AWS.EKS/Cluster@default' existing = {
}
}

param subnetGroupName string = 'subnet-group-memorydb-${uniqueString(context.resource.id)}'
param memoryDBSubnetGroupName string = 'memorydb-subnetgroup-${uniqueString(context.resource.id)}'
resource subnetGroup 'AWS.MemoryDB/SubnetGroup@default' = {
alias:subnetGroupName
alias: memoryDBSubnetGroupName
properties: {
SubnetGroupName: subnetGroupName
SubnetGroupName: memoryDBSubnetGroupName
SubnetIds: ((empty(subnetIds)) ? eksCluster.properties.ResourcesVpcConfig.SubnetIds : concat(subnetIds,eksCluster.properties.ResourcesVpcConfig.SubnetIds))
}
}

param memoryDBClusterName string = 'memorydb-${uniqueString(context.resource.id)}'
param memoryDBClusterName string = 'memorydb-cluster-${uniqueString(context.resource.id)}'
resource memoryDBCluster 'AWS.MemoryDB/Cluster@default' = {
alias: memoryDBClusterName
properties: {
Expand All @@ -42,8 +42,9 @@ output result object = {
values: {
host: memoryDBCluster.properties.ClusterEndpoint.Address
port: memoryDBCluster.properties.ClusterEndpoint.Port
tls: true
}
secrets: {
connectionString: 'rediss://${memoryDBCluster.properties.ClusterEndpoint.Address}:${memoryDBCluster.properties.ClusterEndpoint.Port}'
url: '${memoryDBCluster.properties.ClusterEndpoint.Address}:${memoryDBCluster.properties.ClusterEndpoint.Port},ssl=true'
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved
}
}
71 changes: 71 additions & 0 deletions aws/sqldatabases.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import aws as aws

@description('Radius-provided object containing information about the resource calling the Recipe')
param context object

@description('Name of the EKS cluster used for app deployment')
param eksClusterName string

@description('SQL administrator username')
param adminLogin string

@description('SQL administrator password')
@secure()
param adminPassword string

@description('Database name')
param database string
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved

resource eksCluster 'AWS.EKS/Cluster@default' existing = {
alias: eksClusterName
properties: {
Name: eksClusterName
}
}

var rdsSubnetGroupName = 'eshop-rds-dbsubnetgroup-${uniqueString(context.resource.id)}'
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved
resource rdsDBSubnetGroup 'AWS.RDS/DBSubnetGroup@default' = {
alias: rdsSubnetGroupName
properties: {
DBSubnetGroupName: rdsSubnetGroupName
DBSubnetGroupDescription: rdsSubnetGroupName
SubnetIds: eksCluster.properties.ResourcesVpcConfig.SubnetIds
}
}

var rdsDBInstanceName = 'eshop-rds-dbinstance-${uniqueString(context.resource.id)}'
resource rdsDBInstance 'AWS.RDS/DBInstance@default' = {
alias: rdsDBInstanceName
properties: {
DBInstanceIdentifier: rdsDBInstanceName
Engine: 'sqlserver-ex'
EngineVersion: '15.00.4153.1.v1'
DBInstanceClass: 'db.t3.large'
AllocatedStorage: '20'
MaxAllocatedStorage: 30
MasterUsername: adminLogin
MasterUserPassword: adminPassword
DBSubnetGroupName: rdsDBSubnetGroup.properties.DBSubnetGroupName
VPCSecurityGroups: [eksCluster.properties.ClusterSecurityGroupId]
PreferredMaintenanceWindow: 'Mon:00:00-Mon:03:00'
PreferredBackupWindow: '03:00-06:00'
LicenseModel: 'license-included'
Timezone: 'GMT Standard Time'
CharacterSetName: 'Latin1_General_CI_AS'
}
}

output result object = {
values: {
server: rdsDBInstance.properties.Endpoint.Address
port: 1433
database: database
username: adminLogin
}
secrets: {
#disable-next-line outputs-should-not-contain-secrets
connectionString: 'Server=tcp:${rdsDBInstance.properties.Endpoint.Address},${rdsDBInstance.properties.Endpoint.Port};Initial Catalog=${database};User Id=${adminLogin};Password=${adminPassword};Encrypt=false'
#disable-next-line outputs-should-not-contain-secrets
password: adminPassword
}
}
14 changes: 7 additions & 7 deletions azure/rediscaches.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@ param location string = resourceGroup().location
@description('The size of the Redis cache to deploy. Valid values: for C (Basic/Standard) family (0, 1, 2, 3, 4, 5, 6), for P (Premium) family (1, 2, 3, 4).')
@minValue(0)
@maxValue(6)
param capacity int = 0
param skuCapacity int = 0

@description('The SKU family to use. Valid values: (C, P). (C = Basic/Standard, P = Premium).')
@allowed([
'C'
'P'
])
param family string = 'C'
param skuFamily string = 'C'

@description('The type of Redis cache to deploy. Valid values: (Basic, Standard, Premium)')
@allowed([
'Basic'
'Standard'
'Premium'
])
param name string = 'Basic'
param skuName string = 'Basic'

resource azureCache 'Microsoft.Cache/redis@2022-06-01' = {
// Ensure the resource name is unique and repeatable
name: 'cache-${uniqueString(context.resource.id, resourceGroup().id)}'
location: location
properties: {
sku: {
capacity: capacity
family: family
name: name
capacity: skuCapacity
family: skuFamily
name: skuName
}
}
}
Expand All @@ -42,6 +41,7 @@ output result object = {
host: azureCache.properties.hostName
port: azureCache.properties.sslPort
username: ''
tls: true
}
secrets: {
#disable-next-line outputs-should-not-contain-secrets
Expand Down
74 changes: 74 additions & 0 deletions azure/sqldatabases.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@description('Radius-provided object containing information about the resouce calling the Recipe')
param context object

@description('The geo-location where the resource lives.')
param location string = resourceGroup().location

@description('SQL administrator username')
param adminLogin string

@description('SQL administrator password')
@secure()
param adminPassword string

@description('Database name')
param database string
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved

@description('The type of MSSQL server to deploy. Valid values: (Basic, Standard, Premium)')
@allowed([
'Basic'
'Standard'
'Premium'
])
param skuName string = 'Standard'

@description('The size of the MSSQL server to deploy. Valid values: for C (Basic/Standard) family (0, 1, 2, 3, 4, 5, 6), for P (Premium) family (1, 2, 3, 4).')
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved
@allowed([
'Basic'
'Standard'
'Premium'
])
param skuTier string = 'Standard'

var mssqlPort = 1433

resource mssql 'Microsoft.Sql/servers@2021-02-01-preview' = {
name: 'mssql-${uniqueString(context.resource.id, resourceGroup().id)}'
location: location
properties: {
administratorLogin: adminLogin
administratorLoginPassword: adminPassword
}

resource firewallAllowEverything 'firewallRules' = {
name: 'firewall-allow-everything'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
}

resource db 'databases' = {
name: database
location: location
sku: {
name: skuName
tier: skuTier
}
}
}

output result object = {
values: {
server: mssql.properties.fullyQualifiedDomainName
port: mssqlPort
database: mssql::db.name
username: adminLogin
}
secrets: {
#disable-next-line outputs-should-not-contain-secrets
password: adminPassword
#disable-next-line outputs-should-not-contain-secrets
connectionString: 'Server=tcp:${mssql.properties.fullyQualifiedDomainName},${mssqlPort};Initial Catalog=${mssql::db.name};User Id=${adminLogin};Password=${adminPassword};Encrypt=false'
}
}
102 changes: 102 additions & 0 deletions dev/rabbitmqmessagequeues.bicep
willdavsmith marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
@description('Information about what resource is calling this Recipe. Generated by Radius. For more information visit https://docs.radapp.dev/operations/custom-recipes/')
param context object

@description('Name of the queue. Defaults to the name of the Radius RabbitMQ resource.')
param queue string = context.resource.name

@description('Tag to pull for the rabbitmq container image.')
param tag string = '3'

@description('Memory request for the rabbitmq deployment.')
param memoryRequest string = '256Mi'

@description('Memory limit for the rabbitmq deployment')
param memoryLimit string = '1024Mi'

import kubernetes as kubernetes {
kubeConfig: ''
namespace: context.runtime.kubernetes.namespace
}

var uniqueName = 'rabbitmq-${uniqueString(context.resource.id)}'
var port = 5672

resource rabbitmq 'apps/Deployment@v1' = {
metadata: {
name: uniqueName
}
spec: {
selector: {
matchLabels: {
app: 'rabbitmq'
resource: context.resource.name
}
}
template: {
metadata: {
labels: {
app: 'rabbitmq'
resource: context.resource.name
// Label pods with the application name so `rad run` can find the logs.
'radius.dev/application': context.application == null ? '' : context.application.name
}
}
spec: {
containers: [
{
name: 'rabbitmq'
image: 'rabbitmq:${tag}'
ports: [
{
containerPort: port
}
]
resources: {
requests: {
memory: memoryRequest
}
limits: {
memory: memoryLimit
}
}
env: []
}
]
}
}
}
}

resource svc 'core/Service@v1' = {
metadata: {
name: uniqueName
labels: {
name: uniqueName
}
}
spec: {
type: 'ClusterIP'
selector: {
app: 'rabbitmq'
resource: context.resource.name
}
ports: [
{
port: port
}
]
}
}

output result object = {
resources: [
'/planes/kubernetes/local/namespaces/${svc.metadata.namespace}/providers/core/Service/${svc.metadata.name}'
'/planes/kubernetes/local/namespaces/${rabbitmq.metadata.namespace}/providers/apps/Deployment/${rabbitmq.metadata.name}'
]
values: {
queue: queue
}
secrets: {
connectionString: '${svc.metadata.name}.${svc.metadata.namespace}.svc.cluster.local'
}
}