diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..72a935d138ae54325073ab540f8cf804cf94121c --- /dev/null +++ b/.gitignore @@ -0,0 +1,44 @@ +### Terraform template +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Exclude all .tfvars files, which are likely to contain sentitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +# +*.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +# IDEs +.idea +.vscode +.code +.vs + +login.tfvars +login.sh diff --git a/destroy.sh b/destroy.sh new file mode 100755 index 0000000000000000000000000000000000000000..7e5e3946bffabfe8c8eff2b9e42f3f00bd1923d1 --- /dev/null +++ b/destroy.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +source login.sh +terraform destroy --var-file login.tfvars diff --git a/hosts.tf b/hosts.tf new file mode 100644 index 0000000000000000000000000000000000000000..87f5337850e9b76fadf78a3eebb73920f3b95c1b --- /dev/null +++ b/hosts.tf @@ -0,0 +1,8 @@ +data "vsphere_host" "NOC-A" { + name = "noc-a-test.internal" + datacenter_id = data.vsphere_datacenter.DC.id +} +data "vsphere_host" "NOC-B" { + name = "noc-b-test.internal" + datacenter_id = data.vsphere_datacenter.DC.id +} \ No newline at end of file diff --git a/how-to-import b/how-to-import new file mode 100644 index 0000000000000000000000000000000000000000..e33150804193a5d9a99838ef87682e05facc0aa1 --- /dev/null +++ b/how-to-import @@ -0,0 +1 @@ +terraform import --var-file login.tfvars 'vsphere_distributed_port_group.dvpg["DnPG-Internal-152"]' /NOC/network/DnPG-Internal-152 \ No newline at end of file diff --git a/initState.sh b/initState.sh new file mode 100755 index 0000000000000000000000000000000000000000..dbbfe53e3062042c50bfc4fca2056bc9c35fa8d3 --- /dev/null +++ b/initState.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +source login.sh + +PROJ_ID="3585" +STATE_NAME="petalinux" + +terraform init \ + -backend-config="address=https://git.sch.bme.hu/api/v4/projects/${PROJ_ID}/terraform/state/${STATE_NAME}" \ + -backend-config="lock_address=https://git.sch.bme.hu/api/v4/projects/${PROJ_ID}/terraform/state/${STATE_NAME}/lock" \ + -backend-config="unlock_address=https://git.sch.bme.hu/api/v4/projects/${PROJ_ID}/terraform/state/${STATE_NAME}/lock" \ + -backend-config="username=${GITLAB_USER}" \ + -backend-config="password=${GITLAB_REPO_PAT}" \ + -backend-config="lock_method=POST" \ + -backend-config="unlock_method=DELETE" \ + -backend-config="retry_wait_min=5" \ + -reconfigure diff --git a/login.sh.example b/login.sh.example new file mode 100755 index 0000000000000000000000000000000000000000..f4169532a045066b65ac50d4f94bd731c066eded --- /dev/null +++ b/login.sh.example @@ -0,0 +1,4 @@ +#!/bin/bash + +export GITLAB_USER=kovacs_bela +export GITLAB_REPO_PAT=sokbetu_sokszam \ No newline at end of file diff --git a/login.tfvars.example b/login.tfvars.example new file mode 100644 index 0000000000000000000000000000000000000000..3681aa56bc83308662b610938a25da653bc7193d --- /dev/null +++ b/login.tfvars.example @@ -0,0 +1,2 @@ +vsphere_user="bela_kisnyul" +vsphere_password="almafa123" diff --git a/networks.tf b/networks.tf new file mode 100644 index 0000000000000000000000000000000000000000..3f1465801d81a218628342147738a070f8b09607 --- /dev/null +++ b/networks.tf @@ -0,0 +1,58 @@ +data "vsphere_network" "DnPG-Internal-151" { + name = "DnPG-Internal-151" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-NAT-51" { + name = "DnPG-NAT-51" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-Internal-152" { + name = "DnPG-Internal-152" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-WiFi-69" { + name = "DnPG-WiFi-69" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-mgmt-lan" { + name = "DnPG-mgmt-lan" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-Vlan-172" { + name = "DnPG-Vlan-172" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-Internal-29" { + name = "DnPG-Internal-29" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-Internal-209" { + name = "DnPG-Internal-209" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_network" "DnPG-NATGWTEST-64" { + name = "DnPG-NATGWTEST-64" + datacenter_id = data.vsphere_datacenter.DC.id +} +data "vsphere_network" "DnPG-Internal-211" { + name = "DnPG-Internal-211" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_distributed_virtual_switch" "switch" { + name = "DNocSwitch" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_distributed_virtual_switch" "Switch-mgmt" { + name = "DNocSwitch-mgmt" + datacenter_id = data.vsphere_datacenter.DC.id +} diff --git a/run.sh b/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..ae11db2f4b2a0604aa35d75c311a1f08dc27c840 --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +source login.sh +terraform apply --var-file login.tfvars \ No newline at end of file diff --git a/vms.tf b/vms.tf new file mode 100644 index 0000000000000000000000000000000000000000..ecbf061e8d1d109f9dd69ad88ee0d552f21a711d --- /dev/null +++ b/vms.tf @@ -0,0 +1,48 @@ +#https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.ova +data "vsphere_virtual_machine" "ubuntu_template" { + name = "ubuntu-20.04-server-cloudimg-amd64v2" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_virtual_machine" "ubuntu_template-richard" { + name = "ubu1804-template" + datacenter_id = data.vsphere_datacenter.DC.id +} +variable "pubkeys_woranhun" { + type = string + default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCa/EVELPE/fowuT4xPa9EpcDEOvdilmU5P8ZFmbsApF9ch6COXUv60TAOKMkTUTHswgAgaqU2zlkrFcxb/pS5N9uv8MaRNRZmdg5lZyYnbk90oY08sEyWzNUdPFo1UcpIUm/rojkW35ikWXabc6VKbn5uvM4c3cxT+ryxDXojLV/rkIW8MmrW1GndiANz047xyAPxBW7LqHIa7M8Q/dHB7rV1zEDVyiu6oe9+zV4wreU+5NFODw2+znNs5BicvxL0YAW2kp1IVg6OUVSHyPH+7eW+VYD6bDVmA+xtyIMsWZBCHki4bup1eouNO8ej5h9zj6GmANZZVV8MiHSVHpJGdT7QOLEKZo+SR4ybgfFrqmcyY54HM+PdHsrycHmVuY30lraUk1/P4yHkmuYUP1/0LdfemLPw81T/W8ndRpw2aIVjQYa97mpIj8FRaA9nbEw7hcsXlGfrVXE46lALt3cJXzS9IoW9FCGMV4/aOUWCb65k0pKlBVMrJDsogDVgO5zAvZp11WYwzjZzZkpGD3Yg4YVGm1DhBaWBuMvcb/peNFgVMItTqJe+DcgCjyyq/iDPosfuyoCkYL3NwNUcBzMXcHgLFCVTeHZlieRKajw5GO2S5toAC+gpzmr31CP8jBGlwAuHotb0CbeMR0Dynk58ewdpiwK0stppKShToyQZJbQ== woranhun@woranhunX220ubu" +} + +variable "pubkeys_richard" { + type = string + default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIONs0OwDN2sMIPotBEwm6l/g4qB0z7k31uXS3tmcZLo4 szabo_richard (git.sch.bme.hu)" +} +resource "vsphere_virtual_machine" "richardvm" { + resource_pool_id = data.vsphere_resource_pool.NOC-A.id + datastore_id = data.vsphere_datastore.NOC-A-Storage.id + name = "richardvm" + guest_id = "ubuntu64Guest" + + memory = 32768 + firmware = "efi" + num_cores_per_socket = 15 + + host_system_id = data.vsphere_host.NOC-A.id + + clone { + template_uuid = data.vsphere_virtual_machine.ubuntu_template-richard.id + } + network_interface { + network_id = data.vsphere_network.DnPG-Internal-211.id + use_static_mac = true + mac_address = "00:50:56:10:3d:21" + } + disk { + thin_provisioned = false + label = "disk0" + size = 300 + } + cdrom { + client_device = true + } +} \ No newline at end of file diff --git a/vmware.tf b/vmware.tf new file mode 100644 index 0000000000000000000000000000000000000000..64cf78479749d04c1b06f25a70e802690650696f --- /dev/null +++ b/vmware.tf @@ -0,0 +1,55 @@ +terraform { + required_providers { + vsphere = { + source = "hashicorp/vsphere" + version = "2.0.0" + } + } + backend "http" {} +} + +# Vsphere provider config + +variable "vsphere_user" { + description = "Administrator user" + type = string + sensitive = false +} + +variable "vsphere_password" { + description = "Administrator password" + type = string + sensitive = true +} + +provider "vsphere" { + user = var.vsphere_user + password = var.vsphere_password + vsphere_server = "horizont.sch.bme.hu" + + allow_unverified_ssl = true +} + +data "vsphere_datacenter" "DC" { + name = "NOC" +} + +data "vsphere_datastore" "NOC-A-Storage" { + name = "NOC-A-Test-Storage1" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_datastore" "NOC-B-Storage" { + name = "NOC-B-Test-Storage1" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_resource_pool" "NOC-A" { + name = "noc-a-test.internal/Resources" + datacenter_id = data.vsphere_datacenter.DC.id +} + +data "vsphere_resource_pool" "NOC-B" { + name = "noc-b-test.internal/Resources" + datacenter_id = data.vsphere_datacenter.DC.id +} \ No newline at end of file