首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ip_cidr_range From tf.vars“不是有效的IP CIDR范围:无效的CIDR地址”

ip_cidr_range From tf.vars“不是有效的IP CIDR范围:无效的CIDR地址”
EN

Stack Overflow用户
提问于 2022-05-13 16:19:09
回答 2查看 558关注 0票数 0

我创建了一个Terraform模块,用于在Google中部署VPC,其中的一部分是:

代码语言:javascript
复制
  resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
  name          = var.vpc_subnet_name
  ip_cidr_range = var.ip_cidr_range 
  region        = var.vpc_region
  network       = google_compute_network.vpc_network.id
  secondary_ip_range {
    range_name    = var.services_secondary_range_name
    ip_cidr_range = var.services_secondary_cidr_range
  }
  secondary_ip_range {
    range_name    = var.pods_secondary_range_name
    ip_cidr_range = var.pods_secondary_cidr_range
  }

tf计划访问的main.tf文件由Python更新,以提供唯一的CIDR范围,以确保部署的网络不重叠。这就设置了以下内容:

代码语言:javascript
复制
ip_cidr_range = "10.51.0.0/20"
pods_secondary_cidr_range = "10.52.0.0/20"
services_secondary_cidr_range = "10.53.0.0/20"

然而,信托基金计划抱怨:

*"ip_cidr_range“不是有效的IP CIDR范围:无效的CIDR地址:

用module.ic-vpc.google_compute_subnetwork.network-with-private-secondary-ip-ranges,

在..terraform/modules/ic/main.tf第11行中,资源"google_compute_subnetwork“中的”网络-具有-私有-次要-ip-范围“:11: ip_cidr_range = var.ip_cidr_range

"secondary_ip_range.0.ip_cidr_range“不是有效的IP CIDR范围:无效的CIDR地址:

在..terraform/ module.ic-vpc.google_compute_subnetwork.network-with-private-secondary-ip-ranges,/ic/main.tf第16行中,资源"google_compute_subnetwork“中的”网络-具有私有-次要-ip-范围“:16: ip_cidr_range = var.services_secondary_cidr_range

"secondary_ip_range.1.ip_cidr_range“不是有效的IP CIDR范围:无效的CIDR地址:

在..terraform/ module.ic-vpc.google_compute_subnetwork.network-with-private-secondary-ip-ranges,/ip/main.tf第20行中,资源"google_compute_subnetwork“中的”网络-具有私有-次要-ip-范围“:20: ip_cidr_range = var.pods_secondary_cidr_range

这些地址在我看来很好,除非我遗漏了一些明显的东西。还有什么会导致这个错误呢?

如果能对此提供任何帮助,我们将不胜感激。

编辑:

这不需要通过Cloud解决问题,这正是我需要复制的:

代码语言:javascript
复制
resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
  name          = var.vpc_subnet_name
  ip_cidr_range = "10.51.0.0/20"
  region        = "europe-west2"
  network       = google_compute_network.custom-test.id
  secondary_ip_range {
    range_name    = "services"
    ip_cidr_range = "10.52.0.0/20"
  }
   secondary_ip_range {
    range_name    = "pods"
    ip_cidr_range = "10.53.0.0/20"
  }
}

resource "google_compute_network" "custom-test" {
  name                    = "projectname-subnet-eu"
  auto_create_subnetworks = false
}
EN

回答 2

Stack Overflow用户

发布于 2022-05-16 09:48:59

你的子网有错误的CIDRS。如果您不确定它们应该如何,可以使用熔池子网函数为您的VPC提供正确的CIDR。例如:

代码语言:javascript
复制
> cidrsubnet("10.51.0.0/20", 4, 0)
"10.51.0.0/24"
> cidrsubnet("10.51.0.0/20", 4, 1)
"10.51.1.0/24"
> cidrsubnet("10.51.0.0/20", 4, 2)
"10.51.2.0/24"
> cidrsubnet("10.51.0.0/20", 4, 3)
"10.51.3.0/24"
票数 1
EN

Stack Overflow用户

发布于 2022-05-19 14:26:04

若要查找可使用的有效CIDR地址,https://github.com/GoogleCloudPlatform/networking-tools-python/tree/main/tools/cidr

希望这能解决你的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72232623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档