-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathterraform_test.tf
132 lines (115 loc) · 3.05 KB
/
terraform_test.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
variable "maas_url" {}
variable "apikey" {}
variable "test_machine_power_type" {}
variable "test_machine_power_address" {}
variable "test_machine_power_user" {}
variable "test_machine_power_password" {}
variable "test_machine_power_driver" {}
variable "test_machine_power_boot_type" {}
variable "test_machine_mac_address" {}
variable "pxe_subnet_cidr" {}
variable "distro_series" {
default = "ubuntu/jammy"
}
terraform {
required_providers {
maas = {
source = "terraform.maas.io/canonical/maas"
}
}
}
provider "maas" {
api_version = "2.0"
api_key = var.apikey
api_url = var.maas_url
}
resource "maas_space" "tf_test_space" {
name = "tf_test_space"
}
resource "maas_fabric" "tf_test_fabric" {
name = "tf_test_fabric"
}
resource "maas_vlan" "tf_test_vlan" {
name = "tf_test_vlan"
fabric = maas_fabric.tf_test_fabric.id
vid = 2
depends_on = [maas_fabric.tf_test_fabric]
}
resource "maas_subnet" "tf_test_subnet" {
name = "tf_test_subnet"
fabric = maas_fabric.tf_test_fabric.id
vlan = maas_vlan.tf_test_vlan.id
cidr = "10.10.10.0/24"
gateway_ip = "10.10.10.1"
dns_servers = ["1.1.1.1"]
ip_ranges {
type = "reserved"
start_ip = "10.10.10.1"
end_ip = "10.10.10.12"
}
ip_ranges {
type = "dynamic"
start_ip = "10.10.10.24"
end_ip = "10.10.10.56"
}
depends_on = [maas_vlan.tf_test_vlan]
}
data "maas_fabric" "fabric_0" {
name = "fabric-0"
}
data "maas_vlan" "vlan_0" {
fabric = data.maas_fabric.fabric_0.id
vlan = 0
}
data "maas_subnet" "pxe" {
cidr = var.pxe_subnet_cidr
}
resource "maas_dns_domain" "tf_test_domain" {
name = "tftest"
ttl = 3600
authoritative = true
}
# Re-enable when https://warthogs.atlassian.net/browse/MAASENG-2177 is ready
# resource "maas_dns_record" "tf_test_record" {
# type = "A/AAAA"
# data = "10.10.10.1"
# fqdn = "tftestrecord.${maas_dns_domain.tf_test_domain.name}"
# depends_on = [maas_dns_domain.tf_test_domain]
# }
resource "maas_machine" "tf_test_machine" {
power_type = var.test_machine_power_type
power_parameters = jsonencode({
power_address = var.test_machine_power_address
power_user = var.test_machine_power_user
power_pass = var.test_machine_power_password
power_driver = var.test_machine_power_driver
power_boot_type = var.test_machine_power_boot_type
})
pxe_mac_address = var.test_machine_mac_address
}
resource "maas_vm_host" "tf_test_vm_host" {
machine = maas_machine.tf_test_machine.id
type = "lxd"
timeouts {
create = "40m"
}
}
resource "maas_vm_host_machine" "tf_test_vm" {
vm_host = maas_vm_host.tf_test_vm_host.id
cores = 1
memory = 2048
}
resource "maas_instance" "tf_test_vm_instance" {
allocate_params {
hostname = maas_vm_host_machine.tf_test_vm.hostname
}
deploy_params {
distro_series = var.distro_series
}
}
resource "maas_vm_host_machine" "tf_test_vm_acceptance" {
hostname = "acceptance-vm"
vm_host = maas_vm_host.tf_test_vm_host.id
cores = 1
memory = 2048
}