Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rgl/terraform-vsphere-windows-example
https://github.com/rgl/terraform-vsphere-windows-example
cloud-init example terraform vsphere windows
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rgl/terraform-vsphere-windows-example
- Owner: rgl
- Created: 2019-10-15T19:40:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-18T18:33:44.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T07:16:16.014Z (27 days ago)
- Topics: cloud-init, example, terraform, vsphere, windows
- Language: HCL
- Size: 16.6 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Usage (Ubuntu 22.04 host)
Install the [Windows 2022 VM template](https://github.com/rgl/windows-vagrant).
Install Terraform and govc (Ubuntu):
```bash
wget https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_linux_amd64.zip
unzip terraform_1.3.7_linux_amd64.zip
sudo install terraform /usr/local/bin
rm terraform terraform_*_linux_amd64.zip
wget https://github.com/vmware/govmomi/releases/download/v0.29.0/govc_Linux_x86_64.tar.gz
tar xf govc_Linux_x86_64.tar.gz govc
sudo install govc /usr/local/bin/govc
rm govc govc_Linux_x86_64.tar.gz
```Install Terraform and govc (Windows):
```bash
choco install -y --version 1.3.7 terraform
choco install -y --version 0.29.0 govc
```Save your environment details as a script that sets the terraform variables from environment variables, e.g.:
```bash
cat >secrets.sh <<'EOF'
export TF_VAR_vm_hostname_prefix='example'
export TF_VAR_vm_count='1'
export TF_VAR_vm_cpu='2'
export TF_VAR_vm_memory='4' # [GiB]
export TF_VAR_vm_disk_os_size='60' # [GiB]
export TF_VAR_vm_disk_data_size='1' # [GiB]
export TF_VAR_vsphere_user='[email protected]'
export TF_VAR_vsphere_password='password'
export TF_VAR_vsphere_server='vsphere.local'
export TF_VAR_vsphere_datacenter='Datacenter'
export TF_VAR_vsphere_compute_cluster='Cluster'
export TF_VAR_vsphere_datastore='Datastore'
export TF_VAR_vsphere_network='VM Network'
export TF_VAR_vsphere_folder='example'
export TF_VAR_vsphere_windows_template='vagrant-templates/windows-2022-amd64-vsphere'
export TF_VAR_winrm_username='vagrant'
# NB this value must meet the Windows password policy requirements.
# see https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/password-must-meet-complexity-requirements
export TF_VAR_winrm_password='HeyH0Password'
export GOVC_INSECURE='1'
export GOVC_URL="https://$TF_VAR_vsphere_server/sdk"
export GOVC_USERNAME="$TF_VAR_vsphere_user"
export GOVC_PASSWORD="$TF_VAR_vsphere_password"
EOF
```**NB** You could also add these variables definitions into the `terraform.tfvars` file, but I find the environment variables more versatile as they can also be used from other tools, like govc.
Launch this example:
```bash
source secrets.sh
# see https://github.com/vmware/govmomi/blob/master/govc/USAGE.md
govc version
govc about
govc datacenter.info # list datacenters
govc find # find all managed objects
terraform init
terraform plan -out=tfplan
time terraform apply tfplan
ssh-keygen -f ~/.ssh/known_hosts -R "$(terraform output --json ips | jq -r '.[0]')"
ssh "vagrant@$(terraform output --json ips | jq -r '.[0]')"
exit
time terraform destroy --auto-approve
```