A demo Terraform usage and templates.
TERRAFORM_VER=`curl -sS https://releases.hashicorp.com/terraform/ | grep href | head -2 | tail -1 | awk -F/ '{print $3}'`
curl -o terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VER}/terraform_${TERRAFORM_VER}_linux_amd64.zip
unzip terraform.zip
sudo mv terraform /usr/local/bin/terraform
rm -f terraform.zip
terraform version
Check out source code:
git clone https://github.com/minhluantran017/demo-terraform.git
cd demo-terraform
Code structure:
.
|____<provider> // Each provider is a directory
| |____provider.tf // Contains general configurations for this provider
| |____<...>.tf // Contains TF plans for components
| |____<...>.tfvars // Contains variables for plans
|____scripts // Contains shell/python/powershell scripts
| |____*.sh
| |____*.py
|____files // Contains other files
| |____*.txt
| |____*.cfg
|____LICENSE // Contains licenses
|____README.md
TODO
Go to vsphere
folder:
cd vsphere
Replace value in templates/terraform.tfvars.tpl
with proper values.
envsubst <templates/terraform.tfvars.tpl >terraform.tfvars
Then proceed with Terraform commands:
terraform init
terraform plan
terraform apply -auto-approve
Go to kvm
folder:
cd kvm
Simple CentOS VM creation can be found here. Just proceed with Terraform commands:
terraform init
terraform plan
terraform apply -auto-approve
For using module, please use example format as follow:
module "ubuntu-vm" {
source = "git::https://github.com/minhluantran017/demo-terraform.git//kvm/module-vm?ref=v0.1.4"
base_image_url = "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img"
libvirt_pool = "devops"
create_pool = true
vm_name = "ubuntu-vm"
vm_count = 1
vm_vcpu = 4
vm_memory = 8096
vm_disk = 100000000000
ip_addresses = [
"10.250.200.191"
]
gw_address = "10.250.200.1"
dns_address = "10.250.200.2"
ssh_public_key = "ssh-rsa AAAA..."
}
TODO
-
Create branch for each component from
master
with convention:dev_<provider>
. For example:dev_aws
. -
Please always create Pull Request to merge it to
master
. Only merge if all the tests pass.
Terraform is under MPL2 licence. See LICENSE
- N/A