6
votes

I use the following Terraform configuration to try to create a subnet and a Cloud SQL MySQL 5.6 instance on Google Cloud Platform.

resource "google_compute_network" "default" {
  name = "my-default-network"
  auto_create_subnetworks = "true"
  project = "${google_project.project.project_id}"
}

resource "google_sql_database_instance" "wordpress" {
  region = "${var.region}"
  database_version = "MYSQL_5_6"
  project = "${google_project.project.project_id}"

  settings {
    tier = "db-n1-standard-1"

    ip_configuration {
      private_network = "${google_compute_network.default.self_link}"
    }
  }
}

But applying this plan gives me the following vague error. I also tried to destroy the entire project and tried to build it up again, but I get the same error.

google_sql_database_instance.wordpress: Still creating... (20s elapsed)
google_sql_database_instance.wordpress: Still creating... (30s elapsed)
google_sql_database_instance.wordpress: Still creating... (40s elapsed)

Error: Error applying plan:

1 error(s) occurred:

* google_sql_database_instance.wordpress: 1 error(s) occurred:

* google_sql_database_instance.wordpress: Error waiting for Create Instance:


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.

Can anyone see what I do wrong here?

Edit:

When adding TF_LOG=debug to the terraform apply-run, I get the following error.

"error": {
  "kind": "sql#operationErrors",
  "errors": [{
    "kind": "sql#operationError",
    "code": "INTERNAL_ERROR"
  }]
}

Edit 2: Simplified the network setup, but getting the exact same error.

1
can you delete the created db instance and try to deploy it again? Will this fix the problem?BMW
The instance was never created, but I did try to destroy the entire environment and recreate it. Same thing.pkhamre
I've run into the same issue from terraform based cloud console creating a PSQL 9.6 db. The cloud console logs don't seem to have more information either.akaltar

1 Answers

1
votes

A bit late to the party but I have just had and overcome this issue. In my case it was related to using the private_networking option. My suggestion is to read the documentation paying attention to the "Network Requirements" and check the following:

  • You have the servicenetworking.googleapis.com API enabled in your project
  • The ServiceAccount you are running with Terraform has the "Service Network Admin" role

I found that verifying private networking was the issue (by removing it and setting ipv4_enabled = "true") in a temporary instance helped focus my debugging efforts.

Good Luck!