Terraform-provider-azurerm: Updating MSSQL Database fails

Created on 17 Jan 2019  ·  6Comments  ·  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform 0.11.11
Azurerm 1.21

Affected Resource(s)

  • azurerm_sql_database

Terraform Configuration Files

```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"
}
}
```

Debug Output

Panic Output

n/a

Expected Behavior

The change here is adding a new tag. Nothing else on the resource changes.

Actual Behavior

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 {}

Steps to Reproduce

Ensure there is a sql db with an online secondary in a paired region. Changes to the secondary fail to apply

  1. terraform apply

Important Factoids

We've always had problems with secondary DBS not updating their service objectives when asked to by terraform, but this is new.

References

bug servicmssql

All 6 comments

@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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonaspetersorensen picture jonaspetersorensen  ·  32Comments

srusru picture srusru  ·  44Comments

hashibot picture hashibot  ·  43Comments

ben-lings-tessella picture ben-lings-tessella  ·  30Comments

hashibot picture hashibot  ·  48Comments