forked from ovh/pci-test
feat: Added exercise 3 and .gitignore
This commit is contained in:
parent
6ef29fd620
commit
a3da5e0425
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*/__pycache__
|
||||
**/.terraform/*
|
||||
**/*.tfstate
|
||||
**/*.tfstate.*
|
23
ex3/.terraform.lock.hcl
Normal file
23
ex3/.terraform.lock.hcl
Normal file
@ -0,0 +1,23 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/terraform-provider-openstack/openstack" {
|
||||
version = "1.42.0"
|
||||
constraints = "~> 1.42.0"
|
||||
hashes = [
|
||||
"h1:hpQ+kc+S2Nwcqqt0TtBdiLKJpaLxq5z2eKrA+kjoMq4=",
|
||||
"zh:116e297f03eb304819f8cffd66f25b77638435db2d612c2b1d56205cbbef485f",
|
||||
"zh:332411f8425caaa9ca799cc60ccbab188c6108fa2765032a5cb22a5df36b5fc5",
|
||||
"zh:3843cf3c563ae0348bcd41107508399df997a7293b2a3a79e73264be81dc456c",
|
||||
"zh:4d16af37327d36bb86913220b763ed6e599b47db7702948f019e535c5b9413d4",
|
||||
"zh:9557b325e4617977f0fec913673d2542556174811415417be7dee20f7ab2fec1",
|
||||
"zh:95b4754370eda28624f7dfcfdfc4016775bf6433535b60a8f3d99fd651e71afa",
|
||||
"zh:97c240eba6a179e5910c0afdee97f916ab4537b360db21143ab2dfb0919087e3",
|
||||
"zh:b231c1c988914f4f0be3115a432f50cf43c410867f8b3aff7e3bf7c31739c940",
|
||||
"zh:b3b105ee70e440d350d8fecf50d458ad7d4b9b4a3ab580e9b8ff1e3fec9a6b76",
|
||||
"zh:b531f02dca64486c302046d959770a6b32ac26fc6d1830582e9959d0384dbe20",
|
||||
"zh:b80a2e60dae300217f44318a74b7e45cfe7009a11b937f06fb07f677863cec59",
|
||||
"zh:f18e8dada1e2941585893c579d169bc908c68cb7b71406c47cafc0a3bdcddbe8",
|
||||
"zh:fbdc031f496fa1f80fcab41f1e3cf2e2f99b0266b685079b4a4c4c61720c914c",
|
||||
]
|
||||
}
|
58
ex3/main.tf
Normal file
58
ex3/main.tf
Normal file
@ -0,0 +1,58 @@
|
||||
resource "openstack_networking_router_v2" "rt" {
|
||||
name = "rt"
|
||||
admin_state_up = "true"
|
||||
external_network_id = var.network_external_id
|
||||
}
|
||||
|
||||
resource "openstack_networking_network_v2" "network_internal" {
|
||||
name = var.network_lan
|
||||
admin_state_up = "true"
|
||||
}
|
||||
|
||||
resource "openstack_networking_subnet_v2" "network_subnet" {
|
||||
name = var.network_lan
|
||||
network_id = openstack_networking_network_v2.network_internal.id
|
||||
cidr = var.network_subnet_cidr
|
||||
ip_version = 4
|
||||
enable_dhcp = true
|
||||
dns_nameservers = ["1.1.1.1"]
|
||||
}
|
||||
|
||||
resource "openstack_networking_router_interface_v2" "network_router_interface" {
|
||||
router_id = openstack_networking_router_v2.rt.id
|
||||
subnet_id = openstack_networking_subnet_v2.network_subnet.id
|
||||
}
|
||||
|
||||
resource "openstack_networking_floatingip_v2" "d2_fip" {
|
||||
pool = "Ext-Net"
|
||||
}
|
||||
|
||||
resource "openstack_compute_keypair_v2" "instance_keypair" {
|
||||
provider = openstack.ovh
|
||||
name = "instance_keypair"
|
||||
public_key = file(var.ssh_pubkey)
|
||||
}
|
||||
|
||||
resource "openstack_compute_instance_v2" "instance" {
|
||||
name = "d2_test"
|
||||
provider = openstack.ovh
|
||||
image_name = "Debian 12"
|
||||
flavor_name = "d2-4"
|
||||
key_pair = openstack_compute_keypair_v2.instance_keypair.name
|
||||
user_data = var.cloudinit_script
|
||||
network {
|
||||
name = var.network_lan
|
||||
}
|
||||
|
||||
depends_on = [ openstack_networking_subnet_v2.network_subnet ]
|
||||
}
|
||||
|
||||
data "openstack_networking_port_v2" "port" {
|
||||
device_id = openstack_compute_instance_v2.instance.id
|
||||
network_id = openstack_compute_instance_v2.instance.network.0.uuid
|
||||
}
|
||||
|
||||
resource "openstack_networking_floatingip_associate_v2" "fip_associate" {
|
||||
floating_ip = openstack_networking_floatingip_v2.d2_fip.address
|
||||
port_id = data.openstack_networking_port_v2.port.id
|
||||
}
|
13
ex3/providers.tf
Normal file
13
ex3/providers.tf
Normal file
@ -0,0 +1,13 @@
|
||||
terraform {
|
||||
required_version = ">= 0.14.0"
|
||||
required_providers {
|
||||
openstack = {
|
||||
source = "terraform-provider-openstack/openstack"
|
||||
version = "~> 1.42.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "openstack" {
|
||||
alias = "ovh"
|
||||
}
|
24
ex3/variables.tf
Normal file
24
ex3/variables.tf
Normal file
@ -0,0 +1,24 @@
|
||||
variable "network_external_id" {
|
||||
type = string
|
||||
default = "bcf59eb2-9d83-41cc-b4f5-0435ed594833"
|
||||
}
|
||||
|
||||
variable "network_lan" {
|
||||
type = string
|
||||
default = "lan_d2_demo"
|
||||
}
|
||||
|
||||
variable "network_subnet_cidr" {
|
||||
type = string
|
||||
default = "10.10.0.0/24"
|
||||
}
|
||||
|
||||
variable "ssh_pubkey" {
|
||||
type = string
|
||||
default = "~/.ssh/id_ed25519.pub"
|
||||
}
|
||||
|
||||
variable "cloudinit_script" {
|
||||
type = string
|
||||
default = "#!/bin/bash\nsudo apt update && sudo apt install -y nginx"
|
||||
}
|
Loading…
Reference in New Issue
Block a user