Hi everyone.
I’m trying to create datastream profile in terraform, which data source is AlloyDB.
But it fails with the following error messages.
╷
│ Error: Error waiting to create ConnectionProfile: Error waiting for Creating ConnectionProfile: {"@type":"type.googleapis.com/google.rpc.ErrorInfo","domain":"datastream.googleapis.com","metadata":{"message":"We timed out trying to connect to the data source. Make sure that the hostname and port configuration is correct, and that the data source is available.","originalMessage":"timeout expired\n","time":"2023-07-03T17:24:57.012014Z","uuid":"e5cee153-8b4c-40ea-a222-eee20628dc28"},"reason":"CONNECTION_TIMEOUT"}
│ {"code":"VALIDATE_CONNECTIVITY","description":"Validates that Datastream can connect to the source database.","message":[{"code":"CONNECTION_TIMEOUT","level":"ERROR","message":"We timed out trying to connect to the data source. Make sure that the hostname and port configuration is correct, and that the data source is available.","metadata":{"original_error":"timeout expired\n"}}],"state":"FAILED"}
│
│
│
│ with google_datastream_connection_profile.alloydb,
│ on datastream.tf line 4, in resource "google_datastream_connection_profile" "alloydb":
│ 4: resource "google_datastream_connection_profile" "alloydb" {
│
╵
I followed the instructions of this document , and this is the code I wrote:
module "gce-container" {
source = "terraform-google-modules/container-vm/google"
version = "~> 2.0"
container = {
image = "gcr.io/dms-images/tcp-proxy"
env = [
{
name = "SOURCE_CONFIG"
value = "${var.alloydb.hostname}:5432"
}
],
}
}
resource "google_compute_instance" "ds-tcp-proxy" {
project = var.project_id
name = "ds-tcp-proxy"
machine_type = "e2-micro"
zone = var.default_zone
tags = ["ds-tcp-proxy"]
boot_disk {
initialize_params {
image = module.gce-container.source_image
}
}
network_interface {
network = google_compute_network.vpc_network.id
subnetwork = google_compute_subnetwork.tcp_proxy_datastream.id
}
can_ip_forward = true
metadata = {
gce-container-declaration = module.gce-container.metadata_value
google-logging-enabled = "true"
google-monitoring-enabled = "true"
}
labels = {
container-vm = module.gce-container.vm_container_label
}
}
resource "google_compute_firewall" "ds_proxy" {
name = "ds-proxy"
project = var.project_id
network = google_compute_network.vpc_network.id
allow {
protocol = "tcp"
ports = ["5432"]
}
source_ranges = ["10.1.0.0/29"]
direction = "INGRESS"
priority = 1000
target_tags = ["ds-tcp-proxy"]
}
resource "google_datastream_connection_profile" "alloydb" {
display_name = "AlloyDB Connection profile"
location = var.default_region
connection_profile_id = "alloydb-connection-profile"
project = var.project_id
postgresql_profile {
hostname = google_compute_instance.ds-tcp-proxy.network_interface["0"].network_ip
port = 5432
username = sensitive(var.alloydb.username)
password = sensitive(var.alloydb.password)
database = "postgres"
}
private_connectivity {
private_connection = google_datastream_private_connection.main.id
}
}
resource "google_datastream_private_connection" "main" {
display_name = "Datastream Private Connection"
location = var.default_region
private_connection_id = "ds-private-connection"
project = var.project_id
vpc_peering_config {
vpc = google_compute_network.vpc_network.id
subnet = "10.1.0.0/29"
}
}
when using the username and password of variables.tf, I can log in with psql.
Also, the region and location is the same in all resources.
Will you kindly tell me what is the problem?
Thanks.