Skip to content

Commit e9bc41c

Browse files
committed
feat: Add Database support
1 parent ce3e8be commit e9bc41c

File tree

4 files changed

+213
-0
lines changed

4 files changed

+213
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
private import bicep
2+
3+
module Databases {
4+
/**
5+
* Base class for all database resources in Azure.
6+
*/
7+
abstract class DatabaseResource extends Resource {
8+
/**
9+
* Returns the type of the database resource.
10+
*/
11+
abstract string databaseType();
12+
13+
override string toString() {
14+
result = "DatabaseResource[" + this.databaseType() + "]"
15+
}
16+
}
17+
18+
/**
19+
* Azure SQL Database/Managed Instance
20+
*/
21+
class SqlServers extends DatabaseResource, Resource {
22+
SqlServers() { this.getResourceType().regexpMatch("^Microsoft.Sql/servers@.*") }
23+
24+
override string databaseType() { result = "sql" }
25+
}
26+
27+
/**
28+
* Azure Cosmos DB
29+
*/
30+
class CosmosDBAccounts extends DatabaseResource, Resource {
31+
CosmosDBAccounts() {
32+
this.getResourceType().regexpMatch("^Microsoft.DocumentDB/databaseAccounts@.*")
33+
}
34+
35+
override string databaseType() { result = "cosmosdb" }
36+
}
37+
38+
/**
39+
* Azure Database for PostgreSQL
40+
*/
41+
class PostgreSQLServers extends DatabaseResource, Resource {
42+
PostgreSQLServers() {
43+
this.getResourceType().regexpMatch("^Microsoft.DBforPostgreSQL/servers@.*")
44+
}
45+
46+
override string databaseType() { result = "postgresql" }
47+
}
48+
49+
/**
50+
* Azure Database for MySQL
51+
*/
52+
class MySQLServers extends DatabaseResource, Resource {
53+
MySQLServers() { this.getResourceType().regexpMatch("^Microsoft.DBforMySQL/servers@.*") }
54+
55+
override string databaseType() { result = "mysql" }
56+
}
57+
58+
/**
59+
* Azure Database for MariaDB
60+
*/
61+
class MariaDBServers extends DatabaseResource, Resource {
62+
MariaDBServers() { this.getResourceType().regexpMatch("^Microsoft.DBforMariaDB/servers@.*") }
63+
64+
override string databaseType() { result = "mariadb" }
65+
}
66+
67+
/**
68+
* Azure Data Lake Store Gen1
69+
*/
70+
class DataLakeStoreAccounts extends DatabaseResource, Resource {
71+
DataLakeStoreAccounts() {
72+
this.getResourceType().regexpMatch("^Microsoft.DataLakeStore/accounts@.*")
73+
}
74+
75+
override string databaseType() { result = "datalakestore" }
76+
}
77+
78+
/**
79+
* Azure Cache for Redis
80+
*/
81+
class RedisCaches extends DatabaseResource, Resource {
82+
RedisCaches() { this.getResourceType().regexpMatch("^Microsoft.Cache/Redis@.*") }
83+
84+
override string databaseType() { result = "redis" }
85+
}
86+
87+
/**
88+
* Azure Data Explorer (Kusto)
89+
*/
90+
class KustoClusters extends DatabaseResource, Resource {
91+
KustoClusters() { this.getResourceType().regexpMatch("^Microsoft.Kusto/Clusters@.*") }
92+
93+
override string databaseType() { result = "kusto" }
94+
}
95+
96+
/**
97+
* Azure Arc-enabled SQL Managed Instance
98+
*/
99+
class ArcSqlManagedInstances extends DatabaseResource, Resource {
100+
ArcSqlManagedInstances() {
101+
this.getResourceType().regexpMatch("^Microsoft.AzureArcData/sqlManagedInstances@.*")
102+
}
103+
104+
override string databaseType() { result = "arc-sql-managed-instance" }
105+
}
106+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| app.bicep:2:1:9:1 | DatabaseResource[sql] |
2+
| app.bicep:12:1:18:1 | DatabaseResource[cosmosdb] |
3+
| app.bicep:21:1:29:1 | DatabaseResource[postgresql] |
4+
| app.bicep:32:1:40:1 | DatabaseResource[mysql] |
5+
| app.bicep:43:1:51:1 | DatabaseResource[mariadb] |
6+
| app.bicep:54:1:58:1 | DatabaseResource[datalakestore] |
7+
| app.bicep:61:1:71:1 | DatabaseResource[redis] |
8+
| app.bicep:74:1:83:1 | DatabaseResource[kusto] |
9+
| app.bicep:86:1:93:1 | DatabaseResource[arc-sql-managed-instance] |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import bicep
2+
3+
query predicate databases(Databases::DatabaseResource dr) {
4+
any()
5+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Azure SQL Database
2+
resource sqlDb 'Microsoft.Sql/servers@2022-02-01' = {
3+
name: 'sqlserver1'
4+
location: 'eastus'
5+
properties: {
6+
administratorLogin: 'adminuser'
7+
administratorLoginPassword: 'P@ssw0rd!'
8+
}
9+
}
10+
11+
// Azure Cosmos DB
12+
resource cosmosDb 'Microsoft.DocumentDB/databaseAccounts@2022-03-15' = {
13+
name: 'cosmosdb1'
14+
location: 'eastus'
15+
properties: {
16+
databaseAccountOfferType: 'Standard'
17+
}
18+
}
19+
20+
// Azure Database for PostgreSQL
21+
resource postgresqlDb 'Microsoft.DBforPostgreSQL/servers@2022-01-20' = {
22+
name: 'pgserver1'
23+
location: 'eastus'
24+
properties: {
25+
administratorLogin: 'pgadmin'
26+
administratorLoginPassword: 'P@ssw0rd!'
27+
version: '11'
28+
}
29+
}
30+
31+
// Azure Database for MySQL
32+
resource mysqlDb 'Microsoft.DBforMySQL/servers@2022-01-20' = {
33+
name: 'mysqlserver1'
34+
location: 'eastus'
35+
properties: {
36+
administratorLogin: 'mysqladmin'
37+
administratorLoginPassword: 'P@ssw0rd!'
38+
version: '5.7'
39+
}
40+
}
41+
42+
// Azure Database for MariaDB
43+
resource mariadbDb 'Microsoft.DBforMariaDB/servers@2018-06-01' = {
44+
name: 'mariadbserver1'
45+
location: 'eastus'
46+
properties: {
47+
administratorLogin: 'mariadbadmin'
48+
administratorLoginPassword: 'P@ssw0rd!'
49+
version: '10.2'
50+
}
51+
}
52+
53+
// Azure Data Lake Store Gen1
54+
resource datalakeStore 'Microsoft.DataLakeStore/accounts@2016-11-01' = {
55+
name: 'datalakestore1'
56+
location: 'eastus'
57+
properties: {}
58+
}
59+
60+
// Azure Cache for Redis
61+
resource redisCache 'Microsoft.Cache/Redis@2023-04-01' = {
62+
name: 'rediscache1'
63+
location: 'eastus'
64+
properties: {
65+
sku: {
66+
name: 'Basic'
67+
family: 'C'
68+
capacity: 0
69+
}
70+
}
71+
}
72+
73+
// Azure Data Explorer (Kusto)
74+
resource kustoCluster 'Microsoft.Kusto/Clusters@2023-05-02' = {
75+
name: 'kustocluster1'
76+
location: 'eastus'
77+
properties: {
78+
sku: {
79+
name: 'Standard_D13_v2'
80+
capacity: 2
81+
}
82+
}
83+
}
84+
85+
// Azure Arc-enabled SQL Managed Instance
86+
resource arcSqlMi 'Microsoft.AzureArcData/sqlManagedInstances@2022-03-01-preview' = {
87+
name: 'arcsqlmi1'
88+
location: 'eastus'
89+
properties: {
90+
administratorLogin: 'arcadmin'
91+
administratorLoginPassword: 'P@ssw0rd!'
92+
}
93+
}

0 commit comments

Comments
 (0)