Skip to content

Commit

Permalink
Fix TC for azurerm_cosmosdb_cassandra_cluster and azurerm_cosmosdb_ca…
Browse files Browse the repository at this point in the history
…ssandra_datacenter (#16752)
  • Loading branch information
Neil Ye authored May 18, 2022
1 parent 621a6ca commit ba15449
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ import (

type CassandraClusterResource struct{}

func TestAccCassandraCluster(t *testing.T) {
// NOTE: this is a combined test rather than separate split out tests due to all below TCs sharing same sp
acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){
"basic": {
"basic": testAccCassandraCluster_basic,
"requiresImport": testAccCassandraCluster_requiresImport,
"tags": testAccCassandraCluster_tags,
},
})
}

func testAccCassandraCluster_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_cluster", "test")
r := CassandraClusterResource{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

type CassandraDatacenterResource struct{}

func TestAccCassandraDatacenter_basic(t *testing.T) {
func testAccCassandraDatacenter_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_datacenter", "test")
r := CassandraDatacenterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, 3),
Check: acceptance.ComposeAggregateTestCheckFunc(
Expand All @@ -30,11 +30,11 @@ func TestAccCassandraDatacenter_basic(t *testing.T) {
})
}

func TestAccCassandraDatacenter_update(t *testing.T) {
func testAccCassandraDatacenter_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_datacenter", "test")
r := CassandraDatacenterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, 3),
Check: acceptance.ComposeAggregateTestCheckFunc(
Expand Down Expand Up @@ -91,10 +91,14 @@ resource "azurerm_subnet" "test" {
address_prefixes = ["10.0.1.0/24"]
}
data "azuread_service_principal" "test" {
display_name = "Azure Cosmos DB"
}
resource "azurerm_role_assignment" "test" {
scope = azurerm_virtual_network.test.id
role_definition_name = "Network Contributor"
principal_id = "255f3c8e-0c3d-4f06-ba9d-2fb68af0faed"
principal_id = data.azuread_service_principal.test.object_id
}
resource "azurerm_cosmosdb_cassandra_cluster" "test" {
Expand All @@ -103,6 +107,8 @@ resource "azurerm_cosmosdb_cassandra_cluster" "test" {
location = azurerm_resource_group.test.location
delegated_management_subnet_id = azurerm_subnet.test.id
default_admin_password = "Password1234"
depends_on = [azurerm_role_assignment.test]
}
resource "azurerm_cosmosdb_cassandra_datacenter" "test" {
Expand Down
22 changes: 22 additions & 0 deletions internal/services/cosmos/cosmosdb_cassandra_resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cosmos_test

import (
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
)

func TestAccCassandraSequential(t *testing.T) {
// NOTE: this is a combined test rather than separate split out tests due to all below TCs sharing same sp
acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){
"cluster": {
"basic": testAccCassandraCluster_basic,
"requiresImport": testAccCassandraCluster_requiresImport,
"tags": testAccCassandraCluster_tags,
},
"dataCenter": {
"basic": testAccCassandraDatacenter_basic,
"requiresImport": testAccCassandraDatacenter_update,
},
})
}
14 changes: 13 additions & 1 deletion website/docs/r/cosmosdb_cassandra_datacenter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ description: |-

Manages a Cassandra Datacenter.

~> ** NOTE: ** In order for the `Azure Managed Instances for Apache Cassandra` to work properly the product requires the `Azure Cosmos DB` Application ID to be present and working in your tenant. If the `Azure Cosmos DB` Application ID is missing in your environment you will need to have an administrator of your tenant run the following command to add the `Azure Cosmos DB` Application ID to your tenant:

```powershell
New-AzADServicePrincipal -ApplicationId a232010e-820c-4083-83bb-3ace5fc29d0b
```

## Example Usage

```hcl
Expand All @@ -36,10 +42,14 @@ resource "azurerm_subnet" "example" {
address_prefixes = ["10.0.1.0/24"]
}
data "azuread_service_principal" "example" {
display_name = "Azure Cosmos DB"
}
resource "azurerm_role_assignment" "example" {
scope = azurerm_virtual_network.example.id
role_definition_name = "Network Contributor"
principal_id = "e5007d2c-4b13-4a74-9b6a-605d99f03501"
principal_id = data.azuread_service_principal.example.object_id
}
resource "azurerm_cosmosdb_cassandra_cluster" "example" {
Expand All @@ -48,6 +58,8 @@ resource "azurerm_cosmosdb_cassandra_cluster" "example" {
location = azurerm_resource_group.example.location
delegated_management_subnet_id = azurerm_subnet.example.id
default_admin_password = "Password1234"
depends_on = [azurerm_role_assignment.example]
}
resource "azurerm_cosmosdb_cassandra_datacenter" "example" {
Expand Down

0 comments on commit ba15449

Please sign in to comment.