Terraform IONOS 配置问题

问题描述 投票:0回答:1

我尝试了一切,但得到的都是错误。好心人,如果可以的话请帮忙。 我已阅读文档。我擅长 ansible,并认为 Terraform 会成为一个更简单的工具,但我想我错了。我花了很多时间来做这个,但它就是不想工作。还有几个文件,但我认为只有这个是导致所有错误的原因。


# Fetch Images Dynamically using data blocks
data "ionoscloud_image" "fw0_image" {
  image_alias = "OPNsense:latest"
  location    = "de/txl"
}

data "ionoscloud_image" "windows_2022_image" {
  image_alias = "Windows-Server-2022:latest"
  location    = "de/txl"
}

data "ionoscloud_image" "ubuntu_22_04_image" {
  image_alias = "Ubuntu-22.04:latest"
  location    = "de/txl"
}

# Create New Data Center
resource "ionoscloud_datacenter" "new_vdc" {
  name        = "CGM Medical IaaS - New Clone"
  location    = "de/txl"
  description = "Clone of CGM Medical IaaS - M1"
}

# LAN Setup
resource "ionoscloud_lan" "lan1" {
  datacenter_id = ionoscloud_datacenter.new_vdc.id
  public        = true
  name          = "LAN1"
}

resource "ionoscloud_lan" "lan2" {
  datacenter_id = ionoscloud_datacenter.new_vdc.id
  public        = false
  name          = "LAN2"
}

resource "ionoscloud_lan" "lan3" {
  datacenter_id = ionoscloud_datacenter.new_vdc.id
  public        = false
  name          = "LAN3"
}

# Firewall Server (FW0)
resource "ionoscloud_server" "fw0" {
  datacenter_id     = ionoscloud_datacenter.new_vdc.id
  name              = "FW0"
  cores             = 2
  ram               = 4096
  availability_zone = "AUTO"
  cpu_family        = "AMD_EPYC"
  type              = "ENTERPRISE"

  volume {
    name              = "FW0_BOOT_DISK"
    size              = 80
    disk_type         = "SSD"
    bus               = "VIRTIO"
    image_name        = data.ionoscloud_image.fw0_image.name
  }

  nic {
    lan             = ionoscloud_lan.lan1.id
    name            = "FW0_NIC0_LAN1"
    dhcp            = true
    firewall_active = false
  }
}

# Domain Controller (DC0)
resource "ionoscloud_server" "dc0" {
  datacenter_id     = ionoscloud_datacenter.new_vdc.id
  name              = "DC0"
  cores             = 4
  ram               = 8192
  availability_zone = "AUTO"
  cpu_family        = "AMD_EPYC"
  type              = "ENTERPRISE"

  volume {
    name              = "DC0_BOOT_DISK"
    size              = 160
    disk_type         = "SSD"
    bus               = "VIRTIO"
    image_name        = data.ionoscloud_image.windows_2022_image.name
  }

  nic {
    lan             = ionoscloud_lan.lan2.id
    name            = "DC0_NIC0_LAN2"
    dhcp            = true
    firewall_active = false
  }
}

# M1 Server (M1SRV)
resource "ionoscloud_server" "m1srv" {
  datacenter_id     = ionoscloud_datacenter.new_vdc.id
  name              = "M1SRV"
  cores             = 8
  ram               = 32768
  availability_zone = "AUTO"
  cpu_family        = "AMD_EPYC"
  type              = "ENTERPRISE"

  volume {
    name              = "M1SRV_BOOT_DISK"
    size              = 640
    disk_type         = "SSD"
    bus               = "VIRTIO"
    image_name        = var.m1srv_snapshot_id
  }

  nic {
    lan             = ionoscloud_lan.lan2.id
    name            = "M1SRV_NIC0_LAN2"
    dhcp            = true
    firewall_active = false
  }
}

