diff --git a/README.md b/README.md index a0d84a2..2167680 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ * A vagrant project with an ubuntu box with the tools needed to do DevOps # tools included +* Docker * Terraform +* Packer * AWS CLI * Ansible diff --git a/Vagrantfile b/Vagrantfile index 55f612d..cc243fd 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,12 +1,18 @@ -Vagrant.configure(2) do |config| - config.vm.define "devops-box" do |devbox| - devbox.vm.box = "ubuntu/bionic64" - #devbox.vm.network "private_network", ip: "192.168.199.9" - #devbox.vm.hostname = "devops-box" - devbox.vm.provision "shell", path: "scripts/install.sh" - devbox.vm.provider "virtualbox" do |v| - v.memory = 4096 - v.cpus = 2 - end - end +Vagrant.configure("2") do |config| + # Remove the first "600" line + # config.vm.boot_timeout = 600 # Remove or comment out + + config.vm.define "devops-box" do |devbox| + #devbox.vm.box = "ubuntu/bionic64" + devbox.vm.box = "ubuntu/focal64" + devbox.vm.provision "shell", path: "scripts/install.sh" + devbox.vm.provider "virtualbox" do |v| + #v.gui = true + v.memory = 4096 + v.cpus = 2 + end + end + + # Keep the final large timeout, e.g., 1440 seconds + config.vm.boot_timeout = 1440 end diff --git a/error_notes.txt b/error_notes.txt new file mode 100644 index 0000000..f392827 --- /dev/null +++ b/error_notes.txt @@ -0,0 +1,74 @@ +Stderr: VBoxManage.exe: error: Call to WHvSetupPartition failed + +Note about VirtualBox 6.1.0. This topic has the name it has because that was how most users encountered the problem of VT-x/AMD-v hardware accelerated virtualization not being available. +If the topic had been called "VT-x not available error" then newbies may not have understood the relevance. However VirtualBox 6.1.0 now requires VT-x/AMD-v to be available (or Windows NEM, +but we'll leave that for now) for all VMs, whether 32bit, 64bit, single or multiple vCPU and so on. The original text remains below, the "bittedness" stuff is now less relevant, but the +underlying problem and solutions have not changed. + +VirtualBox requires hardware support for virtualization (Intel VT-x or AMD-v) in order to run certain categories of VM. This includes all 64bit VMs, and all VMs which use >1 CPU core. OS X hosts +require VT-x/AMD-v for every VM. Starting with VirtualBox 6.1.0 the latter is now true for all other hosts. The developers clearly feel that supporting older machines that don't have this hardware + feature is no longer justified commercially. + +To ensure that you can still run VMs in those categories, run through the following checklist :- + +Note your exact CPU model or part number, then go online and check its capabilities. The CPU must be 64bit and support either Intel or AMD virtualization technologies: VT-x or AMD-v. +. +You usually need to enable VT-x/AMD-v in the host PC BIOS. You need to check with your PC manual or support forum to find out how to boot into the BIOS screen. This is probably not something we +here at the VirtualBox forums can help you with. Once you get there you need to look for something buried in a menu, perhaps in the security category. The option may be called something like +"Enable Virtualization Technology", "Enable SVM Mode" (AMD CPUs), "Enable Vanderpool Technology" (Intel), or perhaps "Secure Virtual Mode". If you see "Virtual Directed I/O" (VT-d/AMD-Vi) then +that is a different thing. If you can find the latter option but can't find the former, and it's a recent PC (post 2016) then it's likely that VT-x/AMD-v is enabled by default in your BIOS, so +go to step 3! Remember to cycle power on your host PC after making and saving the BIOS changes - in this case a full restart from power off is required, just rebooting or resuming from a +hibernated state may not do the job. +. +If (1) and (2) are already taken care of, then make sure that no other host apps are already using VT-x/AMD-v. The usual culprits are system level debuggers, other VM platforms, and some resident + anti-virus applications. This has become a particular issue with 64bit Windows desktop and server hosts - especially Win2k12 and Win10, as these may enable Microsoft's Hyper-v VM platform by +default: this grabs ownership of VT-x and won't play nice with VirtualBox. Note: see the third post below for other Win10 functions that have this effect. +. +When creating a VM, make sure you choose the 64-bit version of the guest OS template in | General | Basic | Version, e.g. choose "Ubuntu (64 bit)" and not +"Ubuntu" or "Ubuntu (32bit)". This has become more important since VirtualBox 4.3.x, because choosing the correct template also allows other modern processor features to be visible to the +guest - it's not just about 64bit capability any more. + +Additional Notes for Windows Hosts + +1.- To check the status of Hyper-v in Windows 10, | Run | OptionalFeatures.exe, and look for the "Hyper-V" option. The box should be empty, not checked or shaded. If you want +to be absolutely sure that Hyper-v is gone then open an administrator command console and type "bcdedit /set hypervisorlaunchtype off". Make sure to fully power down and reboot the host after +changing the Hyper-v setting. + +2.- On some Windows hosts with an EFI BIOS, DeviceGuard or CredentialGuard may be active by default, and interferes with OS level virtualization apps in the same way that Hyper-v does. These +features + need to be disabled. On Pro versions of Windows you can do this using gpedit.msc (set Local Computer Policy > Computer Configuration > Administrative Templates > System > Device Guard > +Turn on Virtualization Based Security to Disabled. CredentialGuard is a subset of DeviceGuard, so disabling the former should be enough. If you cannot use gpedit for some reason then the +equivalent registry hack is to find the key HKLM|SYSTEM|CurrentControlSet|Control|DeviceGuard|EnableVirtualizationBasedSecurity|Enabled and set it to 0. + +3.- On Win10 hosts, check Windows Defender > Device Security > Core Isolation Details and make sure settings in this panel are turned off, reboot the host from power down if you needed to +make changes. +"Core isolation [includes] security features available on your device that use virtualization-based security" +...which is why they can interfere with VirtualBox. + + + +The following information is courtesy of user "Socratis". He has made a list of new features that Microsoft have added to Windows 10 which implicitly enable Hyper-V and therefore prevent VirtualBox from using VT-x directly. In an ideal world these should all be disabled, and please understand that Microsoft seems to be adding to this list all the time. + +Socratis wrote: +Here's the list that I have so far: + +Application Guard +Credential Guard (see https://www.microsoft.com/en-us/downloa ... x?id=53337) +Device Guard (see https://www.microsoft.com/en-us/downloa ... x?id=53337) + * Guard +Containers +Hyper-V +Virtual Machine Platform +Windows Hypervisor Platform +Windows Sandbox +Windows Server Containers +Windows Subsystem for Linux 2 (WSL2) (WSL1 does not enable Hyper-V) + +If that doesn't work, enter the following command: + +bcdedit /set hypervisorlaunchtype off + +followed by a cold boot, i.e. shut down the computer, pull the power plug for 10 seconds, reboot. + +If Hyper-V cannot be disabled, e.g. due to company policy, then VirtualBox v6.x has a new ability to run via the Windows Hypervisor Platform, however Windows 10 (1809) or later is required, +the feature still has bugs (as of VirtualBox 6.0.8), and it currently causes a significant drop in VM performance. \ No newline at end of file diff --git a/info.txt b/info.txt new file mode 100644 index 0000000..f05b532 --- /dev/null +++ b/info.txt @@ -0,0 +1,265 @@ +#bcdedit /set hypervisorlaunchtype off +#bcdedit /set hypervisorlaunchtype on +#bcdedit /set hypervisorlaunchtype auto + +#Vagrant up - VBoxManage.exe error: VT-x is not available + +Stop hyper-v service running by default in Windows 8/10, since it blocks all other calls to VT hardware. + +Additional explanation here: https://social.technet.microsoft.com/Forums/windows/en-US/118561b9-7155-46e3-a874-6a38b35c67fd/hyperv-disables-vtx-for-other-hypervisors?forum=w8itprogeneral + +Also as you have mentioned, if not already enabled, turn on Intel VT virtualization in BIOS settings and restart the machine. + +To turn Hypervisor off, run this from Command Prompt (Admin) (Windows+X): + +bcdedit /set hypervisorlaunchtype off +and reboot your computer. To turn it back on again, run: + +bcdedit /set hypervisorlaunchtype on +If you receive "The integer data is not valid as specified", try: + +bcdedit /set hypervisorlaunchtype auto + +#In Windows Features eliminate windows Sandbox so you can use both vagrant and docker toguether + +vagrant up +vagrant ssh-config +------------------------------- +Host devops-box + HostName 127.0.0.1 + User vagrant + Port 2222 + UserKnownHostsFile /dev/null + StrictHostKeyChecking no + PasswordAuthentication no + IdentityFile E:/IdeaProjects/devops-box/.vagrant/machines/devops-box/virtualbox/private_key + IdentitiesOnly yes + LogLevel FATAL +------------------------------- + +vagrant ssh devops-box + +ansible --version +docker -v +aws --version +packer -v +terraform version + +#rm -rf .vagrant/ + +vagrant upload scripts/packer.sh +vagrant upload scripts/terraform.sh +vagrant upload scripts/terraform_version.sh +vagrant upload terraform-test/main.tf +vagrant upload terraform-test/resource.tf +vagrant upload terraform-test/terraform.tfvars + +vagrant global-status +vagrant plugin install vagrant-scp +vagrant destroy 1a2b3c4d +vagrant destroy devops-box +vagrant destroy -f devops-box +vagrant box list +vagrant status devops-box +vagrant halt devops-box +vagrant suspend devops-box +vagrant up devops-box + +vagrant scp devops-box:/home/vagrant/terraform_version.sh "E:\IdeaProjects\devops-box\scripts" + +vagrant scp devops-box:/home/vagrant/terraform-test/main.tf "E:\IdeaProjects\devops-box\terraform-test" +vagrant scp devops-box:/home/vagrant/terraform-test/resource.tf "E:\IdeaProjects\devops-box\terraform-test" +vagrant scp devops-box:/home/vagrant/terraform-test/terraform.tfvars "E:\IdeaProjects\devops-box\terraform-test" +vagrant scp devops-box:/home/vagrant/terraform-test/main.tf /e/IdeaProjects/devops-box/terraform-test/main.tf +vagrant scp devops-box:/home/vagrant/terraform-test/resource.tf /e/IdeaProjects/devops-box/terraform-test/resource.tf +vagrant scp devops-box:/home/vagrant/terraform-test/terraform.tfvars /e/IdeaProjects/devops-box/terraform-test/terraform.tfvars +vagrant scp terraform-test/main.tf devops-box:/home/vagrant/terraform-test/main.tf +vagrant scp terraform-test/resource.tf devops-box:/home/vagrant/terraform-test/resource.tf +vagrant scp terraform-test/terraform.tfvars devops-box:/home/vagrant/terraform-test/terraform.tfvars +vagrant scp terraform devops-box:/home/vagrant +scp -P 2222 alien4cloud-premium-dist-3.4.0-dist.tar.gz vagrant@127.0.0.1:. + +vagrant box update +vagrant provision +vagrant up --provision devops-box +vagrant reload +vagrant reload --provision devops-box +vagrant reload --provision +vagrant --debug ssh + +vagrant plugin repair +vagrant plugin expunge --reinstall +vagrant plugin update + + +mkdir terraform-test +cd terraform-test +vi main.tf + +vagrant@ubuntu-bionic:~$ cat main.tf +variable "myvar" { + type = "string" + default = "hello terraform" +} + +variable "mymap" { + type = map(string) + default = { + mykey = "my value" + } +} + +variable "mylist" { + type = list + default = [1, 2, 3] +} + + +terraform version + +terraform console +var.myvar +or +"${var.myvar}" + +var.mymap +or +"${var.mymap}" + +var.mymap["mykey"] +or +"${var.mymap["mykey"]}" + +var.mylist +or +"${var.mylist}" + +var.mylist[0] +or +"${var.mylist[0]}" + +element(var.mylist, 1) +element(var.mylist, 0) +slice(var.mylist, 0, 2) + +exit + +aws configure + +#export TF_LOG=TRACE +#export TF_LOG=DEBUG +#export TF_LOG=INFO + +#export VAGRANT_DISABLE_VBOXSYMLINKCREATE=1 + +https://www.terraform.io/docs/extend/writing-custom-providers.html + +mkdir -p .terraform.d/plugins/linux_amd64 +cd .terraform.d/plugins/linux_amd64 +wget -q https://releases.hashicorp.com/terraform-provider-google/3.25.0/terraform-provider-google_3.25.0_linux_amd64.zip +unzip -o terraform-provider-google_3.25.0_linux_amd64.zip +rm -f terraform-provider-google_3.25.0_linux_amd64.zip + +mkdir -p .terraform.d/plugins/linux_amd64 +cd .terraform.d/plugins/linux_amd64 +wget -q https://releases.hashicorp.com/terraform-provider-azure/0.1.1/terraform-provider-azure_0.1.1_linux_amd64.zip +unzip -o terraform-provider-azure_0.1.1_linux_amd64.zip +rm -f terraform-provider-azure_0.1.1_linux_amd64.zip + +mkdir -p .terraform.d/plugins/linux_amd64 +cd .terraform.d/plugins/linux_amd64 +#wget -q https://releases.hashicorp.com/terraform-provider-aws/2.66.0/terraform-provider-aws_2.66.0_linux_amd64.zip +wget -q https://releases.hashicorp.com/terraform-provider-aws/2.69.0/terraform-provider-aws_2.69.0_linux_amd64.zip +#unzip -o terraform-provider-aws_2.66.0_linux_amd64.zip +unzip -o terraform-provider-aws_2.69.0_linux_amd64.zip +#rm -f terraform-provider-aws_2.66.0_linux_amd64.zip +rm -f terraform-provider-aws_2.69.0_linux_amd64.zip + +cd terraform-test +terraform init +terraform console +terraform providers + +var.AWS_REGION +var.AMIS[var.AWS_REGION] + +http://www.cloudping.info/ +https://cloud-images.ubuntu.com/locator/ec2/ + +terraform plan +terraform apply +terraform show +terraform destroy + +terraform plan -out out.terraform +terraform apply out.terraform +terraform show +terraform destroy + +sudo apt-get install ntpdate; ntpdate ntp.ubuntu.com + +ssh-keygen -f mykey +ssh -i "mykey" ubuntu@18.197.163.93 +ssh -i "mykey" ubuntu@ec2-18-197-163-93.eu-central-1.compute.amazonaws.com +ssh -i mykey -l ubuntu ec2-18-197-163-93.eu-central-1.compute.amazonaws.com +ssh -i mykey -l ubuntu -o "StrictHostKeyChecking no" ec2-18-197-163-93.eu-central-1.compute.amazonaws.com +ssh -i mykey -l ubuntu -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ec2-18-197-163-93.eu-central-1.compute.amazonaws.com + +#What you do is fix the networking on the server and add some extra time for the boot: +start the VM, log in to the server via GUI (username: vagrant, password: vagrant) and run the following commands + +sudo apt install -y ifupdown +sudo vi /etc/network/interfaces.d/eth0 + +# add this +auto eth0 +iface eth0 inet dhcp + +sudo /etc/init.d/networking restart + +$ sudo ifdown eth0 +$ sudo ifup eth0 +then add the following to the file /etc/rc.local + +ifdown eth0 +ifup eth0 +on the host, add the following to the Vagrantfile + + +config.vm.boot_timeout = 600 + +#Error vagrant ssh fails with VirtualBox +1.- in the VagrantFile, add the gui mode : config.vm.boot_mode = :gui +2.- run vagrant up +3.- in the gui, log with the user "vagrant" (password = "vagrant") +4.- in the gui, run sudo /etc/init.d/networking restart, in /etc/network/interfaces file, you must now have a section with #VAGRANT-BEGIN [...]#VAGRANT-END +5.- run vagrant reload on the physical machine + + +unset SSH_AUTH_SOCK +unset SSH_AGENT_PID + + + +config.vm.boot_timeout = 600 +vagrant reload --provision +vagrant ssh-config + +ssh -i "C:\Program Files (x86)\Vagrant\bin\insecure_private_keys\vagrant.key.rsa" -p 2222 vagrant@127.0.0.1 + +vagrant ssh --debug + +vagrant ssh-config +ssh-keygen -R [127.0.0.1]:2222 +vagrant ssh + + +ssh -vvv -i "C:\Program Files (x86)\Vagrant\bin\insecure_private_keys\vagrant.key.rsa" -p 2222 vagrant@127.0.0.1 +ssh -vvv -i "C:\Program Files (x86)\Vagrant\bin\insecure_private_keys\vagrant.key.ed25519" -p 2222 vagrant@127.0.0.1 +vagrant ssh-config + +vagrant destroy -f +vagrant box remove ubuntu/bionic64 +vagrant box add ubuntu/bionic64 +vagrant up + diff --git a/scripts/install.sh b/scripts/install.sh index 70752ab..9decfcf 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,14 +1,31 @@ #!/bin/bash # remove comment if you want to enable debugging -#set -x +set -x if [ -e /etc/redhat-release ] ; then REDHAT_BASED=true fi -TERRAFORM_VERSION="0.12.18" -PACKER_VERSION="1.2.4" +#TERRAFORM_VERSION=`curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` +#TERRAFORM_VERSION="0.12.25" +#TERRAFORM_VERSION="0.12.26" +TERRAFORM_VERSION="1.1.3" +#PACKER_VERSION=`curl -s https://api.github.com/repos/hashicorp/packer/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` +#PACKER_VERSION="1.5.4" +PACKER_VERSION="1.6.0" +AWS_CLI_VERSION="1.14.44" +#AWS_EB_CLI_VERSION=`curl -s https://api.github.com/repos/aws/aws-elastic-beanstalk-cli-setup/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` +AWS_EB_CLI_VERSION="3.11" +GOOGLE_CLOUD_PROVIDER_VERSION=`curl -s https://api.github.com/repos/terraform-providers/terraform-provider-google/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` +AWS_PROVIDER_VERSION=`curl -s https://api.github.com/repos/terraform-providers/terraform-provider-aws/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` + +#AZURE_PROVIDER_CLASSIC_VERSION=`curl -s https://api.github.com/repos/terraform-providers/terraform-provider-azure-classic/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` +#AZURE_PROVIDER_CLASSIC_VERSION="0.1.1" +#AZURE_PROVIDER_AD_VERSION=`curl -s https://api.github.com/repos/terraform-providers/terraform-provider-azuread/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` +#AZURE_PROVIDER_STACK_VERSION=`curl -s https://api.github.com/repos/terraform-providers/terraform-provider-azurestack/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` +AZURE_PROVIDER_RM_VERSION=`curl -s https://api.github.com/repos/terraform-providers/terraform-provider-azurerm/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'` + # create new ssh key [[ ! -f /home/ubuntu/.ssh/mykey ]] \ && mkdir -p /home/ubuntu/.ssh \ @@ -18,34 +35,161 @@ PACKER_VERSION="1.2.4" # install packages if [ ${REDHAT_BASED} ] ; then yum -y update - yum install -y docker ansible unzip wget + yum install -y docker ansible unzip wget awscli else - apt-get update - apt-get -y install docker.io ansible unzip python3-pip + #apt update && apt -y full-upgrade && apt auto-remove + apt update + apt-get -y install docker.io ansible unzip python3-pip awscli fi + # add docker privileges -usermod -G docker ubuntu +#usermod -G docker ubuntu +usermod -aG docker ubuntu # install awscli and ebcli -pip3 install -U awscli -pip3 install -U awsebcli +#pip3 install -U awscli +#pip3 install -U awsebcli +pip3 install -U awscli==${AWS_CLI_VERSION} +pip3 install awsebcli==${AWS_EB_CLI_VERSION} -#terraform +# terraform +# https://releases.hashicorp.com/terraform/0.12.26/terraform_0.12.26_windows_amd64.zip T_VERSION=$(/usr/local/bin/terraform -v | head -1 | cut -d ' ' -f 2 | tail -c +2) T_RETVAL=${PIPESTATUS[0]} [[ $T_VERSION != $TERRAFORM_VERSION ]] || [[ $T_RETVAL != 0 ]] \ && wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \ -&& unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin \ -&& rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip +&& wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS +#sha256sum=$(sha256sum -c terraform_${TERRAFORM_VERSION}_SHA256SUMS 2>&1 | grep terraform_${TERRAFORM_VERSION}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + +sha256sum="FAILED" +retval=1 +while [ $sha256sum != "OK" ] || [ $retval -ne 0 ]; do + wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \ + && wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS + sha256sum=$(sha256sum -c terraform_${TERRAFORM_VERSION}_SHA256SUMS 2>&1 | grep terraform_${TERRAFORM_VERSION}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + if [ $sha256sum = "OK" ]; then + unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin + rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip + which terraform + terraform version + retval=$? + if [ $retval -eq 0 ]; then + break + fi + fi +done + +#for version in `curl -s https://releases.hashicorp.com/terraform/ | grep terraform | cut -d/ -f3 | awk '{$1=$1};1'`; do +# wget -q https://releases.hashicorp.com/terraform/${version}/terraform_${version}_linux_amd64.zip \ +# && wget -q https://releases.hashicorp.com/terraform/${version}/terraform_${version}_SHA256SUMS +# #sha256sum=$(sha256sum -c terraform_${version}_SHA256SUMS | grep terraform_${version}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") +# sha256sum=$(sha256sum -c terraform_${version}_SHA256SUMS | grep terraform_${version}_linux_amd64.zip | cut -d: -f2 >/dev/null && echo "OK" || echo "FAILED") +# if [ $sha256sum = "OK" ]; then +# unzip -o terraform_${version}_linux_amd64.zip -d /usr/local/bin +# rm terraform_${version}_linux_amd64.zip +# which terraform +# terraform version +# retval=$? +# if [ $retval -eq 0 ]; then +# break +# fi +# fi +#done + +rm -f terraform_* +#unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin \ +#&& rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip +#which terraform +#terraform version + # packer +# https://releases.hashicorp.com/packer/1.5.6/packer_1.5.6_windows_amd64.zip P_VERSION=$(/usr/local/bin/packer -v) P_RETVAL=$? [[ $P_VERSION != $PACKER_VERSION ]] || [[ $P_RETVAL != 1 ]] \ && wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip \ -&& unzip -o packer_${PACKER_VERSION}_linux_amd64.zip -d /usr/local/bin \ -&& rm packer_${PACKER_VERSION}_linux_amd64.zip +&& wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_SHA256SUMS \ +#sha256sum=$(sha256sum -c packer_${PACKER_VERSION}_SHA256SUMS 2>&1 | grep packer_${PACKER_VERSION}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + +#sha256sum="FAILED" +#retval=1 +#while [ $sha256sum != "OK" ] || [ $retval -ne 0 ]; do +# wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip \ +# && wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_SHA256SUMS +# sha256sum=$(sha256sum -c packer_${PACKER_VERSION}_SHA256SUMS 2>&1 | grep packer_${PACKER_VERSION}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") +# if [ $sha256sum = "OK" ]; then +# unzip -o packer_${PACKER_VERSION}_linux_amd64.zip -d /usr/local/bin +# rm packer_${PACKER_VERSION}_linux_amd64.zip +# which packer +# packer -v +# retval=$? +# if [ $retval -eq 0 ]; then +# break +# fi +# fi +#done + +for version in `curl -s https://releases.hashicorp.com/packer/ | grep packer | cut -d/ -f3 | awk '{$1=$1};1'`; do + wget -q https://releases.hashicorp.com/packer/${version}/packer_${version}_linux_amd64.zip \ + && wget -q https://releases.hashicorp.com/packer/${version}/packer_${version}_SHA256SUMS + #sha256sum=$(sha256sum -c packer_${version}_SHA256SUMS | grep packer_${version}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + sha256sum=$(sha256sum -c packer_${version}_SHA256SUMS | grep packer_${version}_linux_amd64.zip | cut -d: -f2 >/dev/null && echo "OK" || echo "FAILED") + if [ $sha256sum = "OK" ]; then + unzip -o packer_${version}_linux_amd64.zip -d /usr/local/bin + rm packer_${version}_linux_amd64.zip + which packer + packer -v + retval=$? + if [ $retval -eq 0 ]; then + break + fi + fi +done + +rm -f packer_* +#unzip -o packer_${PACKER_VERSION}_linux_amd64.zip -d /usr/local/bin \ +#&& rm packer_${PACKER_VERSION}_linux_amd64.zip +#which packer +#packer -v + +user=$(whoami) +cd /home/vagrant +mkdir -p .terraform.d/plugins/linux_amd64 +cd .terraform.d/plugins/linux_amd64 + +# installing some providers + +# google provider +wget -q https://releases.hashicorp.com/terraform-provider-google/${GOOGLE_CLOUD_PROVIDER_VERSION}/terraform-provider-google_${GOOGLE_CLOUD_PROVIDER_VERSION}_linux_amd64.zip +unzip -o terraform-provider-google_${GOOGLE_CLOUD_PROVIDER_VERSION}_linux_amd64.zip +rm -f terraform-provider-google_${GOOGLE_CLOUD_PROVIDER_VERSION}_linux_amd64.zip + +# aws provider +wget -q https://releases.hashicorp.com/terraform-provider-aws/${AWS_PROVIDER_VERSION}/terraform-provider-aws_${AWS_PROVIDER_VERSION}_linux_amd64.zip +unzip -o terraform-provider-aws_${AWS_PROVIDER_VERSION}_linux_amd64.zip +rm -f terraform-provider-aws_${AWS_PROVIDER_VERSION}_linux_amd64.zip + +# azure provider classic +#wget -q https://releases.hashicorp.com/terraform-provider-azure/${AZURE_PROVIDER_CLASSIC_VERSION}/terraform-provider-azure_${AZURE_PROVIDER_CLASSIC_VERSION}_linux_amd64.zip +#unzip -o terraform-provider-azure_${AZURE_PROVIDER_CLASSIC_VERSION}_linux_amd64.zip +#rm -f terraform-provider-azure_${AZURE_PROVIDER_CLASSIC_VERSION}_linux_amd64.zip + +# azure provider ad +#wget -q https://releases.hashicorp.com/terraform-provider-azuread/${AZURE_PROVIDER_AD_VERSION}/terraform-provider-azuread_${AZURE_PROVIDER_AD_VERSION}_linux_amd64.zip +#unzip -o terraform-provider-azuread_${AZURE_PROVIDER_AD_VERSION}_linux_amd64.zip +#rm -f terraform-provider-azuread_${AZURE_PROVIDER_AD_VERSION}_linux_amd64.zip + +# azure provider stack +#wget -q https://releases.hashicorp.com/terraform-provider-azurestack/${AZURE_PROVIDER_STACK_VERSION}/terraform-provider-azurestack_${AZURE_PROVIDER_STACK_VERSION}_linux_amd64.zip +#unzip -o terraform-provider-azurestack_${AZURE_PROVIDER_STACK_VERSION}_linux_amd64.zip +#rm -f terraform-provider-azurestack_${AZURE_PROVIDER_STACK_VERSION}_linux_amd64.zip + +# azure provider rm +wget -q https://releases.hashicorp.com/terraform-provider-azurerm/${AZURE_PROVIDER_RM_VERSION}/terraform-provider-azurerm_${AZURE_PROVIDER_RM_VERSION}_linux_amd64.zip +unzip -o terraform-provider-azurerm_${AZURE_PROVIDER_RM_VERSION}_linux_amd64.zip +rm -f terraform-provider-azurerm_${AZURE_PROVIDER_RM_VERSION}_linux_amd64.zip # clean up if [ ! ${REDHAT_BASED} ] ; then diff --git a/scripts/packer.sh b/scripts/packer.sh new file mode 100644 index 0000000..d3d7e38 --- /dev/null +++ b/scripts/packer.sh @@ -0,0 +1,19 @@ +#!/bin/sh +mkdir download +cd download +for version in `curl -s https://releases.hashicorp.com/packer/ | grep packer | cut -d/ -f3 | awk '{$1=$1};1'`; do + wget -q https://releases.hashicorp.com/packer/${version}/packer_${version}_linux_amd64.zip \ + && wget -q https://releases.hashicorp.com/packer/${version}/packer_${version}_SHA256SUMS + #sha256sum=$(sha256sum -c packer_${version}_SHA256SUMS | grep packer_${version}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + sha256sum=$(sha256sum -c packer_${version}_SHA256SUMS | grep packer_${version}_linux_amd64.zip | cut -d: -f2 >/dev/null && echo "OK" || echo "FAILED") + if [ $sha256sum = "OK" ]; then + echo $version + sudo unzip -o packer_${version}_linux_amd64.zip -d /usr/local/bin \ + && rm packer_${version}_linux_amd64.zip + break + fi +done +cd .. +rm -rf download +which packer +packer -v diff --git a/scripts/packer_version.sh b/scripts/packer_version.sh new file mode 100644 index 0000000..95a57b5 --- /dev/null +++ b/scripts/packer_version.sh @@ -0,0 +1,27 @@ +#!/bin/sh +PACKER_VERSION="1.6.0" +sha256sum="FAILED" +retval=1 +#echo $sha256sum +#echo $retval +mkdir download +cd download +while [ $sha256sum != "OK" ] || [ $retval -ne 0 ]; do + wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip \ + && wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_SHA256SUMS + sha256sum=$(sha256sum -c packer_${PACKER_VERSION}_SHA256SUMS 2>&1 | grep packer_${PACKER_VERSION}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + #echo $sha256sum + if [ $sha256sum = "OK" ]; then + sudo unzip -o packer_${PACKER_VERSION}_linux_amd64.zip -d /usr/local/bin + rm packer_${PACKER_VERSION}_linux_amd64.zip + which packer + packer -v + retval=$? + #echo $retval + if [ $retval -eq 0 ]; then + break + fi + fi +done +cd .. +rm -rf download diff --git a/scripts/terraform.sh b/scripts/terraform.sh new file mode 100644 index 0000000..36b7a91 --- /dev/null +++ b/scripts/terraform.sh @@ -0,0 +1,23 @@ +#!/bin/sh +mkdir download +cd download +for version in `curl -s https://releases.hashicorp.com/terraform/ | grep terraform | cut -d/ -f3 | awk '{$1=$1};1'`; do + wget -q https://releases.hashicorp.com/terraform/${version}/terraform_${version}_linux_amd64.zip \ + && wget -q https://releases.hashicorp.com/terraform/${version}/terraform_${version}_SHA256SUMS + #sha256sum=$(sha256sum -c packer_${version}_SHA256SUMS 2>&1 | grep OK) + #sha256sum=$(sha256sum -c terraform_0.12.26_SHA256SUMS | grep terraform_0.12.26_linux_amd64.zip | cut -d: -f2) + #sha256sum=$(sha256sum -c terraform_0.12.26_SHA256SUMS | grep terraform_0.12.26_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + #sha256sum=$(sha256sum -c terraform_0.12.26_SHA256SUMS | grep terraform_0.12.26_linux_amd64.zip | cut -d: -f2 >/dev/null && echo "OK" || echo "FAILED") + #sha256sum=$(sha256sum -c terraform_${version}_SHA256SUMS | grep terraform_${version}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + sha256sum=$(sha256sum -c terraform_${version}_SHA256SUMS | grep terraform_${version}_linux_amd64.zip | cut -d: -f2 >/dev/null && echo "OK" || echo "FAILED") + if [ $sha256sum = "OK" ]; then + echo $version + sudo unzip -o terraform_${version}_linux_amd64.zip -d /usr/local/bin \ + && rm terraform_${version}_linux_amd64.zip + break + fi +done +cd .. +rm -rf download +which terraform +terraform version diff --git a/scripts/terraform_version.sh b/scripts/terraform_version.sh new file mode 100644 index 0000000..a4f4fce --- /dev/null +++ b/scripts/terraform_version.sh @@ -0,0 +1,27 @@ +#!/bin/sh +TERRAFORM_VERSION="0.12.26" +sha256sum="FAILED" +retval=1 +#echo $sha256sum +#echo $retval +mkdir download +cd download +while [ $sha256sum != "OK" ] || [ $retval -ne 0 ]; do + wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \ + && wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS + sha256sum=$(sha256sum -c terraform_${TERRAFORM_VERSION}_SHA256SUMS 2>&1 | grep terraform_${TERRAFORM_VERSION}_linux_amd64.zip | awk {'print $2'} >/dev/null && echo "OK" || echo "FAILED") + #echo $sha256sum + if [ $sha256sum = "OK" ]; then + sudo unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin + rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip + which terraform + terraform version + retval=$? + #echo $retval + if [ $retval -eq 0 ]; then + break + fi + fi +done +cd .. +rm -rf download diff --git a/terraform b/terraform new file mode 100644 index 0000000..b190539 Binary files /dev/null and b/terraform differ diff --git a/terraform-test/main.tf b/terraform-test/main.tf new file mode 100644 index 0000000..ca9e0b0 --- /dev/null +++ b/terraform-test/main.tf @@ -0,0 +1,16 @@ +variable "myvar" { + type = string + default = "hello terraform" +} + +variable "mymap" { + type = map(string) + default = { + mykey = "my value" + } +} + +variable "mylist" { + type = list + default = [1, 2, 3] +} diff --git a/terraform-test/resource.tf b/terraform-test/resource.tf new file mode 100644 index 0000000..5b9d77f --- /dev/null +++ b/terraform-test/resource.tf @@ -0,0 +1,29 @@ +provider "aws" { + +} + +variable "AWS_REGION" { + type = string +} + +variable "AMIS" { + type = map(string) + default = { + eu-central-1 = "my ami" + } +} + +resource "aws_instance" "example1" { + ami = var.AMIS[var.AWS_REGION] + instance_type = "t2.micro" +} + +resource "aws_instance" "example2" { + ami = var.AMIS[var.AWS_REGION] + instance_type = "t2.micro" +} + +resource "aws_instance" "example3" { + ami = var.AMIS[var.AWS_REGION] + instance_type = "t2.small" +} diff --git a/terraform-test/terraform.tfvars b/terraform-test/terraform.tfvars new file mode 100644 index 0000000..d79e167 --- /dev/null +++ b/terraform-test/terraform.tfvars @@ -0,0 +1 @@ +AWS_REGION="eu-central-1" diff --git a/terraform.zip b/terraform.zip new file mode 100644 index 0000000..a419844 Binary files /dev/null and b/terraform.zip differ