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

azurerm_cosmosdb_sql_container doesn't call get throughput api when cosmos account is serverless #9311

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func resourceArmCosmosDbSQLContainerUpdate(d *schema.ResourceData, meta interfac

func resourceArmCosmosDbSQLContainerRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Cosmos.SqlClient
accountClient := meta.(*clients.Client).Cosmos.DatabaseClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -338,16 +339,36 @@ func resourceArmCosmosDbSQLContainerRead(d *schema.ResourceData, meta interface{
}
}

throughputResp, err := client.GetSQLContainerThroughput(ctx, id.ResourceGroup, id.Account, id.Database, id.Name)
accResp, err := accountClient.Get(ctx, id.ResourceGroup, id.Account)
if err != nil {
if !utils.ResponseWasNotFound(throughputResp.Response) {
return fmt.Errorf("Error reading Throughput on Cosmos SQL Container %s (Account: %q, Database: %q) ID: %v", id.Name, id.Account, id.Database, err)
} else {
d.Set("throughput", nil)
d.Set("autoscale_settings", nil)
return fmt.Errorf("reading CosmosDB Account %q (Resource Group %q): %+v", id.Account, id.ResourceGroup, err)
}

if accResp.ID == nil || *accResp.ID == "" {
return fmt.Errorf("cosmosDB Account %q (Resource Group %q) ID is empty or nil", id.Account, id.ResourceGroup)
}

if props := accResp.DatabaseAccountGetProperties; props != nil && props.Capabilities != nil {
serverless := false
for _, v := range *props.Capabilities {
if *v.Name == "EnableServerless" {
serverless = true
}
}

if !serverless {
throughputResp, err := client.GetSQLContainerThroughput(ctx, id.ResourceGroup, id.Account, id.Database, id.Name)
if err != nil {
if !utils.ResponseWasNotFound(throughputResp.Response) {
return fmt.Errorf("Error reading Throughput on Cosmos SQL Container %s (Account: %q, Database: %q) ID: %v", id.Name, id.Account, id.Database, err)
} else {
d.Set("throughput", nil)
d.Set("autoscale_settings", nil)
}
} else {
common.SetResourceDataThroughputFromResponse(throughputResp, d)
}
}
} else {
common.SetResourceDataThroughputFromResponse(throughputResp, d)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ func TestAccAzureRMCosmosDbSqlContainer_basic(t *testing.T) {
})
}

func TestAccAzureRMCosmosDbSqlContainer_basic_serverless(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_container", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMCosmosDbSqlContainerDestroy,
Steps: []resource.TestStep{
{

Config: testAccAzureRMCosmosDbSqlContainer_basic_serverless(data),
Check: resource.ComposeAggregateTestCheckFunc(
testCheckAzureRMCosmosDbSqlContainerExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMCosmosDbSqlContainer_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_container", "test")

Expand Down Expand Up @@ -230,6 +250,19 @@ resource "azurerm_cosmosdb_sql_container" "test" {
`, testAccAzureRMCosmosDbSqlDatabase_basic(data), data.RandomInteger)
}

func testAccAzureRMCosmosDbSqlContainer_basic_serverless(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s

resource "azurerm_cosmosdb_sql_container" "test" {
name = "acctest-CSQLC-%[2]d"
resource_group_name = azurerm_cosmosdb_account.test.resource_group_name
account_name = azurerm_cosmosdb_account.test.name
database_name = azurerm_cosmosdb_sql_database.test.name
}
`, testAccAzureRMCosmosDbSqlDatabase_serverless(data), data.RandomInteger)
}

func testAccAzureRMCosmosDbSqlContainer_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down