# Monitoring Proxy (MONPROX)
resource "ionoscloud_server" "monprox" {
  datacenter_id     = ionoscloud_datacenter.new_vdc.id
  name              = "MONPROX"
  cores             = 1
  ram               = 2048
  availability_zone = "AUTO"
  cpu_family        = "AMD_EPYC"
  type              = "ENTERPRISE"

  volume {
    name              = "MONPROX_BOOT_DISK"
    size              = 50
    disk_type         = "SSD"
    bus               = "VIRTIO"
    image_name        = data.ionoscloud_image.ubuntu_22_04_image.name
  }

  nic {
    lan             = ionoscloud_lan.lan2.id
    name            = "MONPROX_NIC0_LAN2"
    dhcp            = true
    firewall_active = false
  }
}

# Terminal Servers (TS0 and TS1)
resource "ionoscloud_server" "ts" {
  count             = var.ts_count
  datacenter_id     = ionoscloud_datacenter.new_vdc.id
  name              = "TS${count.index}"
  cores             = 6
  ram               = 16384
  availability_zone = "AUTO"
  cpu_family        = "AMD_EPYC"
  type              = "ENTERPRISE"

  volume {
    name              = "TS${count.index}_BOOT_DISK"
    size              = 320
    disk_type         = "SSD"
    bus               = "VIRTIO"
    image_name        = data.ionoscloud_image.windows_2022_image.name
  }

  nic {
    lan             = ionoscloud_lan.lan2.id
    name            = "TS${count.index}_NIC0_LAN2"
    dhcp            = true
    firewall_active = false
  }
}

# Cross Connect
resource "ionoscloud_private_crossconnect" "cross_connect" {
  name         = "Cross Connect"
  description  = "Cross Connecting with M1-MGMT"

  peers {
    lan_id = ionoscloud_lan.lan1.id
  }

  peers {
    lan_id = ionoscloud_lan.lan2.id
  }

  peers {
    lan_id = ionoscloud_lan.lan3.id
  }
}

我做了很多事情,我什至尝试咨询chatgpt,但这只带来了更多错误。我做错了什么。我想如果我设法修复一个错误,我就能修复所有错误。

 Error: Unsupported argument
│
│   on main.tf line 58, in resource "ionoscloud_server" "fw0":
│   58:     image_name        = data.ionoscloud_image.fw0_image.name
│
│ An argument named "image_name" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│   on main.tf line 84, in resource "ionoscloud_server" "dc0":
│   84:     image_name        = data.ionoscloud_image.windows_2022_image.name
│
│ An argument named "image_name" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│   on main.tf line 110, in resource "ionoscloud_server" "m1srv":
│  110:     image_name        = var.m1srv_snapshot_id
│
│ An argument named "image_name" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│   on main.tf line 136, in resource "ionoscloud_server" "monprox":
│  136:     image_name        = data.ionoscloud_image.ubuntu_22_04_image.name
│
│ An argument named "image_name" is not expected here.
╵
╷
│ Error: Unsupported argument
│
│   on main.tf line 163, in resource "ionoscloud_server" "ts":
│  163:     image_name        = data.ionoscloud_image.windows_2022_image.name
│
│ An argument named "image_name" is not expected here.

terraform devops ionos
1个回答
0
投票

image_name
内没有
volume
字段。您应该将
image_name=<image-name>
替换为
ionoscloud_server
。这是一个例子:

# Firewall Server (FW0)
resource "ionoscloud_server" "fw0" {
  datacenter_id     = ionoscloud_datacenter.new_vdc.id
  name              = "FW0"
  cores             = 2
  ram               = 4096
  availability_zone = "AUTO"
  cpu_family        = "AMD_EPYC"
  type              = "ENTERPRISE"
  image_name        = data.ionoscloud_image.fw0_image.name

  volume {
    name              = "FW0_BOOT_DISK"
    size              = 80
    disk_type         = "SSD"
    bus               = "VIRTIO"
  }

  nic {
    lan             = ionoscloud_lan.lan1.id
    name            = "FW0_NIC0_LAN1"
    dhcp            = true
    firewall_active = false
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.