Terraform - Creating Google Cloud SQL instance not working - google-cloud-platform

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.

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!

Related

error waiting for API Gateway Stage (ags-1suu2m3o7a-dev) to be available: unexpected state 'NOT_AVAILABLE', wanted target 'AVAILABLE'. last error

I use Terraform in order to create Api gateway stage, but when I try to set cache_cluster_enabled = false always I receive an error:
error waiting for API Gateway Stage (ags-1suu2m3o7a-dev) to be
available: unexpected state 'NOT_AVAILABLE', wanted target
'AVAILABLE'. last error: %!s()
resource "aws_api_gateway_stage" "example" {
cache_cluster_enabled = false
cache_cluster_size = 0.5
...
}
Seems for now you need to switch aws version to 3.73.0 according to this issue https://github.com/hashicorp/terraform-provider-aws/issues/22866 it will be fixed in future updates

AWS rds Layer version does not exist" when trying to deploy from serverless

I am trying to deploy a stack using serverless but I am getting this error that the layer version 31 doesn't exist while the latest version I am having is 33 which I have updated in the config file as well.
Here is the Config File:
module.exports.layerArn = "arn:aws:lambda:eu-hhjhj-:13245460551:layer:rds:33"
module.exports.securityGroupIds = "sg-0bb9bb454646451da"
module.exports.subnetIds = "subnet-07d5454664669frdtc"
module.exports.lambdaApiDatabaseAccessRole = "arn:aws:iam::13345353531:role/lambda-api-
database-access-Role-OM-AWS-SAAS-DEV-EU1"
module.exports.ctrStream = "arn:aws:kinesis:eu-central-1:1335353666551:stream/stream-ctr-
bucket"
module.exports.agentEventStream = "arn:aws:kinesis:eu-central-
1:13251:stream/KinesisStreamEvents"
module.exports.domainName = "91h7syppl4eu-central-1.amazonaws.com"
module.exports.stage = "dev"
Here is the full error message:
An error occurred: GetCallTranscriptAndRecordingLambdaFunction - Resource handler returned message:
"Layer version arn:aws:lambda:eu-central-1:132334r43r341:layer:rds:31 does not exist.
(Service: Lambda, Status Code: 400, Request ID: 681468f7-62dd-485a-bc34-180745456f9a)"
(RequestToken: 32eb7c85-1b21-2217-0e87-0a0229c454d2, HandlerErrorCode: InvalidRequest).
Any help would be appreciated
This question is resolved. the problem was with layer arn. after updating the layer arn, the stack deployed successfully.

STANDARD network tier is not supported for global address

