gpt4 book ai didi

openstack - 在 OVH 的 Openstack 上使用 Terraform 创建专用网络

转载 作者:行者123 更新时间:2023-12-03 08:19:31 30 4
gpt4 key购买 nike

我正在尝试使用 Terraform 在 OVH 的公共(public)云上部署一些 Openstack 实例。重点是(目前)在两个网络上有两个实例。每个实例都应该有一个外部 IP 地址(这不是问题)和一个私有(private)网络上的内部 IP 地址(这给我带来了麻烦)。

我的地形文件是:

resource "openstack_compute_keypair_v2" "keypair" {
provider = "openstack.ovh"
name = "jpin"
public_key = "${file("~/.ssh/id_rsa.pub")}"
region = "GRA3"
}

resource "openstack_networking_network_v2" "network_1" {
provider = "openstack.ovh"
name = "network_1"
admin_state_up = "true"
region = "GRA3"
}

resource "openstack_networking_subnet_v2" "subnet_1" {
provider = "openstack.ovh"
name = "subnet_1"
network_id = "${openstack_networking_network_v2.network_1.id}"
cidr = "192.168.199.0/24"
ip_version = 4
region = "GRA3"
enable_dhcp = true
}

resource "openstack_networking_port_v2" "port_1" {
provider = "openstack.ovh"
name = "port_1"
network_id = "${openstack_networking_network_v2.network_1.id}"
admin_state_up = "true"
region = "GRA3"

fixed_ip {
"subnet_id" = "${openstack_networking_subnet_v2.subnet_1.id}"
}
}

resource "openstack_networking_port_v2" "port_2" {
provider = "openstack.ovh"
name = "port_2"
network_id = "${openstack_networking_network_v2.network_1.id}"
admin_state_up = "true"
region = "GRA3"

fixed_ip {
"subnet_id" = "${openstack_networking_subnet_v2.subnet_1.id}"
}
}

resource "openstack_compute_instance_v2" "instance_1" {
provider = "openstack.ovh"
name = "instance_1"
security_groups = ["default"]
region = "GRA3"
key_pair = "${openstack_compute_keypair_v2.keypair.name}"
flavor_name = "s1-2"
image_name = "Debian 8 - Docker"

network = [
{
name = "Ext-Net"
},
{
port = "${openstack_networking_port_v2.port_1.id}"
},
]
}

resource "openstack_compute_instance_v2" "instance_2" {
provider = "openstack.ovh"
name = "instance_2"
security_groups = ["default"]
region = "GRA3"
key_pair = "${openstack_compute_keypair_v2.keypair.name}"
flavor_name = "s1-2"
image_name = "Debian 8 - Docker"

network {
port = "${openstack_networking_port_v2.port_2.id}"
}
}

{
name = "Ext-Net"
},

部分允许我将实例连接到外部世界。我的两个实例应该有 192.168.199.0/24 网络中的 IP 地址,但它们没有。他们没有 IP 地址,也没有路由来与该网络通信。但我知道他们有合适的 IP 地址:

enter image description here

在该屏幕截图中,instance_1 与外部连接良好(如预期)。 instance_1 和 instance_2 都有一个私有(private) IP 地址。但是:

root@instance-1:~# ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:b1:7c:ae brd ff:ff:ff:ff:ff:ff
inet 145.239.XXX.YY/32 brd 145.239.XXX.YY scope global eth0
valid_lft forever preferred_lft forever

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:6a:87:8e brd ff:ff:ff:ff:ff:ff

eth1 没有那个 IP 地址(192.168.199.2 或 .3)。并且没有到 192.168.199.0/24 子网的路由。

最佳答案

几天后,一切正常。不管供应商的支持是怎么说的,它似乎是一个错误:我没有改变任何东西,它突然无处不在。

编辑:几周后,我得到了以下代码:

小心复制/粘贴,我的 compute_instance 在一个模块中,因此所有那些 var

resource "ovh_publiccloud_private_network" "network" {
provider = "ovh.ovh"
project_id = "${var.tenant_id}"
name = "Private Network"
regions = "${values(var.regions)}"
}

resource "ovh_publiccloud_private_network_subnet" "subnet" {
provider = "ovh.ovh"
project_id = "${var.tenant_id}"
network_id = "${element(ovh_publiccloud_private_network.network.*.id, count.index)}"

start = FIRST_PRIVATE_IP
end = LAST_PRIVATE_IP
network = PRIVATE_SUBNET

count = "${length(var.regions)}"
region = "${element(values(var.regions), count.index)}"
}

resource "openstack_compute_instance_v2" "compute_instance" {
provider = "openstack.ovh"
region = "${var.region_id}"
key_pair = "${var.keypair}"
flavor_name = "${var.instance_flavor}"
image_name = "${var.instance_image}"

network = [
{
name = "Ext-Net"
},
{
name = "${var.private_network}"
fixed_ip_v4 = MY_PRIVATE_IP
},
]
}

我不再使用端口了。选择停止使用端口与该问题无关。

从 Debian 9 开始,实例可能会尝试将私有(private)接口(interface)配置为访问 Internet 的接口(interface)。这行不通。

关于openstack - 在 OVH 的 Openstack 上使用 Terraform 创建专用网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46423766/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com