Terraform 0.11.11
Azurerm 1.21
azurerm_sql_database```resource azurerm_sql_database secondary {
  count                            = "${var.db_secondary_server_name == "" ? 0 : 1}"
  name                             = "${var.db_name}"
  resource_group_name              = "${data.azurerm_resource_group.core.name}"
  location                         = "${var.db_secondary_location}"
  server_name                      = "${var.db_secondary_server_name}"
  create_mode                      = "OnlineSecondary"
  source_database_id               = "${azurerm_sql_database.primary.id}"
  edition                          = "${local.edition}"
  requested_service_objective_name = "${var.db_secondary_service_objective == "" ? var.db_service_objective : var.db_secondary_service_objective}"
  collation                        = "${local.collation}"
tags {
    "managed-by" = "terraform"
    environment  = "${var.suffix}"
    "cost-center" = "XXXXX"
  }
}
```
n/a
The change here is adding a new tag. Nothing else on the resource changes.
Getting this error reported and therefore the resources won't update.
azurerm_sql_database.secondary: sql.DatabasesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: json: cannot unmarshal array into Go struct field serviceError2.details of type map[string]interface {}
Ensure there is a sql db with an online secondary in a paired region. Changes to the secondary fail to apply
terraform applyWe've always had problems with secondary DBS not updating their service objectives when asked to by terraform, but this is new.
@jeffreyCline would you be able to take a look into this?
@simongh Thanks for opening this issue. I have taken a look at this and it is a bug in the 2014-04-01 API, which is called by the 2015-05-01-preview API and has been fixed in the 2017-10-01-preview version of the API. Terraform is currently calling the 2015-05-01-preview so when you attempt to add a tag you will receive a 400 Bad Request The destination database name 'repro2699secondarydb' already exists on the server 'repro2699secondarysqlsvr'.","target":null`. The service team that owns this ARM API will not fix this issue as it is considered a legacy API and is already fixed in the newer version of the API. At this point there are two possible options:
1) Add the tag via the Azure Portal, since the portal is already using the 2017-10-01-preview version of the API.
2) Wait for Terraform to upgrade the resource to use the 2017-10-01-preview version of the API.
As for number 2 above I am not exactly sure when that work is planned to be done, perhaps @tombuildsstuff would have a better idea about that.
@jeffreyCline, provided nothing breaks we can upgrade whenever, however a quick find replace & look does result in:
[21:04:15] kt@snowbook:~/hashi/..3../terraform-providers/terraform-provider-azurerm▸master$ make fmt build test
==> Fixing source code with gofmt...
# This logic should match the search logic in scripts/gofmtcheck.sh
gofmt -s -w `find . -name '*.go' | grep -v vendor`
==> Checking that code complies with gofmt requirements...
go install
# github.com/terraform-providers/terraform-provider-azurerm/azurerm
azurerm/config.go:195:43: undefined: sql.DatabaseThreatDetectionPoliciesClient
azurerm/config.go:199:39: undefined: sql.FirewallRulesClient
azurerm/config.go:200:39: undefined: sql.ServersClient
azurerm/config.go:201:39: undefined: sql.ServerAzureADAdministratorsClient
azurerm/config.go:202:39: undefined: sql.VirtualNetworkRulesClient
make: *** [build] Error 2
So i'm not sure if we can upgrade? Could you take a closer look?
I think we've worked around it by adding the tags manually. It's just I have an ops team I work with that get all jumpy when they see errors, so a more permanent fix is always appreciated.
Thanks for the detailed response.
@katbyte You read my mind I am currently seeing I can upgrade the existing resource. :)
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!