I'd like to add an A-type DNS name on GCP with the following Terraform code:
data "google_dns_managed_zone" "env_dns_zone" {
name = "env-zone"
}
resource "google_compute_global_address" "argo_events_webhook" {
name = "argo-events-webhook"
}
/*
resource "google_dns_record_set" "argo-events-webhook" {
name = "argo-events-webhook.${data.google_dns_managed_zone.env_dns_zone.dns_name}"
managed_zone = data.google_dns_managed_zone.env_dns_zone.name
rrdatas = [google_compute_global_address.argo_events_webhook.address]
ttl = 600
type = "A"
}
*/
(The out commented part is not causing the error but maybe relevant as it shows more info about what I want to achieve)
But this yields the following error message ...
...
module.gke.google_compute_global_address.argo_events_webhook: Creating...
Error: Error creating GlobalAddress: googleapi: Error 400: STANDARD network tier (the project's default network tier) is not supported: STANDARD network tier is not supported for global address., badRequest
... for which I can't find more information. Does somebody have an idea how to solve this?
What I find confusing is that there are A-level entries added and my terraform code is c/p'ed from their corresponding tf code (+ adjustment of names).
The Standard Network Tier doesn't use the Google global fiber network and use the "standard internet", locally to the region. If you use global address, the address is globally reachable and thus you need to use the premium network tier to access to this feature.
more details here
In your case, you have to update the project configuration to Premium Network Tier. You can achieve this with Terraform
resource "google_compute_project_default_network_tier" "default" {
network_tier = "PREMIUM"
}

Error while creating a TPU: "cannot be less than the existing policy version"

I am trying to create a TPU using GC console:
ctpu up --name=daniels-tpu --zone=us-central1-b --tpu-size=v3-8 --tf-version=1.15 --tpu-only -noconf --require-permissions
and I am getting the following error:
ctpu will use the following configuration:
Name: daniels-tpu2
Zone: us-central1-b
GCP Project: ai2-aristo
TensorFlow Version: 1.15
Cloud TPU:
Size: v3-8
Preemptible: false
Reserved: false
OK to create your Cloud TPU resources with the above configuration? [Yn]: y
2020/01/31 21:12:21 Creating TPU daniels-tpu2 (this may take a few minutes)...
2020/01/31 21:12:28 TPU operation still running...
2020/01/31 21:12:49 TPU operation still running...
2020/01/31 21:13:10 TPU operation still running...
2020/01/31 21:13:31 TPU operation still running...
2020/01/31 21:13:36 Created TPU daniels-tpu2!
2020/01/31 21:13:36 Error adding the TPU's service account to the project's access control lists: &googleapi.Error{Code:400, Message:"Requested policy version (1) cannot be less than the existing policy versi
on (3). For more information, please refer to https://cloud.google.com/iam/docs/policies#versions.", Body:"{\n \"error\": {\n \"code\": 400,\n \"message\": \"Requested policy version (1) cannot be less
than the existing policy version (3). For more information, please refer to https://cloud.google.com/iam/docs/policies#versions.\",\n \"errors\": [\n {\n \"message\": \"Requested policy versio
n (1) cannot be less than the existing policy version (3). For more information, please refer to https://cloud.google.com/iam/docs/policies#versions.\",\n \"domain\": \"global\",\n \"reason\": \
"badRequest\"\n }\n ],\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n", Header:http.Header(nil), Errors:[]googleapi.ErrorItem{googleapi.ErrorItem{Reason:"badRequest", Message:"Requested policy versio
n (1) cannot be less than the existing policy version (3). For more information, please refer to https://cloud.google.com/iam/docs/policies#versions."}}}
googleapi: Error 400: Requested policy version (1) cannot be less than the existing policy version (3). For more information, please refer to https://cloud.google.com/iam/docs/policies#versions., badRequest
Any thoughts?
I was able to create the TPU instance successfully with the same command. Have you tried using a different zone?
I also found a thread that I believe could be very useful.

Terraform: google_sql_database_instance not being created

I am trying to create a CloudSQL instance using terraform but its not even trying to create it appears: The CloudSQL dashboard doesnt change
google_sql_database_instance.db-instance: Still creating... [9m41s elapsed]
google_sql_database_instance.db-instance: Still creating... [9m51s elapsed]
google_sql_database_instance.db-instance: Still creating... [10m1s elapsed]
It eventually timesout. Why is that?
resource "google_sql_database_instance" "db-instance" {
# depends_on = [google_service_networking_connection.private-vpc-connection]
name = "sonarqube"
database_version = "POSTGRES_9_6"
region = "asia-southeast1"
settings {
tier = "db-f1-micro"
# ip_configuration {
# private_network = google_compute_network.private-network.self_link
# }
}
}
I even removed the private networking parts
Ok, so I set TF_LOG=DEBUG and saw
2019-11-23T22:04:41.365+0800 [DEBUG] plugin.terraform-provider-google-beta_v3.0.0-beta.1_x4: 2019/11/23 22:04:41 [DEBUG] Dismissed an error as retryable. Waiting for other concurrent Cloud SQL operations to finish - googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState
After some googling, I found https://github.com/hashicorp/terraform/issues/20972
This happens because instance names cannot be reused for up to a week after it's deleted.
So I guess the issue is because I am attempting to create an instance with a name that was recently used ...