diff --git a/.travis.yml b/.travis.yml index a6bedbcc5..9d863c4e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ before_deploy: - export KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 12) - export PASSWORD=$KEY$(cat /dev/urandom | tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | tr -cd '0-9' | head -c 2) + # terraform deploy script deploy: - provider: script @@ -27,5 +28,9 @@ deploy: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux -# TODO: possibly use Azure CLI to delete the resource group -after_deploy: docker run --rm -it azuresdk/azure-cli-python sh -c "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID; az group delete -y -n $KEY" +# destroy resources with Azure CLI +after_deploy: + - docker run --rm -it \ + azuresdk/azure-cli-python \ + sh -c "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID; \ + az group delete -y -n $KEY" diff --git a/examples/azure-vm-simple-linux/deploy.mac.sh b/examples/azure-vm-simple-linux/deploy.mac.sh new file mode 100755 index 000000000..f0bb60f8b --- /dev/null +++ b/examples/azure-vm-simple-linux/deploy.mac.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -o errexit -o nounset + +# generate a unique string for CI deployment +export KEY=$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-z' | head -c 12) +export PASSWORD=$KEY$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | env LC_CTYPE=C tr -cd '0-9' | head -c 2) + +/bin/sh ./deploy.sh + +# docker run --rm -it \ +# azuresdk/azure-cli-python \ +# sh -c "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID; \ +# az group delete -y -n $KEY" diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 899385f27..5347f3a83 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -2,10 +2,6 @@ set -o errexit -o nounset -# generate a unique string for CI deployment -# KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 12) -# PASSWORD=$KEY$(cat /dev/urandom | tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | tr -cd '0-9' | head -c 2) - docker run --rm -it \ -e ARM_CLIENT_ID \ -e ARM_CLIENT_SECRET \ @@ -14,26 +10,8 @@ docker run --rm -it \ -v $(pwd):/data \ --entrypoint "/bin/sh" \ hashicorp/terraform:light \ - -c "cd /data; /bin/terraform get; /bin/terraform plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan; /bin/terraform apply out.tfplan" - -# TODO: determine external validation, possibly Azure CLI - -# echo "Setting git user name" -# git config user.name $GH_USER_NAME -# -# echo "Setting git user email" -# git config user.email $GH_USER_EMAIL -# -# echo "Adding git upstream remote" -# git remote add upstream "https://$GH_TOKEN@github.com/$GH_REPO.git" -# -# git checkout master - - -# -# NOW=$(TZ=America/Chicago date) -# -# git commit -m "tfstate: $NOW [ci skip]" -# -# echo "Pushing changes to upstream master" -# git push upstream master + -c "cd /data; \ + /bin/terraform get; \ + /bin/terraform validate; \ + /bin/terraform plan -out=out.tfplan -var dns_name=$KEY -var hostname=$KEY -var resource_group=$KEY -var admin_password=$PASSWORD; \ + /bin/terraform apply out.tfplan" diff --git a/examples/azure-vm-simple-linux/azuredeploy.tf b/examples/azure-vm-simple-linux/main.tf similarity index 95% rename from examples/azure-vm-simple-linux/azuredeploy.tf rename to examples/azure-vm-simple-linux/main.tf index 639f22707..cf931d0f9 100644 --- a/examples/azure-vm-simple-linux/azuredeploy.tf +++ b/examples/azure-vm-simple-linux/main.tf @@ -18,9 +18,9 @@ resource "azurerm_subnet" "subnet" { } resource "azurerm_network_interface" "nic" { - name = "${var.rg_prefix}nic" - location = "${var.location}" - resource_group_name = "${azurerm_resource_group.rg.name}" + name = "${var.rg_prefix}nic" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" ip_configuration { name = "${var.rg_prefix}ipconfig" diff --git a/examples/azure-vm-simple-linux/terraform.tfvars.example b/examples/azure-vm-simple-linux/terraform.tfvars.example index 715f259dc..262093ba5 100644 --- a/examples/azure-vm-simple-linux/terraform.tfvars.example +++ b/examples/azure-vm-simple-linux/terraform.tfvars.example @@ -3,5 +3,4 @@ rg_prefix = "rg" hostname = "myvm" dns_name = "mydnsname" location = "southcentralus" -admin_username = "vmadmin" admin_password = "T3rr@f0rmP@ssword" diff --git a/examples/azure-vm-simple-linux/variables.tf b/examples/azure-vm-simple-linux/variables.tf index 72680c74f..6d65a0277 100644 --- a/examples/azure-vm-simple-linux/variables.tf +++ b/examples/azure-vm-simple-linux/variables.tf @@ -4,6 +4,7 @@ variable "resource_group" { variable "rg_prefix" { description = "The shortened abbreviation to represent your resource group that will go on the front of some resources." + default = "rg" } variable "hostname" { @@ -16,6 +17,7 @@ variable "dns_name" { variable "location" { description = "The location/region where the virtual network is created. Changing this forces a new resource to be created." + default = "southcentralus" } variable "virtual_network_name" { @@ -65,6 +67,7 @@ variable "image_version" { variable "admin_username" { description = "administrator user name" + default = "vmadmin" } variable "admin_password" {