Static property is not supported by Cassandra tables in Cosmos - using ARM templates or terraform

67 Views Asked by At

Creating a table in Cosmos Cassandra with static property along with the datatype fails! Creating a table using CQL after the keyspace is deployed works fine with static fields. Anyone else facing same or similar issues? Here is a github issue: https://github.com/Azure/azure-rest-api-specs/issues/26506

I tried running terraform apply with the below script

resource "azurerm_resource_group" "example" {
  name     = "tflex-cosmosdb-account-rg"
  location = "West Europe"
}

resource "azurerm_cosmosdb_account" "example" {
  name                = "tfex-cosmosdb-account"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  offer_type          = "Standard"

  capabilities {
    name = "EnableCassandra"
  }

  consistency_policy {
    consistency_level = "Strong"
  }

  geo_location {
    location          = azurerm_resource_group.example.location
    failover_priority = 0
  }
}

resource "azurerm_cosmosdb_cassandra_keyspace" "example" {
  name                = "tfex-cosmos-cassandra-keyspace"
  resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
  account_name        = azurerm_cosmosdb_account.example.name
  throughput          = 400
}

resource "azurerm_cosmosdb_cassandra_table" "example" {
  name                  = "testtable"
  cassandra_keyspace_id = azurerm_cosmosdb_cassandra_keyspace.example.id

  schema {

    column {
      name = "id"
      type = "uuid"
    }
    column {
      name = "type"
      type = "text"
    }
    column {
      name = "source"
      type = "text"
    }
    column {
      name = "time"
      type = "timestamp"
    }
    column {
      name = "entity"
      type = "text"
    }
    column {
      name = "ownerid"
      type = "uuid"
    }
    column {
      name = "ownertype"
      type = "text"
    }
    column {
      name = "data"
      type = "blob"
    }
    column {
      name = "sequence"
      type = "int"
    }
    column {
      name = "cloudeventview"
      type = "blob static"
    }
    
    column {
      name = "lastupdated"
      type = "timestamp static"
    }
    partition_key {
      name = "ownertype"
    }
    partition_key {
      name = "ownerid"
    }
    cluster_key {
      name     = "sequence"
      order_by = "Desc"
    }
  }
}

Table got created, but without static fields. According to the documentation from Azure Static is supported for datatype declaration.

1

There are 1 best solutions below

0
Vinay B On

I tried to provision Static property type in Cassandra tables in Cosmos - using Terraform and I was able to provision the requirement successfully.

In Cassandra, static columns are shared by all rows of the same partition.

Looking at your Terraform script, you've defined the cloudeventview and lastupdated columns as static. However, the issue might be in the syntax used for defining static columns. The standard syntax for defining a static column in CQL is column_name type static, but this syntax might not translate directly in Terraform.

Ensure that the Terraform provider you are using supports the syntax for defining static columns. It's possible that the syntax might be different or that the current version of the provider has limitations

My terraform configuration:

main.tf:

provider "azurerm" {
    features {} # Here I provided the latest version to eliminate all the compatibility issues
}

# Resource Group
resource "azurerm_resource_group" "example" {
  name     = "tflex-cosmosdb-vkaccount-rg"
  location = "east us"
}

# Cosmos DB Account
resource "azurerm_cosmosdb_account" "example" {
  name                = "tfex-cosmosdb-account"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  offer_type          = "Standard"

  capabilities {
    name = "EnableCassandra"
  }

  consistency_policy {
    consistency_level = "Strong"
  }

  geo_location {
    location          = azurerm_resource_group.example.location
    failover_priority = 0
  }
}

# Cassandra Keyspace
resource "azurerm_cosmosdb_cassandra_keyspace" "example" {
  name                = "tfex-cosmos-cassandra-keyspace"
  resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
  account_name        = azurerm_cosmosdb_account.example.name
  throughput          = 400
}

# Cosmos DB Cassandra Table without static fields
resource "azurerm_cosmosdb_cassandra_table" "example" {
  name                  = "testtable"
  cassandra_keyspace_id = azurerm_cosmosdb_cassandra_keyspace.example.id
  # Define schema without static fields
    schema {

    column {
      name = "id"
      type = "uuid"
    }
    column {
      name = "type"
      type = "text"
    }
    column {
      name = "source"
      type = "text"
    }
    column {
      name = "time"
      type = "timestamp"
    }
    column {
      name = "entity"
      type = "text"
    }
    column {
      name = "ownerid"
      type = "uuid"
    }
    column {
      name = "ownertype"
      type = "text"
    }
    column {
      name = "data"
      type = "blob"
    }
    column {
      name = "sequence"
      type = "int"
    }
    column {
      name = "cloudeventview"
      type = "blob static"
    }
    
    column {
      name = "lastupdated"
      type = "timestamp static"
    }
    partition_key {
      name = "ownertype"
    }
    partition_key {
      name = "ownerid"
    }
    cluster_key {
      name     = "sequence"
      order_by = "Desc"
    }
  }
}

Output:

enter image description here

enter image description here

ref: Apache Cassandra features supported by Azure Cosmos DB for Apache Cassandra | Microsoft Learn