Victor Martinez
Victor Martinez

Reputation: 1170

Error creating sql server when applying terraform plan

I have the following resources to create a sql server and database using terraform

# Configure the Microsoft Azure Provider
provider "azurerm" {
  version = "0.2.2"
}

# ...

resource "azurerm_sql_server" "demo" {
  name                         = "${var.sql_server_name}"
  resource_group_name          = "${azurerm_resource_group.demo.name}"
  location                     = "${azurerm_resource_group.demo.location}"
  version                      = "12.0"
  administrator_login          = "${var.sql_server_account}"
  administrator_login_password = "${var.sql_server_password}"
}

# Create SQL Database
resource "azurerm_sql_database" "demo" {
   name = "demo"
   resource_group_name = "${azurerm_resource_group.demo.name}"
   location = "${azurerm_resource_group.demo.location}"

   server_name = "${azurerm_sql_server.demo.name}"
}

When I run terraform plan it says it will create these resources, but when running terraform apply I get this error:

Error applying plan:

1 error(s) occurred:

* azurerm_sql_server.demo: 1 error(s) occurred:

* azurerm_sql_server.demo: sql.ServersClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="Unknown" Message="Unknown service error"

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

I tried changing the version of the azurerm plugin I'm using, but nothing has changed. I use the azurerm plugin version 0.2.2, same error occurs with versions 0.2.1, 0.2.0 does not work with some other resources.

Upvotes: 0

Views: 1221

Answers (2)

Vinay MP
Vinay MP

Reputation: 37

I guess Terraform has some problem to propogate the error from Azure to the command line.

In my case there was a mismatch with the values supplied to the variables: edition requested_service_objective_name

Upvotes: 0

Victor Martinez
Victor Martinez

Reputation: 1170

It was silly, I looked into my azure logs and in turns out I was using the login name "admin" for sql server and that is not valid in the current version.

Upvotes: 1

Related Questions