@@ -78,7 +78,7 @@ required_version = ">= 0.14.0" # Takes into account Terraform versions from 0
78
78
source = " terraform-provider-openstack/openstack"
79
79
version = " >= 3.0.0"
80
80
}
81
-
81
+
82
82
ovh = {
83
83
source = " ovh/ovh"
84
84
version = " >= 2.1.0"
@@ -90,11 +90,9 @@ required_version = ">= 0.14.0" # Takes into account Terraform versions from 0
90
90
provider " openstack" {
91
91
auth_url = " https://auth.cloud.ovh.net/v3/" # Authentication URL
92
92
domain_name = " default" # Domain name - Always at 'default' for OVHcloud
93
- alias = " ovh" # An alias
94
93
}
95
94
96
95
provider " ovh" {
97
- alias = " ovh"
98
96
endpoint = " ovh-eu"
99
97
application_key = " <your_access_key>"
100
98
application_secret = " <your_application_secret>"
@@ -145,15 +143,13 @@ For example purposes, we will create a simple instance on **Debian 10** with the
145
143
``` python
146
144
# Creating an SSH key pair resource
147
145
resource " openstack_compute_keypair_v2" " test_keypair" {
148
- provider = openstack.ovh # Provider name declared in provider.tf
149
146
name = " test_keypair" # Name of the SSH key to use for creation
150
147
public_key = file (" ~/.ssh/id_rsa.pub" ) # Path to your previously generated SSH key
151
148
}
152
-
149
+
153
150
# Creating the instance
154
151
resource " openstack_compute_instance_v2" " test_terraform_instance" {
155
152
name = " terraform_instance" # Instance name
156
- provider = openstack.ovh # Provider name
157
153
image_name = " Debian 10" # Image name
158
154
flavor_name = " d2-2" # Instance type name
159
155
# Name of openstack_compute_keypair_v2 resource named keypair_test
@@ -162,7 +158,7 @@ resource "openstack_compute_instance_v2" "test_terraform_instance" {
162
158
name = " Ext-Net" # Adds the network component to reach your instance
163
159
}
164
160
lifecycle {
165
- # OVHcloud regularly updates the base image of a given OS so that customer has less packages to update after spawning a new instance
161
+ # OVHcloud regularly updates the base image of a given OS so that customer has less packages to update after spawning a new instance
166
162
# To avoid terraform to have some issue with that, the following ignore_changes is required.
167
163
ignore_changes = [
168
164
image_name
@@ -281,22 +277,20 @@ To do this, we will create a file named `multiple_instance.tf`. In it, we first
281
277
type = list
282
278
default = [" GRA11" , " SBG5" , " BHS5" ]
283
279
}
284
-
280
+
285
281
# Creating an SSH key pair
286
282
resource " openstack_compute_keypair_v2" " test_keypair_all" {
287
283
count = length(var.region)
288
- provider = openstack.ovh # Specify provider name
289
284
name = " test_keypair_all" # Name of the SSH key
290
285
public_key = file (" ~/.ssh/id_rsa.pub" ) # Your SSH key path
291
286
region = element(var.region, count.index)
292
287
}
293
-
288
+
294
289
# Create a resource that is an OpenStack instance in each region
295
290
resource " openstack_compute_instance_v2" " instances_on_all_regions" {
296
291
# Number of times the resource will be created
297
292
# defined by the length of the list named region
298
293
count = length(var.region)
299
- provider = openstack.ovh # Provider name
300
294
name = " terraform_instances" # Instance name
301
295
flavor_name = " d2-2" # Instance flavor
302
296
image_name = " Debian 10" # Image name
@@ -334,9 +328,8 @@ In this example we will attach a new storage volume to our first instance. Open
334
328
resource " openstack_blockstorage_volume_v2" " volume_to_add" {
335
329
name = " simple_volume" # Volume name
336
330
size = 10 # Volume size in GB
337
- provider = openstack.ovh # Provider name
338
331
}
339
-
332
+
340
333
# Attach the volume created previously to the instance
341
334
resource " openstack_compute_volume_attach_v2" " attached" {
342
335
# ID of openstack_compute_instance_v2 resource named test_terraform_instance
@@ -381,18 +374,17 @@ variable "region" {
381
374
resource " ovh_vrack_cloudproject" " vcp" {
382
375
service_name = var.service_name
383
376
project_id = var.project_id
384
- }
377
+ }
385
378
386
379
# Creating a private network
387
380
resource " ovh_cloud_project_network_private" " network" {
388
381
service_name = var.service_name
389
382
name = " private_network" # Network name
390
383
regions = [var.region]
391
- provider = ovh.ovh # Provider name
392
384
vlan_id = 168 # VLAN ID for vRack
393
385
depends_on = [ovh_vrack_cloudproject.vcp] # Depends on the vRack's association with the cloud project
394
386
}
395
-
387
+
396
388
# Creating a subnet using the previously created private network
397
389
resource " ovh_cloud_project_network_private_subnet" " subnet" {
398
390
service_name = var.service_name
@@ -403,13 +395,11 @@ variable "region" {
403
395
network = " 192.168.168.0/24" # Subnet IP address location
404
396
dhcp = true # Enables DHCP
405
397
region = var.region
406
- provider = ovh.ovh # Provider name
407
398
no_gateway = true # No default gateway
408
399
}
409
-
400
+
410
401
# Creating an instance with 2 network interfaces
411
402
resource " openstack_compute_instance_v2" " proxy_instance" {
412
- provider = openstack.ovh # Provider name
413
403
name = " proxy_instance" # Instance name
414
404
image_name = " Debian 10" # Image name
415
405
flavor_name = " d2-2" # Flavor name
@@ -465,12 +455,11 @@ variable myregion {
465
455
resource " ovh_cloud_project_network_private" " private_network" {
466
456
service_name = var.service_name
467
457
name = " backend" # Network name
468
- regions = [var.myregion]
469
- provider = ovh.ovh # Provider name
458
+ regions = [var.myregion]
470
459
vlan_id = 42 # vRack vlan ID
471
460
depends_on = [ovh_vrack_cloudproject.vcp] # Depends on vRack being associated with the cloud project
472
461
}
473
-
462
+
474
463
# Creating a private subnet
475
464
resource " ovh_cloud_project_network_private_subnet" " private_subnet" {
476
465
# ID for the ovh_cloud_network_private resource named private_network
@@ -481,27 +470,24 @@ resource "ovh_cloud_project_network_private_subnet" "private_subnet" {
481
470
start = " 192.168.42.2" # First IP of the subnet
482
471
end = " 192.168.42.200" # Last IP of the subnet
483
472
dhcp = false # Disabling DHCP
484
- provider = ovh.ovh # Provider name
485
473
no_gateway = true # No default gateway
486
474
}
487
-
475
+
488
476
# Search for the latest Archlinux image
489
477
data " openstack_images_image_v2" " archlinux" {
490
478
name = " Archlinux" # Image name
491
479
most_recent = true # Limits search to the most recent
492
- provider = openstack.ovh # Provider name
493
480
}
494
-
481
+
495
482
# List of possible private IP addresses for front-ends
496
483
variable " front_private_ip" {
497
484
type = list (any )
498
485
default = [" 192.168.42.2" , " 192.168.42.3" ]
499
486
}
500
-
487
+
501
488
# Create 2 instances with 2 network interfaces
502
489
resource " openstack_compute_instance_v2" " front" {
503
490
count = length(var.front_private_ip) # Number of instances to create
504
- provider = openstack.ovh # Provider name
505
491
name = " front" # Instance name
506
492
key_pair = openstack_compute_keypair_v2.test_keypair.name
507
493
flavor_name = " d2-2" # Instance type name
@@ -518,17 +504,15 @@ resource "openstack_compute_instance_v2" "front" {
518
504
}
519
505
depends_on = [ovh_cloud_project_network_private_subnet.private_subnet] # Depends on private network
520
506
}
521
-
507
+
522
508
# Create an attachable storage device for the backup (volume)
523
509
resource " openstack_blockstorage_volume_v2" " backup" {
524
510
name = " backup_disk" # Name of storage device
525
511
size = 10 # Size
526
- provider = openstack.ovh # Provider name
527
512
}
528
-
513
+
529
514
# Create an instance with a network interface and storage device
530
515
resource " openstack_compute_instance_v2" " back" {
531
- provider = openstack.ovh # Provider name
532
516
name = " back" # Instance name
533
517
key_pair = openstack_compute_keypair_v2.test_keypair.name
534
518
flavor_name = " d2-2" # Instance type name
0 commit comments