用于创建 Cassandra 表的 Terraform 提供程序

Terraform provider to create cassandra tables

我希望通过 terraform 在 Azure 上创建 cassandra 数据库表。我已经有了相关的键空间。

我的部署正在利用 azurerm,但是他们的供应商缺少 cassandra 表资源。 截至目前,我只能通过门户上的 Azure UI 或使用 Azure CLI scripting 部署 cassandra 表,但是由于各种原因,这不是最佳解决方案。

有提供者可以帮助我解决这个问题吗?我正在四处看看,但似乎没有太多我可以利用的东西。

显然,解决方法是在“增量”模式下使用 the ARM provider 将资源作为 ARM 部署到 Azure。

 resource "azurerm_resource_group_template_deployment" "example" {
   depends_on = [module.cassandratest]

   name                = "example-cassandra-tables"
   resource_group_name = azurerm_resource_group.test.name
   deployment_mode     = "Incremental"
   template_content    = templatefile("resources/templatecosmos.json", {
     cosmos_db_account_name    = "test-cassandra-2",
     keyspace_name             = "keyspace1",
     table_name                = "test-table-2",
     autoscale_max_throughput  = 4000
   })
 }

记录了 CosmosDB Cassandra 模板 here。 resources/templatecosmos.json:

的内容示例
{
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
    "accountName": {
       "type": "string",
       "defaultValue": "${cosmos_db_account_name}",
       "metadata": {
          "description": "Cosmos DB account name, max length 44 characters"
       }
    },
    "keyspaceName": {
       "type": "string",
       "defaultValue": "${keyspace_name}",
       "metadata": {
          "description": "The name for the Cassandra Keyspace"
       }
    },
    "tableName": {
       "type": "string",
       "defaultValue": "${table_name}",
       "metadata": {
          "description": "The name for the Cassandra table"
       }
    },
    "autoscaleMaxThroughput": {
       "type": "int",
       "defaultValue": "[int(${autoscale_max_throughput})]",
       "minValue": 4000,
       "maxValue": 1000000,
       "metadata": {
          "description": "Maximum autoscale throughput for the Cassandra table"
       }
    }
 },
 "variables": {
    "accountName": "[toLower(parameters('accountName'))]",
    "databaseRef": "[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('accountName'))]",
    "keyspaceRef": "[resourceId('Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces', parameters('accountName'), parameters('keyspaceName'))]"
 },
  "resources": [
    {
       "type": "Microsoft.DocumentDb/databaseAccounts/cassandraKeyspaces/tables",
        "name": "[concat(variables('accountName'), '/', parameters('keyspaceName'), '/', parameters('tableName'))]",
        "apiVersion": "2020-04-01",
        "properties": {
           "resource": {
              "id": "[concat(parameters('tableName'))]",
              "schema": {
                 "columns": [
                    {
                       "name": "loadid",
                       "type": "uuid"
                    }
                 ],
                 "partitionKeys": [
                    { "name": "machine" },
                    { "name": "cpu" },
                    { "name": "mtime" }
                 ],
                 "clusterKeys": [
                    {
                       "name": "loadid",
                       "orderBy": "asc"
                    }
                 ]
              }
           },
           "options": {
              "autoscaleSettings": { 
                 "maxThroughput": "[parameters('autoscaleMaxThroughput')]" 
              }
           }
        }
     }
 ]
} 

无论出于何种原因,hashicorp 似乎从未在其提供商中实施 cassandra table。他们的 source code 缺少它的实现。

我建议在他们的回购协议中提交一个新错误。你可以做到 here