This commit is contained in:
parent
125179c28e
commit
e5d4c577f8
52
.drone.yml
Normal file
52
.drone.yml
Normal file
@ -0,0 +1,52 @@
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
name: Terraform
|
||||
|
||||
steps:
|
||||
- name: Terraform Init
|
||||
image: bv11-cr01.bessems.eu/library/packer-extended
|
||||
commands:
|
||||
- |
|
||||
terraform init \
|
||||
-chdir=terraform \
|
||||
-input=false \
|
||||
-backend-config="conn_str=${PG_CONNECTIONSTRING}"
|
||||
environment:
|
||||
PG_CONNECTIONSTRING: postgres://${PG_USERNAME}:${PG_PASSWORD}@${PG_HOST}/${PG_DATABASE}?sslmode=disable
|
||||
PG_HOST: tfstate.default.svc.cluster.local
|
||||
PG_DATABASE: terraform_backend
|
||||
PG_USERNAME: terraform
|
||||
PG_PASSWORD: terraform
|
||||
TF_AUTOMATION: yes
|
||||
# TF_LOG: TRACE
|
||||
- name: Terraform Plan
|
||||
image: bv11-cr01.bessems.eu/library/packer-extended
|
||||
commands:
|
||||
- |
|
||||
terraform plan \
|
||||
-var='vsphere_password=$${VSPHERE_PASSWORD}' -var='repo_username=$${REPO_USERNAME}' -var='repo_password=$${REPO_PASSWORD}' \
|
||||
-var-file='vsphere.tfvars' \
|
||||
-chdir=terraform \
|
||||
-input=false \
|
||||
-out=terraform.plan
|
||||
environment:
|
||||
TF_AUTOMATION: yes
|
||||
VSPHERE_PASSWORD:
|
||||
from_secret: vsphere_password
|
||||
REPO_USERNAME:
|
||||
from_secret: repo_username
|
||||
REPO_PASSWORD:
|
||||
from_secret: repo_password
|
||||
# TF_LOG: TRACE
|
||||
- name: Terraform Apply
|
||||
image: bv11-cr01.bessems.eu/library/packer-extended
|
||||
commands:
|
||||
- |
|
||||
terraform apply \
|
||||
-chdir=terraform \
|
||||
-input=false \
|
||||
-auto-approve \
|
||||
terraform.plan
|
||||
environment:
|
||||
TF_AUTOMATION: yes
|
||||
# TF_LOG: TRACE
|
28
terraform/contentlibrary.tf
Normal file
28
terraform/contentlibrary.tf
Normal file
@ -0,0 +1,28 @@
|
||||
resource "vsphere_content_library" "library" {
|
||||
name = "OVA appliances"
|
||||
storage_backing = flatten([
|
||||
data.vsphere_datastore.cldatastore.id
|
||||
])
|
||||
}
|
||||
|
||||
resource "vsphere_content_library_item" "Server2019" {
|
||||
name = "Windows-Server-2019-LTSC"
|
||||
library_id = vsphere_content_library.library.id
|
||||
file_url = "https://{{user `repo_username`}}:{{user `repo_password`}}@sn.itch.fyi/Repository/rel/Windows-Server-2019-LTSC.ova"
|
||||
}
|
||||
resource "vsphere_content_library_item" "ADCS" {
|
||||
name = "ADCS-appliance"
|
||||
library_id = vsphere_content_library.library.id
|
||||
file_url = "https://{{user `repo_username`}}:{{user `repo_password`}}@sn.itch.fyi/Repository/rel/ADCS-appliance.ova"
|
||||
}
|
||||
resource "vsphere_content_library_item" "ADDS" {
|
||||
name = "ADDS-appliance"
|
||||
library_id = vsphere_content_library.library.id
|
||||
file_url = "https://{{user `repo_username`}}:{{user `repo_password`}}@sn.itch.fyi/Repository/rel/ADDS-appliance.ova"
|
||||
}
|
||||
|
||||
resource "vsphere_content_library_item" "Win10" {
|
||||
name = "Windows 10"
|
||||
library_id = vsphere_content_library.library.id
|
||||
file_url = "https://{{user `repo_username`}}:{{user `repo_password`}}@sn.itch.fyi/Repository/rel/Windows10.ova"
|
||||
}
|
36
terraform/main.tf
Normal file
36
terraform/main.tf
Normal file
@ -0,0 +1,36 @@
|
||||
terraform {
|
||||
backend "pg" {}
|
||||
}
|
||||
|
||||
provider "vsphere" {
|
||||
version = "1.24.1"
|
||||
|
||||
vsphere_server = var.vcenter_server
|
||||
user = var.vsphere_username
|
||||
password = var.vsphere_password
|
||||
|
||||
allow_unverified_ssl = true
|
||||
}
|
||||
|
||||
data "vsphere_datacenter" "dc" {
|
||||
name = var.vsphere_datacenter
|
||||
}
|
||||
|
||||
data "vsphere_resource_pool" "pool" {
|
||||
name = "/${var.vsphere_datacenter}/host/${var.vsphere_hostip}/Resources"
|
||||
datacenter_id = data.vsphere_datacenter.dc.id
|
||||
}
|
||||
|
||||
data "vsphere_datastore" "vmdatastore" {
|
||||
name = var.vsphere_vmdatastore
|
||||
datacenter_id = data.vsphere_datacenter.dc.id
|
||||
}
|
||||
data "vsphere_datastore" "cldatastore" {
|
||||
name = var.vsphere_cldatastore
|
||||
datacenter_id = data.vsphere_datacenter.dc.id
|
||||
}
|
||||
|
||||
data "vsphere_network" "network" {
|
||||
name = var.vsphere_network
|
||||
datacenter_id = data.vsphere_datacenter.dc.id
|
||||
}
|
29
terraform/variables.tf
Normal file
29
terraform/variables.tf
Normal file
@ -0,0 +1,29 @@
|
||||
variable "vcenter_server" {
|
||||
}
|
||||
|
||||
variable "vsphere_username" {
|
||||
}
|
||||
|
||||
variable "vsphere_password" {
|
||||
}
|
||||
|
||||
variable "vsphere_datacenter" {
|
||||
}
|
||||
|
||||
variable "vsphere_host" {
|
||||
}
|
||||
|
||||
variable "vsphere_hostip" {
|
||||
}
|
||||
|
||||
variable "vsphere_datastore" {
|
||||
}
|
||||
|
||||
variable "vsphere_folder" {
|
||||
}
|
||||
|
||||
variable "vsphere_templatefolder" {
|
||||
}
|
||||
|
||||
variable "vsphere_network" {
|
||||
}
|
57
terraform/vm.tf
Normal file
57
terraform/vm.tf
Normal file
@ -0,0 +1,57 @@
|
||||
resource "vsphere_virtual_machine" "TF-Windows2019" {
|
||||
name = "TF-Windows2019"
|
||||
resource_pool_id = data.vsphere_resource_pool.pool.id
|
||||
datastore_id = data.vsphere_datastore.datastore.id
|
||||
folder = var.vsphere_vmfolder
|
||||
|
||||
num_cpus = 2
|
||||
memory = 4096
|
||||
|
||||
network_interface {
|
||||
network_id = data.vsphere_network.network.id
|
||||
}
|
||||
|
||||
disk {
|
||||
label = "disk0"
|
||||
unit_number = 0
|
||||
size = 150
|
||||
thin_provisioned = true
|
||||
}
|
||||
disk {
|
||||
label = "disk1"
|
||||
unit_number = 1
|
||||
size = 225
|
||||
thin_provisioned = true
|
||||
}
|
||||
|
||||
vapp {
|
||||
properties = {
|
||||
"guestinfo.hostname" = "<<vm-hostname>>"
|
||||
"guestinfo.ipaddress" = "<<vm-ipaddress>>"
|
||||
"guestinfo.netmask" = "<<vm-netmask>>"
|
||||
"guestinfo.gateway" = "<<vm-gateway>>"
|
||||
"guestinfo.dns" = "<<vm-dns>>"
|
||||
"guestinfo.domain_name" = "<<vm-searchdomain>>"
|
||||
"guestinfo.ntp" = "<<vm-ntp>>"
|
||||
"guestinfo.enable_domain_join" = "<<ad-enable-domain-join>>"
|
||||
"guestinfo.domain_short_name" = "<<ad-netbios>>"
|
||||
"guestinfo.domain_join_user" = "<<ad-user>>"
|
||||
"guestinfo.domain_join_password" = "<<ad-password>>"
|
||||
"guestinfo.domain_controller" = "<<ad-domaincontroller>>"
|
||||
"guestinfo.viadmin_password" = "<<pass-viadmin>>"
|
||||
"guestinfo.viuser_password" = "<<pass-viuser>>"
|
||||
"guestinfo.viservice_password" = "<<pass-viservice>>"
|
||||
"guestinfo.project_name" = "<<proj-name>>"
|
||||
"guestinfo.monitor_server" = "<<mon-address>>"
|
||||
}
|
||||
}
|
||||
|
||||
clone {
|
||||
template_uuid = vsphere_content_library_item.Server2019.id
|
||||
}
|
||||
|
||||
# # This does not actually achieve protection from destruction, see https://github.com/hashicorp/terraform/issues/17599
|
||||
# lifecycle {
|
||||
# prevent_destroy = true
|
||||
# }
|
||||
}
|
9
terraform/vsphere.tfvars
Normal file
9
terraform/vsphere.tfvars
Normal file
@ -0,0 +1,9 @@
|
||||
vcenter_server = "bv11-vc01.bessems.lan"
|
||||
vsphere_username = "administrator@vsphere.local"
|
||||
vsphere_datacenter = "DeSchakel"
|
||||
vsphere_host = "bv11-esx.bessems.eu"
|
||||
vsphere_hostip = "192.168.11.200"
|
||||
vsphere_vmdatastore = "Datastore02.SSD"
|
||||
vsphere_cldatastore = "Datastore01.NAS"
|
||||
vsphere_vmfolder = "/Terraform"
|
||||
vsphere_network = "LAN"
|
Loading…
Reference in New Issue
Block a user