【问题标题】:Want to create a cloud sql instance with private and public ip on a separate vpc in gcp using terraform想要使用 terraform 在 gcp 中的单独 vpc 上创建具有私有和公共 ip 的云 sql 实例
【发布时间】:2020-07-15 19:46:12
【问题描述】:

我尝试使用 terraform 在单独的 vpc 中配置具有私有和公共 ip 的云 sql 实例。可以从单独的 vpc 在该实例上分配私有 ip,但无法同时分配公共 ip。

这是我的代码。

resource "google_compute_global_address" "private_ip_address" {
  provider = google-beta

  name          = "private-ip-address"
  purpose       = "VPC_PEERING"
  address_type  = "INTERNAL"
  prefix_length = 16
  network       = "${var.vpc_self_link}"
}

resource "google_service_networking_connection" "private_vpc_connection" {
  provider = google-beta

  network                 = "${var.vpc_self_link}"
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]
}


# create database instance
resource "google_sql_database_instance" "instance" {
        name = "test-${var.project_id}"
        region = "us-central1"
        database_version = "${var.db_version}"

        depends_on = [google_service_networking_connection.private_vpc_connection]

        settings {
                tier = "${var.db_tier}"
                activation_policy = "${var.db_activation_policy}"
                disk_autoresize = "${var.db_disk_autoresize}"
                disk_size = "${var.db_disk_size}"
                disk_type = "${var.db_disk_type}"
                pricing_plan = "${var.db_pricing_plan}"

                database_flags {
                        name  = "slow_query_log"
                        value = "on"
                }

                ip_configuration {
                        ipv4_enabled = "false"
                        private_network = "projects/${var.project_id}/global/networks/${var.vpc_name}"
                }
        }
}

但是当我尝试传递以下参数 - 分配公共 ip 时,由于 private_network 标志而出错。

ipv4_enabled = "true"

请让我知道如何从自定义或单独的 vpc(不是默认)中找出私有和公共 ip 的问题。

【问题讨论】:

    标签: google-cloud-platform terraform google-cloud-sql terraform-provider-gcp


    【解决方案1】:

    根据the documentation,你不能

    ipv4_enabled -(可选)是否应为此 Cloud SQL 实例分配公共 IPV4 地址。必须启用 ipv4_enabled 或必须配置 private_network。

    打开功能请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-05
      • 2020-09-23
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 2020-12-30
      • 2013-09-30
      • 1970-01-01
      相关资源
      最近更新 更多