From 630f371b0ca8f4b5a419a9282fb4ff3763b0e35b Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Wed, 29 Mar 2017 11:49:38 -0700 Subject: [PATCH 01/82] Fix crash in import azurerm_local_network_gateway The plug-in crashes if "localNetworkGateways" is not found in the id parameter. The fix is to verify the parameter before proceeding. Also the "import" example in the documentation is wrong, "localNetworkGateways" should be case sensitive. The current example actually causes the plugin to crash due to the bug. --- .../providers/azurerm/resource_arm_local_network_gateway.go | 3 +++ .../providers/azurerm/r/local_network_gateway.html.markdown | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 6287f0ce2..6038e47c3 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -101,6 +101,9 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} return err } name := id.Path["localNetworkGateways"] + if name == "" { + return fmt.Errorf("Cannot find parameter 'localNetworkGateways' from '%s'", id.Path) + } resGroup := id.ResourceGroup resp, err := lnetClient.Get(resGroup, name) diff --git a/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown b/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown index ac74bafa5..b4681b6e4 100644 --- a/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown +++ b/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown @@ -52,5 +52,5 @@ The following attributes are exported: Local Network Gateways can be imported using the `resource id`, e.g. ``` -terraform import azurerm_local_network_gateway.lng1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.network/localnetworkgateways/lng1 +terraform import azurerm_local_network_gateway.lng1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/localNetworkGateways/lng1 ``` From 1db5efc8bcb871ef92b5655aac5f1a1fe91ccd1c Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Thu, 30 Mar 2017 15:35:29 -0700 Subject: [PATCH 02/82] Better error message for LNG import error. --- .../azurerm/resource_arm_local_network_gateway.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 6038e47c3..8d23a2ae7 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -102,7 +102,12 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} } name := id.Path["localNetworkGateways"] if name == "" { - return fmt.Errorf("Cannot find parameter 'localNetworkGateways' from '%s'", id.Path) + var pathString, sp string + for key, value := range id.Path { + pathString += fmt.Sprintf("%s'%s:%s'", sp, key, value) + sp = ", " + } + return fmt.Errorf("Cannot find 'localNetworkGateways' in [%s], make sure it is specified in the ID parameter", pathString) } resGroup := id.ResourceGroup From ebd5dc5d3dde461eb61abfb4459350ce0e520731 Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Thu, 30 Mar 2017 18:44:39 -0700 Subject: [PATCH 03/82] Even better error message. --- .../azurerm/resource_arm_local_network_gateway.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 8d23a2ae7..64c2243fb 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -102,12 +102,7 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} } name := id.Path["localNetworkGateways"] if name == "" { - var pathString, sp string - for key, value := range id.Path { - pathString += fmt.Sprintf("%s'%s:%s'", sp, key, value) - sp = ", " - } - return fmt.Errorf("Cannot find 'localNetworkGateways' in [%s], make sure it is specified in the ID parameter", pathString) + return fmt.Errorf("Cannot find 'localNetworkGateways' in '%s', make sure it is specified in the ID parameter", d.Id()) } resGroup := id.ResourceGroup From 65c4b9ca3886b77d9d3b7ce06c19c58089e68524 Mon Sep 17 00:00:00 2001 From: Jie Wang Date: Fri, 31 Mar 2017 13:55:39 -0700 Subject: [PATCH 04/82] Revert "Even better error message." This reverts commit ebd5dc5d3dde461eb61abfb4459350ce0e520731. --- .../azurerm/resource_arm_local_network_gateway.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 64c2243fb..8d23a2ae7 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -102,7 +102,12 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} } name := id.Path["localNetworkGateways"] if name == "" { - return fmt.Errorf("Cannot find 'localNetworkGateways' in '%s', make sure it is specified in the ID parameter", d.Id()) + var pathString, sp string + for key, value := range id.Path { + pathString += fmt.Sprintf("%s'%s:%s'", sp, key, value) + sp = ", " + } + return fmt.Errorf("Cannot find 'localNetworkGateways' in [%s], make sure it is specified in the ID parameter", pathString) } resGroup := id.ResourceGroup From 8308ed22461fe8f07dfb87ab7f57b621c57c98e5 Mon Sep 17 00:00:00 2001 From: Jie Wang Date: Fri, 31 Mar 2017 13:55:52 -0700 Subject: [PATCH 05/82] Revert "Better error message for LNG import error." This reverts commit 1db5efc8bcb871ef92b5655aac5f1a1fe91ccd1c. --- .../azurerm/resource_arm_local_network_gateway.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 8d23a2ae7..6038e47c3 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -102,12 +102,7 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} } name := id.Path["localNetworkGateways"] if name == "" { - var pathString, sp string - for key, value := range id.Path { - pathString += fmt.Sprintf("%s'%s:%s'", sp, key, value) - sp = ", " - } - return fmt.Errorf("Cannot find 'localNetworkGateways' in [%s], make sure it is specified in the ID parameter", pathString) + return fmt.Errorf("Cannot find parameter 'localNetworkGateways' from '%s'", id.Path) } resGroup := id.ResourceGroup From 469b9a2d232fad25d14bbd7e878824a1053f5da9 Mon Sep 17 00:00:00 2001 From: Jie Wang Date: Fri, 31 Mar 2017 13:56:15 -0700 Subject: [PATCH 06/82] Revert "Fix crash in import azurerm_local_network_gateway" This reverts commit 630f371b0ca8f4b5a419a9282fb4ff3763b0e35b. --- .../providers/azurerm/resource_arm_local_network_gateway.go | 3 --- .../providers/azurerm/r/local_network_gateway.html.markdown | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 6038e47c3..6287f0ce2 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -101,9 +101,6 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} return err } name := id.Path["localNetworkGateways"] - if name == "" { - return fmt.Errorf("Cannot find parameter 'localNetworkGateways' from '%s'", id.Path) - } resGroup := id.ResourceGroup resp, err := lnetClient.Get(resGroup, name) diff --git a/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown b/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown index b4681b6e4..ac74bafa5 100644 --- a/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown +++ b/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown @@ -52,5 +52,5 @@ The following attributes are exported: Local Network Gateways can be imported using the `resource id`, e.g. ``` -terraform import azurerm_local_network_gateway.lng1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/localNetworkGateways/lng1 +terraform import azurerm_local_network_gateway.lng1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.network/localnetworkgateways/lng1 ``` From 48f749cb28c37bdab7ee46ec9e8755b7a1ec46b7 Mon Sep 17 00:00:00 2001 From: Jie Wang Date: Fri, 31 Mar 2017 13:57:01 -0700 Subject: [PATCH 07/82] provider/azurerm: Fix crash when importing Local Network Gateway (#9198) --- .../providers/azurerm/resource_arm_local_network_gateway.go | 3 +++ .../providers/azurerm/r/local_network_gateway.html.markdown | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_local_network_gateway.go b/builtin/providers/azurerm/resource_arm_local_network_gateway.go index 6287f0ce2..64c2243fb 100644 --- a/builtin/providers/azurerm/resource_arm_local_network_gateway.go +++ b/builtin/providers/azurerm/resource_arm_local_network_gateway.go @@ -101,6 +101,9 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} return err } name := id.Path["localNetworkGateways"] + if name == "" { + return fmt.Errorf("Cannot find 'localNetworkGateways' in '%s', make sure it is specified in the ID parameter", d.Id()) + } resGroup := id.ResourceGroup resp, err := lnetClient.Get(resGroup, name) diff --git a/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown b/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown index ac74bafa5..b4681b6e4 100644 --- a/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown +++ b/website/source/docs/providers/azurerm/r/local_network_gateway.html.markdown @@ -52,5 +52,5 @@ The following attributes are exported: Local Network Gateways can be imported using the `resource id`, e.g. ``` -terraform import azurerm_local_network_gateway.lng1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.network/localnetworkgateways/lng1 +terraform import azurerm_local_network_gateway.lng1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/localNetworkGateways/lng1 ``` From 2c1c999a37572b2a53a9bf1d70f2cf1bea014df7 Mon Sep 17 00:00:00 2001 From: anniehedgpeth Date: Mon, 17 Apr 2017 15:46:01 -0500 Subject: [PATCH 08/82] initial commit - deploys successfully --- examples/101-vm-simple-linux/README.md | 8 ++ examples/101-vm-simple-linux/main.tf | 120 ++++++++++++++++++++++ examples/101-vm-simple-linux/variables.tf | 78 ++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 examples/101-vm-simple-linux/README.md create mode 100644 examples/101-vm-simple-linux/main.tf create mode 100644 examples/101-vm-simple-linux/variables.tf diff --git a/examples/101-vm-simple-linux/README.md b/examples/101-vm-simple-linux/README.md new file mode 100644 index 000000000..92446ee9e --- /dev/null +++ b/examples/101-vm-simple-linux/README.md @@ -0,0 +1,8 @@ +# Deploy a simple Linux VM +**ubuntu** + +This template allows you to deploy a simple Linux VM using a few different options for the Ubuntu version, using the latest patched version. This will deploy a A1 size VM in the resource group location and return the FQDN of the VM. + +This template takes a minimum amount of parameters and deploys a Linux VM, using the latest patched version. + +Azure requires that an application is added to Azure Active Directory to generate the client_id, client_secret, and tenant_id needed by Terraform (subscription_id can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this. \ No newline at end of file diff --git a/examples/101-vm-simple-linux/main.tf b/examples/101-vm-simple-linux/main.tf new file mode 100644 index 000000000..f0ef74241 --- /dev/null +++ b/examples/101-vm-simple-linux/main.tf @@ -0,0 +1,120 @@ +resource "azurerm_resource_group" "rg" { + name = "${var.resource_group}" + location = "${var.location}" +} + +resource "azurerm_virtual_network" "vnet" { + name = "${var.virtual_network_name}" + location = "${var.location}" + address_space = ["${var.address_space}"] + resource_group_name = "${azurerm_resource_group.rg.name}" +} + +resource "azurerm_subnet" "subnet" { + name = "${var.rg_prefix}subnet" + virtual_network_name = "${azurerm_virtual_network.vnet.name}" + resource_group_name = "${azurerm_resource_group.rg.name}" + address_prefix = "${var.subnet_prefix}" +} + +resource "azurerm_network_interface" "nic" { + name = "${var.rg_prefix}nic" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + + ip_configuration { + name = "${var.rg_prefix}ipconfig" + subnet_id = "${azurerm_subnet.subnet.id}" + private_ip_address_allocation = "Dynamic" + public_ip_address_id = "${azurerm_public_ip.pip.id}" + } +} + +resource "azurerm_public_ip" "pip" { + name = "${var.rg_prefix}-ip" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + public_ip_address_allocation = "dynamic" + domain_name_label = "${var.dns_name}" +} + +resource "azurerm_storage_account" "stor" { + name = "${var.hostname}stor" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + account_type = "${var.storage_account_type}" +} + +resource "azurerm_storage_container" "storc" { + name = "${var.hostname}-vhds" + resource_group_name = "${azurerm_resource_group.rg.name}" + storage_account_name = "${azurerm_storage_account.stor.name}" + container_access_type = "private" +} + +resource "azurerm_managed_disk" "disk1" { + name = "${var.hostname}-osdisk1" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "30" +} + +resource "azurerm_managed_disk" "disk2" { + name = "${var.hostname}-disk2" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1023" +} + +resource "azurerm_virtual_machine" "vm" { + name = "${var.rg_prefix}vm" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + vm_size = "${var.vm_size}" + network_interface_ids = ["${azurerm_network_interface.nic.id}"] + + storage_image_reference { + publisher = "${var.image_publisher}" + offer = "${var.image_offer}" + sku = "${var.image_sku}" + version = "${var.image_version}" + } + + storage_os_disk { + name = "${var.hostname}-osdisk1" + vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-osdisk1.vhd" + caching = "ReadWrite" + create_option = "FromImage" + } + + storage_data_disk { + name = "${var.hostname}-disk2" + vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-disk2.vhd" + disk_size_gb = "1023" + create_option = "Empty" + lun = 0 + } + + os_profile { + computer_name = "${var.hostname}" + admin_username = "${var.admin_username}" + admin_password = "${var.admin_password}" + } + + boot_diagnostics { + enabled = "true" + storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}" + } +} + +output "hostname" { + value = "${var.hostname}" +} + +output "vm_fqdn" { + value = "${azurerm_public_ip.pip.fqdn}" +} \ No newline at end of file diff --git a/examples/101-vm-simple-linux/variables.tf b/examples/101-vm-simple-linux/variables.tf new file mode 100644 index 000000000..b2ab32721 --- /dev/null +++ b/examples/101-vm-simple-linux/variables.tf @@ -0,0 +1,78 @@ +variable "resource_group" { + description = "The name of the resource group in which to create the virtual network." + default = "myresourcegroup" +} + +variable "rg_prefix" { + description = "The shortened abbreviation to represent your resource group that will go on the front of some resources." + default = "rg" +} + +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" { + description = "The name for the virtual network." + default = "vnet" +} + +variable "address_space" { + description = "The address space that is used by the virtual network. You can supply more than one address space. Changing this forces a new resource to be created." + default = "10.0.0.0/16" +} + +variable "subnet_prefix" { + description = "The address prefix to use for the subnet." + default = "10.0.10.0/24" +} + +variable "storage_account_type" { + description = "Specifies the name of the storage account. Changing this forces a new resource to be created. This must be unique across the entire Azure service, not just within the resource group." + default = "Standard_LRS" +} + +variable "vm_size" { + description = "Specifies the name of the virtual machine resource. Changing this forces a new resource to be created." + default = "Standard_A0" +} + +variable "image_publisher" { + description = "name of the publisher of the image (az vm image list)" + default = "Canonical" +} + +variable "image_offer" { + description = "the name of the offer (az vm image list)" + default = "UbuntuServer" +} + +variable "image_sku" { + description = "image sku to apply (az vm image list)" + default = "16.04-LTS" +} + +variable "image_version" { + description = "version of the image to apply (az vm image list)" + default = "latest" +} + +variable "hostname" { + description = "VM name referenced also in storage-related names." + default = "myvm" +} + +variable "dns_name" { + description = " Label for the Domain Name. Will be used to make up the FQDN. If a domain name label is specified, an A DNS record is created for the public IP in the Microsoft Azure DNS system." +} + +variable "admin_username" { + description = "administrator user name" + default = "vmadmin" +} + +variable "admin_password" { + description = "administrator password (recommended to disable password auth)" + default = "T3rr@f0rmP@ssword" +} From 84ebc6795827d843e22370e5859229d75427ee3e Mon Sep 17 00:00:00 2001 From: anniehedgpeth Date: Mon, 17 Apr 2017 18:02:29 -0500 Subject: [PATCH 09/82] gitignore added --- examples/101-vm-simple-linux/.gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/101-vm-simple-linux/.gitignore diff --git a/examples/101-vm-simple-linux/.gitignore b/examples/101-vm-simple-linux/.gitignore new file mode 100644 index 000000000..352c8a2b9 --- /dev/null +++ b/examples/101-vm-simple-linux/.gitignore @@ -0,0 +1,3 @@ +terraform.tfstate* +terraform.tfvars* +creds.tf* From 5da82e699317fe372bf210f0628d8099445dc5af Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Tue, 18 Apr 2017 17:51:51 -0500 Subject: [PATCH 10/82] added .travis.yml and deploy.sh --- examples/101-vm-simple-linux/.travis.yml | 31 ++++++++++++++++++++++++ examples/101-vm-simple-linux/deploy.sh | 29 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 examples/101-vm-simple-linux/.travis.yml create mode 100644 examples/101-vm-simple-linux/deploy.sh diff --git a/examples/101-vm-simple-linux/.travis.yml b/examples/101-vm-simple-linux/.travis.yml new file mode 100644 index 000000000..1517dbdd0 --- /dev/null +++ b/examples/101-vm-simple-linux/.travis.yml @@ -0,0 +1,31 @@ +language: generic + +# establish environment variables +# env: +# global: +# - GH_USER_NAME="travis-ci" +# - GH_USER_EMAIL="mikedball@gmail.com" +# - GH_REPO="10thmagnitude/terraform" +# # encrypted GH_TOKEN and AWS credentials +# - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" + +branches: + only: + # - master + - /^(?i:101).*$/ + +# install terraform +before_deploy: + - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip + - sudo unzip terraform.zip -d /opt/terraform + - sudo ln -s /opt/terraform/terraform /usr/bin/terraform + - rm -f terraform.zip + +# terraform apply +deploy: + - provider: script + skip_cleanup: true + script: "./deploy.sh" + on: + repo: 10thmagnitude/terraform + branch: master diff --git a/examples/101-vm-simple-linux/deploy.sh b/examples/101-vm-simple-linux/deploy.sh new file mode 100644 index 000000000..c2d949681 --- /dev/null +++ b/examples/101-vm-simple-linux/deploy.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -o errexit -o nounset + +cd terraform + +terraform get +terraform plan +terraform apply + +# 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 From 4febc170b71e5a6348614326523359017e2cd45b Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Tue, 18 Apr 2017 18:37:39 -0500 Subject: [PATCH 11/82] updated travis.yml for builds on terraform examples --- .travis.yml | 61 ++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04cc6f309..535c4831d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,42 +1,27 @@ -dist: trusty -sudo: false -language: go -go: -- 1.8 +language: generic -# add TF_CONSUL_TEST=1 to run consul tests -# they were causing timouts in travis +# establish environment variables env: - - CONSUL_VERSION=0.7.5 GOMAXPROCS=4 + - TEST_DIR=examples/101-vm-simple-linux +# global: +# - GH_USER_NAME="travis-ci" +# - GH_USER_EMAIL="mikedball@gmail.com" +# - GH_REPO="10thmagnitude/terraform" +# # encrypted GH_TOKEN and AWS credentials +# - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" -# Fetch consul for the backend and provider tests -before_install: - - curl -sLo consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip - - unzip consul.zip - - mkdir ~/bin - - mv consul ~/bin - - export PATH="~/bin:$PATH" +# install terraform +before_deploy: + - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip + - sudo unzip terraform.zip -d /opt/terraform + - sudo ln -s /opt/terraform/terraform /usr/bin/terraform + - rm -f terraform.zip -install: -# This script is used by the Travis build to install a cookie for -# go.googlesource.com so rate limits are higher when using `go get` to fetch -# packages that live there. -# See: https://github.com/golang/go/issues/12933 -- bash scripts/gogetcookie.sh -- go get github.com/kardianos/govendor -script: -- make vet vendor-status test -- GOOS=windows go build -branches: - only: - - master -notifications: - irc: - channels: - - irc.freenode.org#terraform-tool - skip_join: true - use_notice: true -matrix: - fast_finish: true - allow_failures: - - go: tip +# terraform apply +deploy: + - provider: script + skip_cleanup: true + script: "./deploy.sh" + on: + repo: 10thmagnitude/terraform + branch: 101-vm-simple-linux From b7f8ae542a466a978cd749de1d21ac5b9a282ccb Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Tue, 18 Apr 2017 18:44:06 -0500 Subject: [PATCH 12/82] added directory to build matrix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 535c4831d..8ef73ccb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: "./deploy.sh" + script: cd $TEST_DIR && "./deploy.sh" on: repo: 10thmagnitude/terraform branch: 101-vm-simple-linux From 8d9e3e1b80725e3e3e94421521e791fc859e0daa Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Tue, 18 Apr 2017 19:09:15 -0500 Subject: [PATCH 13/82] added deploy script, updated travis.yml to build topic- branches --- .travis.yml | 62 ++++++++++++++++++++++------------------------------- deploy.sh | 27 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 deploy.sh diff --git a/.travis.yml b/.travis.yml index 04cc6f309..f6887ef44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,42 +1,32 @@ -dist: trusty -sudo: false -language: go -go: -- 1.8 +language: generic -# add TF_CONSUL_TEST=1 to run consul tests -# they were causing timouts in travis +# establish environment variables env: - - CONSUL_VERSION=0.7.5 GOMAXPROCS=4 + - TEST_DIR=examples/101-vm-simple-linux +# global: +# - GH_USER_NAME="travis-ci" +# - GH_USER_EMAIL="mikedball@gmail.com" +# - GH_REPO="10thmagnitude/terraform" +# # encrypted GH_TOKEN and AWS credentials +# - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" -# Fetch consul for the backend and provider tests -before_install: - - curl -sLo consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip - - unzip consul.zip - - mkdir ~/bin - - mv consul ~/bin - - export PATH="~/bin:$PATH" - -install: -# This script is used by the Travis build to install a cookie for -# go.googlesource.com so rate limits are higher when using `go get` to fetch -# packages that live there. -# See: https://github.com/golang/go/issues/12933 -- bash scripts/gogetcookie.sh -- go get github.com/kardianos/govendor -script: -- make vet vendor-status test -- GOOS=windows go build branches: only: - master -notifications: - irc: - channels: - - irc.freenode.org#terraform-tool - skip_join: true - use_notice: true -matrix: - fast_finish: true - allow_failures: - - go: tip + - /^(?i:topic)-.*$/ + +# install terraform +before_deploy: + - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip + - sudo unzip terraform.zip -d /opt/terraform + - sudo ln -s /opt/terraform/terraform /usr/bin/terraform + - rm -f terraform.zip + +# terraform apply +deploy: + - provider: script + skip_cleanup: true + script: cd $TEST_DIR && "./deploy.sh" + on: + repo: 10thmagnitude/terraform + branch: 101-vm-simple-linux diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 000000000..00b5266b8 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -o errexit -o nounset + +terraform get +terraform plan +terraform apply + +# 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 From 601735b8733f8f6154994b3b7df28ae2cf74f713 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Tue, 18 Apr 2017 19:10:41 -0500 Subject: [PATCH 14/82] updated .travis.yml to read branches prefixed with topic- --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8ef73ccb4..f6887ef44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,11 @@ env: # # encrypted GH_TOKEN and AWS credentials # - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" +branches: + only: + - master + - /^(?i:topic)-.*$/ + # install terraform before_deploy: - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip From 90d948bccaaec5ef03fbeaa24635b0e10083bce5 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 10:12:27 -0500 Subject: [PATCH 15/82] cleanup and simplify deploy script --- deploy.sh | 27 --------------------- examples/101-vm-simple-linux/.travis.yml | 31 ------------------------ examples/101-vm-simple-linux/deploy.sh | 2 -- 3 files changed, 60 deletions(-) delete mode 100644 deploy.sh delete mode 100644 examples/101-vm-simple-linux/.travis.yml diff --git a/deploy.sh b/deploy.sh deleted file mode 100644 index 00b5266b8..000000000 --- a/deploy.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -set -o errexit -o nounset - -terraform get -terraform plan -terraform apply - -# 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 diff --git a/examples/101-vm-simple-linux/.travis.yml b/examples/101-vm-simple-linux/.travis.yml deleted file mode 100644 index 1517dbdd0..000000000 --- a/examples/101-vm-simple-linux/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: generic - -# establish environment variables -# env: -# global: -# - GH_USER_NAME="travis-ci" -# - GH_USER_EMAIL="mikedball@gmail.com" -# - GH_REPO="10thmagnitude/terraform" -# # encrypted GH_TOKEN and AWS credentials -# - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" - -branches: - only: - # - master - - /^(?i:101).*$/ - -# install terraform -before_deploy: - - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip - - sudo unzip terraform.zip -d /opt/terraform - - sudo ln -s /opt/terraform/terraform /usr/bin/terraform - - rm -f terraform.zip - -# terraform apply -deploy: - - provider: script - skip_cleanup: true - script: "./deploy.sh" - on: - repo: 10thmagnitude/terraform - branch: master diff --git a/examples/101-vm-simple-linux/deploy.sh b/examples/101-vm-simple-linux/deploy.sh index c2d949681..00b5266b8 100644 --- a/examples/101-vm-simple-linux/deploy.sh +++ b/examples/101-vm-simple-linux/deploy.sh @@ -2,8 +2,6 @@ set -o errexit -o nounset -cd terraform - terraform get terraform plan terraform apply From bbdb2cef53f55b85e0df48247ee7e0d14a55ad12 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 10:28:11 -0500 Subject: [PATCH 16/82] removed branch restrictions on deploy --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6887ef44..69386fcf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,9 @@ branches: - master - /^(?i:topic)-.*$/ + +##todo: switch to before_script and script + # install terraform before_deploy: - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip @@ -27,6 +30,3 @@ deploy: - provider: script skip_cleanup: true script: cd $TEST_DIR && "./deploy.sh" - on: - repo: 10thmagnitude/terraform - branch: 101-vm-simple-linux From ca65fe31cec12065866bedff0403457b9ee429b9 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 10:46:54 -0500 Subject: [PATCH 17/82] disabling travis deployment on master short-term --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 69386fcf0..c34013696 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,3 +30,7 @@ deploy: - provider: script skip_cleanup: true script: cd $TEST_DIR && "./deploy.sh" + on: + repo: 10thmagnitude/terraform + branch: 101-vm-simple-linux + condition: false # re-enable when examples exist in master From d8131c2d5e924d2b28ebf927be6947c07477d790 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 10:51:07 -0500 Subject: [PATCH 18/82] cleanup; permitted topic branch --- .travis.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6887ef44..2d122f68d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,16 +3,9 @@ language: generic # establish environment variables env: - TEST_DIR=examples/101-vm-simple-linux -# global: -# - GH_USER_NAME="travis-ci" -# - GH_USER_EMAIL="mikedball@gmail.com" -# - GH_REPO="10thmagnitude/terraform" -# # encrypted GH_TOKEN and AWS credentials -# - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" branches: only: - - master - /^(?i:topic)-.*$/ # install terraform @@ -22,11 +15,11 @@ before_deploy: - sudo ln -s /opt/terraform/terraform /usr/bin/terraform - rm -f terraform.zip -# terraform apply +# terraform deploy script deploy: - provider: script skip_cleanup: true script: cd $TEST_DIR && "./deploy.sh" on: repo: 10thmagnitude/terraform - branch: 101-vm-simple-linux + branch: topic-101-vm-simple-linux From 3ce7a2499ada4166f9f6f496926ac7df27796288 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 10:59:21 -0500 Subject: [PATCH 19/82] add execute permissions to deploy.sh file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2d122f68d..edf26582c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && "./deploy.sh" + script: cd $TEST_DIR && chmod +x ./deploy.sh && ./deploy.sh on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux From 832ab98094240051c557982b288fd147cb60d6e5 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 12:35:51 -0500 Subject: [PATCH 20/82] generate random string for hostname --- examples/101-vm-simple-linux/deploy.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/101-vm-simple-linux/deploy.sh b/examples/101-vm-simple-linux/deploy.sh index 00b5266b8..7e82233bc 100644 --- a/examples/101-vm-simple-linux/deploy.sh +++ b/examples/101-vm-simple-linux/deploy.sh @@ -2,9 +2,11 @@ set -o errexit -o nounset +HOSTNAME=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) + terraform get terraform plan -terraform apply +terraform apply HOSTNAME # echo "Setting git user name" # git config user.name $GH_USER_NAME From 62dc7320c542908d9bc588744be4fff04c1adeae Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 12:43:18 -0500 Subject: [PATCH 21/82] updated syntax for arguments to terraform --- examples/101-vm-simple-linux/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/101-vm-simple-linux/deploy.sh b/examples/101-vm-simple-linux/deploy.sh index 7e82233bc..dde0649ce 100644 --- a/examples/101-vm-simple-linux/deploy.sh +++ b/examples/101-vm-simple-linux/deploy.sh @@ -5,8 +5,8 @@ set -o errexit -o nounset HOSTNAME=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) terraform get -terraform plan -terraform apply HOSTNAME +terraform plan -var 'dns_name=$HOSTNAME' +terraform apply -var 'dns_name=$HOSTNAME' # echo "Setting git user name" # git config user.name $GH_USER_NAME From c4ac9c3dbb52490be1c839002919cb6abafce25d Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 16:38:18 -0500 Subject: [PATCH 22/82] fixed syntax for terraform variables --- examples/101-vm-simple-linux/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/101-vm-simple-linux/deploy.sh b/examples/101-vm-simple-linux/deploy.sh index dde0649ce..3d95969f6 100644 --- a/examples/101-vm-simple-linux/deploy.sh +++ b/examples/101-vm-simple-linux/deploy.sh @@ -5,8 +5,8 @@ set -o errexit -o nounset HOSTNAME=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) terraform get -terraform plan -var 'dns_name=$HOSTNAME' -terraform apply -var 'dns_name=$HOSTNAME' +terraform plan -var 'dns_name='$HOSTNAME +terraform apply -var 'dns_name='$HOSTNAME # echo "Setting git user name" # git config user.name $GH_USER_NAME From 048ab5a77440132fc2b77d77bfe60bb4c789993f Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 17:59:56 -0500 Subject: [PATCH 23/82] renamed folder; updated deployment script; prompt for additional variables --- .travis.yml | 2 +- examples/101-vm-simple-linux/deploy.sh | 22 +++++++++++-- .../.gitignore | 0 .../README.md | 0 examples/azure-vm-simple-linux/deploy.sh | 33 +++++++++++++++++++ .../main.tf | 4 +-- .../variables.tf | 3 -- 7 files changed, 55 insertions(+), 9 deletions(-) rename examples/{101-vm-simple-linux => azure-vm-simple-linux}/.gitignore (100%) rename examples/{101-vm-simple-linux => azure-vm-simple-linux}/README.md (100%) create mode 100644 examples/azure-vm-simple-linux/deploy.sh rename examples/{101-vm-simple-linux => azure-vm-simple-linux}/main.tf (98%) rename examples/{101-vm-simple-linux => azure-vm-simple-linux}/variables.tf (96%) diff --git a/.travis.yml b/.travis.yml index edf26582c..06fa72134 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: generic # establish environment variables env: - - TEST_DIR=examples/101-vm-simple-linux + - TEST_DIR=examples/azure-vm-simple-linux branches: only: diff --git a/examples/101-vm-simple-linux/deploy.sh b/examples/101-vm-simple-linux/deploy.sh index 3d95969f6..a900e65c7 100644 --- a/examples/101-vm-simple-linux/deploy.sh +++ b/examples/101-vm-simple-linux/deploy.sh @@ -2,11 +2,27 @@ set -o errexit -o nounset -HOSTNAME=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) +# generate a unique string for CI deployment +KEY=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) terraform get -terraform plan -var 'dns_name='$HOSTNAME -terraform apply -var 'dns_name='$HOSTNAME + +terraform plan \ + -var 'dns_name='$KEY \ + -var 'admin_password='$KEY \ + -var 'admin_username='$KEY \ + -var 'resource_group='$KEY + +terraform apply + -var 'dns_name='$KEY \ + -var 'admin_password='$KEY \ + -var 'admin_username='$KEY \ + -var 'resource_group='$KEY + + +# TODO: determine external validation, possibly Azure CLI + +terraform destroy # echo "Setting git user name" # git config user.name $GH_USER_NAME diff --git a/examples/101-vm-simple-linux/.gitignore b/examples/azure-vm-simple-linux/.gitignore similarity index 100% rename from examples/101-vm-simple-linux/.gitignore rename to examples/azure-vm-simple-linux/.gitignore diff --git a/examples/101-vm-simple-linux/README.md b/examples/azure-vm-simple-linux/README.md similarity index 100% rename from examples/101-vm-simple-linux/README.md rename to examples/azure-vm-simple-linux/README.md diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh new file mode 100644 index 000000000..6028622c3 --- /dev/null +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -o errexit -o nounset + +HOSTNAME=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) + +terraform get +terraform plan -var 'dns_name='$HOSTNAME +terraform apply -var 'dns_name='$HOSTNAME + +# TODO: determine external validation, possibly Azure CLI + +terraform destroy + +# 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 diff --git a/examples/101-vm-simple-linux/main.tf b/examples/azure-vm-simple-linux/main.tf similarity index 98% rename from examples/101-vm-simple-linux/main.tf rename to examples/azure-vm-simple-linux/main.tf index f0ef74241..a94d4325c 100644 --- a/examples/101-vm-simple-linux/main.tf +++ b/examples/azure-vm-simple-linux/main.tf @@ -39,7 +39,7 @@ resource "azurerm_public_ip" "pip" { } resource "azurerm_storage_account" "stor" { - name = "${var.hostname}stor" + name = "${var.dns_name}stor" location = "${var.location}" resource_group_name = "${azurerm_resource_group.rg.name}" account_type = "${var.storage_account_type}" @@ -117,4 +117,4 @@ output "hostname" { output "vm_fqdn" { value = "${azurerm_public_ip.pip.fqdn}" -} \ No newline at end of file +} diff --git a/examples/101-vm-simple-linux/variables.tf b/examples/azure-vm-simple-linux/variables.tf similarity index 96% rename from examples/101-vm-simple-linux/variables.tf rename to examples/azure-vm-simple-linux/variables.tf index b2ab32721..915751c8c 100644 --- a/examples/101-vm-simple-linux/variables.tf +++ b/examples/azure-vm-simple-linux/variables.tf @@ -1,6 +1,5 @@ variable "resource_group" { description = "The name of the resource group in which to create the virtual network." - default = "myresourcegroup" } variable "rg_prefix" { @@ -69,10 +68,8 @@ variable "dns_name" { variable "admin_username" { description = "administrator user name" - default = "vmadmin" } variable "admin_password" { description = "administrator password (recommended to disable password auth)" - default = "T3rr@f0rmP@ssword" } From d0973b77c1dd943db8f115301e2cb5ae9bfdef06 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 18:20:56 -0500 Subject: [PATCH 24/82] moved outputs to outputs.tf; added sshCommand --- examples/azure-vm-simple-linux/main.tf | 8 -------- examples/azure-vm-simple-linux/outputs.tf | 11 +++++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 examples/azure-vm-simple-linux/outputs.tf diff --git a/examples/azure-vm-simple-linux/main.tf b/examples/azure-vm-simple-linux/main.tf index a94d4325c..639f22707 100644 --- a/examples/azure-vm-simple-linux/main.tf +++ b/examples/azure-vm-simple-linux/main.tf @@ -110,11 +110,3 @@ resource "azurerm_virtual_machine" "vm" { storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}" } } - -output "hostname" { - value = "${var.hostname}" -} - -output "vm_fqdn" { - value = "${azurerm_public_ip.pip.fqdn}" -} diff --git a/examples/azure-vm-simple-linux/outputs.tf b/examples/azure-vm-simple-linux/outputs.tf new file mode 100644 index 000000000..9c762e3a9 --- /dev/null +++ b/examples/azure-vm-simple-linux/outputs.tf @@ -0,0 +1,11 @@ +output "hostname" { + value = "${var.hostname}" +} + +output "vm_fqdn" { + value = "${azurerm_public_ip.pip.fqdn}" +} + +output "sshCommand" { + value = "${concat('ssh ', var.admin_username, '@', azurerm_public_ip.pip.fqdn)}" +} From 3dce8c2c78c7b751dce37c1b44f30e5cea345a3f Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 18:28:42 -0500 Subject: [PATCH 25/82] was working on the wrong deploy.sh........ :( --- examples/101-vm-simple-linux/deploy.sh | 45 ------------------------ examples/azure-vm-simple-linux/deploy.sh | 18 ++++++++-- 2 files changed, 15 insertions(+), 48 deletions(-) delete mode 100644 examples/101-vm-simple-linux/deploy.sh diff --git a/examples/101-vm-simple-linux/deploy.sh b/examples/101-vm-simple-linux/deploy.sh deleted file mode 100644 index a900e65c7..000000000 --- a/examples/101-vm-simple-linux/deploy.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -set -o errexit -o nounset - -# generate a unique string for CI deployment -KEY=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) - -terraform get - -terraform plan \ - -var 'dns_name='$KEY \ - -var 'admin_password='$KEY \ - -var 'admin_username='$KEY \ - -var 'resource_group='$KEY - -terraform apply - -var 'dns_name='$KEY \ - -var 'admin_password='$KEY \ - -var 'admin_username='$KEY \ - -var 'resource_group='$KEY - - -# TODO: determine external validation, possibly Azure CLI - -terraform destroy - -# 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 diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 6028622c3..a900e65c7 100644 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -2,11 +2,23 @@ set -o errexit -o nounset -HOSTNAME=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) +# generate a unique string for CI deployment +KEY=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) terraform get -terraform plan -var 'dns_name='$HOSTNAME -terraform apply -var 'dns_name='$HOSTNAME + +terraform plan \ + -var 'dns_name='$KEY \ + -var 'admin_password='$KEY \ + -var 'admin_username='$KEY \ + -var 'resource_group='$KEY + +terraform apply + -var 'dns_name='$KEY \ + -var 'admin_password='$KEY \ + -var 'admin_username='$KEY \ + -var 'resource_group='$KEY + # TODO: determine external validation, possibly Azure CLI From 44d416ca8eb6f2b4cade7d6f0ec6202a36387561 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 18:34:44 -0500 Subject: [PATCH 26/82] fixed quotes --- examples/azure-vm-simple-linux/outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-vm-simple-linux/outputs.tf b/examples/azure-vm-simple-linux/outputs.tf index 9c762e3a9..e0e255a9e 100644 --- a/examples/azure-vm-simple-linux/outputs.tf +++ b/examples/azure-vm-simple-linux/outputs.tf @@ -7,5 +7,5 @@ output "vm_fqdn" { } output "sshCommand" { - value = "${concat('ssh ', var.admin_username, '@', azurerm_public_ip.pip.fqdn)}" + value = "${concat("ssh ", var.admin_username, "@", azurerm_public_ip.pip.fqdn)}" } From 42b4ddc737e2f0b7f9fd4661ab2632da3afa35f0 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 18:41:38 -0500 Subject: [PATCH 27/82] plan now produces output plan, apply now consumes outputted plan --- examples/azure-vm-simple-linux/deploy.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) mode change 100644 => 100755 examples/azure-vm-simple-linux/deploy.sh diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh old mode 100644 new mode 100755 index a900e65c7..3e34d2824 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -12,12 +12,9 @@ terraform plan \ -var 'admin_password='$KEY \ -var 'admin_username='$KEY \ -var 'resource_group='$KEY + -out ./out.tfplan -terraform apply - -var 'dns_name='$KEY \ - -var 'admin_password='$KEY \ - -var 'admin_username='$KEY \ - -var 'resource_group='$KEY +terraform apply ./out.tfplan # TODO: determine external validation, possibly Azure CLI From f52b7a9d854434619586b7d7eec9776d419bbed9 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 18:44:55 -0500 Subject: [PATCH 28/82] fixed -out syntax --- examples/azure-vm-simple-linux/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 3e34d2824..41ed7e432 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -12,9 +12,9 @@ terraform plan \ -var 'admin_password='$KEY \ -var 'admin_username='$KEY \ -var 'resource_group='$KEY - -out ./out.tfplan + -out=out.tfplan -terraform apply ./out.tfplan +terraform apply out.tfplan # TODO: determine external validation, possibly Azure CLI From 1d7d3f1b45cf9810fddfdeaeaff80ab0f9a1b640 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 18:56:12 -0500 Subject: [PATCH 29/82] added missing \ to plan command --- examples/azure-vm-simple-linux/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 41ed7e432..8bebe59bd 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -11,7 +11,7 @@ terraform plan \ -var 'dns_name='$KEY \ -var 'admin_password='$KEY \ -var 'admin_username='$KEY \ - -var 'resource_group='$KEY + -var 'resource_group='$KEY \ -out=out.tfplan terraform apply out.tfplan From acaea87c93e35a09cbc80065b56191a655386307 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 19:02:39 -0500 Subject: [PATCH 30/82] nixed the numbers from string generation --- examples/azure-vm-simple-linux/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 8bebe59bd..f9bdb63c1 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -3,7 +3,7 @@ set -o errexit -o nounset # generate a unique string for CI deployment -KEY=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) +KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 16) terraform get From 4fb55b0c5e17b9635d786e77b5909c0aabcb63aa Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 19:19:15 -0500 Subject: [PATCH 31/82] made string generation more robust --- examples/azure-vm-simple-linux/deploy.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index f9bdb63c1..c6f9bc55e 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -3,13 +3,15 @@ set -o errexit -o nounset # generate a unique string for CI deployment -KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 16) +KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 8) +KEY+=$(cat /dev/urandom | tr -cd '0-9' | head -c 8) +PASSWORD=KEY+"#" terraform get terraform plan \ -var 'dns_name='$KEY \ - -var 'admin_password='$KEY \ + -var 'admin_password='$PASSWORD \ -var 'admin_username='$KEY \ -var 'resource_group='$KEY \ -out=out.tfplan From e0208f48ba9260552cdefcd21c507e90ecfbd38e Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 19:29:36 -0500 Subject: [PATCH 32/82] added after_deploy step to travis.yml; updated string generation yet again --- .travis.yml | 4 ++++ examples/azure-vm-simple-linux/deploy.sh | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 06fa72134..874e22b95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,7 @@ deploy: on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux + +after_deploy: + - provider: script + script: terraform destroy diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index c6f9bc55e..2c54a94ca 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -4,7 +4,8 @@ set -o errexit -o nounset # generate a unique string for CI deployment KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 8) -KEY+=$(cat /dev/urandom | tr -cd '0-9' | head -c 8) +KEY+=$(cat /dev/urandom | tr -cd 'A-Z' | head -c 4) +KEY+=$(cat /dev/urandom | tr -cd '0-9' | head -c 4) PASSWORD=KEY+"#" terraform get @@ -21,8 +22,6 @@ terraform apply out.tfplan # TODO: determine external validation, possibly Azure CLI -terraform destroy - # echo "Setting git user name" # git config user.name $GH_USER_NAME # From af3de7b7dfa88d003eb811cb67c199e133111868 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 19:36:16 -0500 Subject: [PATCH 33/82] azure is awfully particular for certain strings --- .travis.yml | 1 + examples/azure-vm-simple-linux/deploy.sh | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 874e22b95..519154eb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ deploy: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux +# TODO: possibly use Azure CLI to delete the resource group after_deploy: - provider: script script: terraform destroy diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 2c54a94ca..22a5909b6 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -3,10 +3,10 @@ set -o errexit -o nounset # generate a unique string for CI deployment -KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 8) -KEY+=$(cat /dev/urandom | tr -cd 'A-Z' | head -c 4) -KEY+=$(cat /dev/urandom | tr -cd '0-9' | head -c 4) -PASSWORD=KEY+"#" +KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 12) +PASSWORD=KEY +PASSWORD+=$(cat /dev/urandom | tr -cd 'A-Z' | head -c 2) +PASSWORD+=$(cat /dev/urandom | tr -cd '0-9' | head -c 2) terraform get From 1653d5da737a2bd8ad6ddedf36626f18a1d497c1 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 19:52:02 -0500 Subject: [PATCH 34/82] incorrect variable reference --- examples/azure-vm-simple-linux/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 22a5909b6..d358639dc 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -4,7 +4,7 @@ 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 +PASSWORD=$KEY PASSWORD+=$(cat /dev/urandom | tr -cd 'A-Z' | head -c 2) PASSWORD+=$(cat /dev/urandom | tr -cd '0-9' | head -c 2) From bf5d9773e22108d1a69970802e83fe35bd45e033 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 20:23:07 -0500 Subject: [PATCH 35/82] fixed after_deploy syntax for .travis.yml --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 519154eb4..8b0d51f79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,4 @@ deploy: branch: topic-101-vm-simple-linux # TODO: possibly use Azure CLI to delete the resource group -after_deploy: - - provider: script - script: terraform destroy +after_deploy: terraform destroy From 36e4b74c13c433a68918cf9dabbd45df5428b419 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 20:32:22 -0500 Subject: [PATCH 36/82] added -force to after_deploy --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8b0d51f79..f5d37c4b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,4 @@ deploy: branch: topic-101-vm-simple-linux # TODO: possibly use Azure CLI to delete the resource group -after_deploy: terraform destroy +after_deploy: terraform destroy -force From 87b049b72d86bc824dc672e683ac868dd50d20da Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 19 Apr 2017 23:26:28 -0500 Subject: [PATCH 37/82] adding cd to after_deploy to ensure we're in the correct directory --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f5d37c4b2..dd9b0aefc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,4 @@ deploy: branch: topic-101-vm-simple-linux # TODO: possibly use Azure CLI to delete the resource group -after_deploy: terraform destroy -force +after_deploy: cd $TEST_DIR && terraform destroy -force From f117f1de262f75d4565d3eacb0d07f006e17043c Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 00:43:32 -0500 Subject: [PATCH 38/82] trying terraform 0.9.2 for destroy bug; fixed interpolation issue with sshCommand --- .travis.yml | 12 +++++++++++- examples/azure-vm-simple-linux/outputs.tf | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd9b0aefc..d8286cac7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,8 @@ +# sudo: required +# +# services: +# - docker + language: generic # establish environment variables @@ -8,13 +13,18 @@ branches: only: - /^(?i:topic)-.*$/ +# before_install: +# - docker pull azuresdk/azure-cli-python + # install terraform before_deploy: - - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip + - curl -fSL "https://releases.hashicorp.com/terraform/0.9.2/terraform_0.9.2_linux_amd64.zip" -o terraform.zip - sudo unzip terraform.zip -d /opt/terraform - sudo ln -s /opt/terraform/terraform /usr/bin/terraform - rm -f terraform.zip +# + # terraform deploy script deploy: - provider: script diff --git a/examples/azure-vm-simple-linux/outputs.tf b/examples/azure-vm-simple-linux/outputs.tf index e0e255a9e..9e3c2f071 100644 --- a/examples/azure-vm-simple-linux/outputs.tf +++ b/examples/azure-vm-simple-linux/outputs.tf @@ -7,5 +7,5 @@ output "vm_fqdn" { } output "sshCommand" { - value = "${concat("ssh ", var.admin_username, "@", azurerm_public_ip.pip.fqdn)}" + value = "ssh ${var.admin_username}@${azurerm_public_ip.pip.fqdn}" } From 602559f3f7fc92046d0a82a146157eb1f795d67d Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 12:34:32 -0500 Subject: [PATCH 39/82] updated travis file to use docker for pre_deploy/deploy/after_deploy --- .travis.yml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index d8286cac7..68acbe2f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ -# sudo: required -# -# services: -# - docker +sudo: required + +services: + - docker language: generic @@ -13,15 +13,18 @@ branches: only: - /^(?i:topic)-.*$/ -# before_install: -# - docker pull azuresdk/azure-cli-python +before_install: + - docker pull hashicorp/terraform + - docker pull azuresdk/azure-cli-python # install terraform before_deploy: - - curl -fSL "https://releases.hashicorp.com/terraform/0.9.2/terraform_0.9.2_linux_amd64.zip" -o terraform.zip - - sudo unzip terraform.zip -d /opt/terraform - - sudo ln -s /opt/terraform/terraform /usr/bin/terraform - - rm -f terraform.zip + - 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) + # - curl -fSL "https://releases.hashicorp.com/terraform/0.9.2/terraform_0.9.2_linux_amd64.zip" -o terraform.zip + # - sudo unzip terraform.zip -d /opt/terraform + # - sudo ln -s /opt/terraform/terraform /usr/bin/terraform + # - rm -f terraform.zip # @@ -29,10 +32,10 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && chmod +x ./deploy.sh && ./deploy.sh + script: cd $TEST_DIR && docker run --rm -it hashicorp/terraform:light "terraform get; terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan; terraform apply out.tfplan" on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux # TODO: possibly use Azure CLI to delete the resource group -after_deploy: cd $TEST_DIR && terraform destroy -force +after_deploy: cd $TEST_DIR && docker run --rm -it azuresdk/azure-cli-python "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID && az group delete $KEY" From 3f9d6a2111e8be7b7095a0223ec4a50141049b42 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 12:38:00 -0500 Subject: [PATCH 40/82] no need to pull images --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 68acbe2f2..487720eaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,6 @@ branches: only: - /^(?i:topic)-.*$/ -before_install: - - docker pull hashicorp/terraform - - docker pull azuresdk/azure-cli-python - # install terraform before_deploy: - KEY=$(cat /dev/urandom | tr -cd 'a-z' | head -c 12) From 017b469ee652b1e533f17413c606dadcc10d03be Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 12:46:43 -0500 Subject: [PATCH 41/82] mount pwd to container for terraform --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 487720eaa..9030d77b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && docker run --rm -it hashicorp/terraform:light "terraform get; terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan; terraform apply out.tfplan" + script: cd $TEST_DIR && docker run --rm -it -v .:/data --workdir=/data hashicorp/terraform:light "terraform get; terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan; terraform apply out.tfplan" on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux From 8ed7e8125557e469c5ff901c84a2b0f494640897 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 12:49:23 -0500 Subject: [PATCH 42/82] invalid path for travis --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9030d77b1..920baa522 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,5 @@ sudo: required -services: - - docker - language: generic # establish environment variables @@ -28,7 +25,7 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && docker run --rm -it -v .:/data --workdir=/data hashicorp/terraform:light "terraform get; terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan; terraform apply out.tfplan" + script: cd $TEST_DIR && docker run --rm -it -v ./:/data --workdir=/data hashicorp/terraform:light "terraform get; terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan; terraform apply out.tfplan" on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux From 60b20817b4b4421308ab412f1e8433657e03e79e Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 12:52:12 -0500 Subject: [PATCH 43/82] service docker required, despite docker already running --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 920baa522..a001a6d8a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ sudo: required +services: + - docker + language: generic # establish environment variables From 3a1adfc3e12be549272f2241dcf34fc5223d6cdf Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 13:44:23 -0500 Subject: [PATCH 44/82] simplified travis.yml and deploy.sh --- .travis.yml | 4 ++-- examples/azure-vm-simple-linux/deploy.sh | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index a001a6d8a..d241c3704 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,10 +28,10 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && docker run --rm -it -v ./:/data --workdir=/data hashicorp/terraform:light "terraform get; terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan; terraform apply out.tfplan" + script: cd $TEST_DIR && ./deploy.sh $KEY $PASSWORD on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux # TODO: possibly use Azure CLI to delete the resource group -after_deploy: cd $TEST_DIR && docker run --rm -it azuresdk/azure-cli-python "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID && az group delete $KEY" +# after_deploy: docker run --rm -it azuresdk/azure-cli-python "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID && az group delete $KEY" diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index d358639dc..94d6d8038 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -3,21 +3,21 @@ 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 -PASSWORD+=$(cat /dev/urandom | tr -cd 'A-Z' | head -c 2) -PASSWORD+=$(cat /dev/urandom | tr -cd '0-9' | head -c 2) +# 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) -terraform get +KEY=$1 +PASSWORD=$2 -terraform plan \ - -var 'dns_name='$KEY \ - -var 'admin_password='$PASSWORD \ - -var 'admin_username='$KEY \ - -var 'resource_group='$KEY \ - -out=out.tfplan +docker run --rm -it -v $(pwd):/data -w /data hashicorp/terraform:light get +docker run --rm -it -v $(pwd):/data -w /data hashicorp/terraform:light plan -var dns_name=$KEY -var admin_password=$PASSWORD -var admin_username=$KEY -var resource_group=$KEY -out=out.tfplan +docker run --rm -it -v $(pwd):/data -w /data hashicorp/terraform:light apply out.tfplan -terraform apply out.tfplan +# terraform get +# +# terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan +# +# terraform apply out.tfplan # TODO: determine external validation, possibly Azure CLI From 372605c5bbb4a00fe5284326f1cdc5fc8e753664 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 13:52:15 -0500 Subject: [PATCH 45/82] added env variables to terraform:light --- examples/azure-vm-simple-linux/deploy.sh | 25 +++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 94d6d8038..674462dc0 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -9,9 +9,28 @@ set -o errexit -o nounset KEY=$1 PASSWORD=$2 -docker run --rm -it -v $(pwd):/data -w /data hashicorp/terraform:light get -docker run --rm -it -v $(pwd):/data -w /data hashicorp/terraform:light plan -var dns_name=$KEY -var admin_password=$PASSWORD -var admin_username=$KEY -var resource_group=$KEY -out=out.tfplan -docker run --rm -it -v $(pwd):/data -w /data hashicorp/terraform:light apply out.tfplan +docker run --rm -it -v \ + $(pwd):/data -w /data \ + hashicorp/terraform:light \ + get + +docker run --rm -it -v \ + -e ARM_CLIENT_ID=$ARM_CLIENT_ID + -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET + -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID + -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID + $(pwd):/data -w /data \ + hashicorp/terraform:light \ + plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan + +docker run --rm -it -v \ + -e ARM_CLIENT_ID=$ARM_CLIENT_ID + -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET + -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID + -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID + $(pwd):/data -w /data \ + hashicorp/terraform:light \ + apply out.tfplan # terraform get # From f04718040cc8b3b459ebe31544fc705dd356e82b Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 13:57:49 -0500 Subject: [PATCH 46/82] env vars need quotes --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index d241c3704..bed7b6bf4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,12 +17,6 @@ branches: before_deploy: - 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) - # - curl -fSL "https://releases.hashicorp.com/terraform/0.9.2/terraform_0.9.2_linux_amd64.zip" -o terraform.zip - # - sudo unzip terraform.zip -d /opt/terraform - # - sudo ln -s /opt/terraform/terraform /usr/bin/terraform - # - rm -f terraform.zip - -# # terraform deploy script deploy: From d89e652729d9a8f82598bb2cc3b1e6b8d12630fa Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 14:02:12 -0500 Subject: [PATCH 47/82] forgot \ at eol --- examples/azure-vm-simple-linux/deploy.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 674462dc0..f10ba5d17 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -14,20 +14,20 @@ docker run --rm -it -v \ hashicorp/terraform:light \ get -docker run --rm -it -v \ - -e ARM_CLIENT_ID=$ARM_CLIENT_ID - -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET - -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID - -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID +docker run + -e ARM_CLIENT_ID="$ARM_CLIENT_ID" \ + -e ARM_CLIENT_SECRET="$ARM_CLIENT_SECRET" \ + -e ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID" \ + -e ARM_TENANT_ID="$ARM_SUBSCRIPTION_ID" \ $(pwd):/data -w /data \ hashicorp/terraform:light \ plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan docker run --rm -it -v \ - -e ARM_CLIENT_ID=$ARM_CLIENT_ID - -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET - -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID - -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID + -e ARM_CLIENT_ID="$ARM_CLIENT_ID" \ + -e ARM_CLIENT_SECRET="$ARM_CLIENT_SECRET" \ + -e ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID" \ + -e ARM_TENANT_ID="$ARM_SUBSCRIPTION_ID" \ $(pwd):/data -w /data \ hashicorp/terraform:light \ apply out.tfplan From 4edbc8bd926fcf11e6c34eca4f3baa057445f87e Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 14:06:59 -0500 Subject: [PATCH 48/82] fixed plan args --- examples/azure-vm-simple-linux/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index f10ba5d17..c2d853896 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -14,7 +14,7 @@ docker run --rm -it -v \ hashicorp/terraform:light \ get -docker run +docker run --rm -it -v \ -e ARM_CLIENT_ID="$ARM_CLIENT_ID" \ -e ARM_CLIENT_SECRET="$ARM_CLIENT_SECRET" \ -e ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID" \ From 10f48d565edccb3278314ce6068bf2052fced853 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 14:10:54 -0500 Subject: [PATCH 49/82] cleaned up argument passing;removed quotes from container args --- .travis.yml | 6 +++--- examples/azure-vm-simple-linux/deploy.sh | 19 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index bed7b6bf4..d5c8e269e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,14 +15,14 @@ branches: # install terraform before_deploy: - - 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) + - 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 skip_cleanup: true - script: cd $TEST_DIR && ./deploy.sh $KEY $PASSWORD + script: cd $TEST_DIR && ./deploy.sh on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index c2d853896..65a4b0a32 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -6,28 +6,25 @@ set -o errexit -o nounset # 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) -KEY=$1 -PASSWORD=$2 - docker run --rm -it -v \ $(pwd):/data -w /data \ hashicorp/terraform:light \ get docker run --rm -it -v \ - -e ARM_CLIENT_ID="$ARM_CLIENT_ID" \ - -e ARM_CLIENT_SECRET="$ARM_CLIENT_SECRET" \ - -e ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID" \ - -e ARM_TENANT_ID="$ARM_SUBSCRIPTION_ID" \ + -e ARM_CLIENT_ID=$ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID \ $(pwd):/data -w /data \ hashicorp/terraform:light \ plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan docker run --rm -it -v \ - -e ARM_CLIENT_ID="$ARM_CLIENT_ID" \ - -e ARM_CLIENT_SECRET="$ARM_CLIENT_SECRET" \ - -e ARM_SUBSCRIPTION_ID="$ARM_SUBSCRIPTION_ID" \ - -e ARM_TENANT_ID="$ARM_SUBSCRIPTION_ID" \ + -e ARM_CLIENT_ID=$ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID \ $(pwd):/data -w /data \ hashicorp/terraform:light \ apply out.tfplan From 86f68f4aa8c087ceb4b2b1b9ed6df32f5c9e7aea Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 14:33:49 -0500 Subject: [PATCH 50/82] better passing of env vars --- examples/azure-vm-simple-linux/deploy.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/azure-vm-simple-linux/deploy.sh b/examples/azure-vm-simple-linux/deploy.sh index 65a4b0a32..5a282c15e 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -12,19 +12,19 @@ docker run --rm -it -v \ get docker run --rm -it -v \ - -e ARM_CLIENT_ID=$ARM_CLIENT_ID \ - -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET \ - -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID \ - -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID \ + -e $ARM_CLIENT_ID \ + -e $ARM_CLIENT_SECRET \ + -e $ARM_SUBSCRIPTION_ID \ + -e $ARM_TENANT_ID \ $(pwd):/data -w /data \ hashicorp/terraform:light \ plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan docker run --rm -it -v \ - -e ARM_CLIENT_ID=$ARM_CLIENT_ID \ - -e ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET \ - -e ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID \ - -e ARM_TENANT_ID=$ARM_SUBSCRIPTION_ID \ + -e $ARM_CLIENT_ID \ + -e $ARM_CLIENT_SECRET \ + -e $ARM_SUBSCRIPTION_ID \ + -e $ARM_TENANT_ID \ $(pwd):/data -w /data \ hashicorp/terraform:light \ apply out.tfplan From 20d8a07ad0b10276214bc1a75f357292d4ccc8ca Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 15:45:05 -0500 Subject: [PATCH 51/82] azure cli after_deploy step working properly; cleanup --- .travis.yml | 2 +- examples/azure-vm-simple-linux/deploy.sh | 29 ++++++++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index d5c8e269e..933db6b24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ deploy: 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 "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID && az group delete $KEY" +after_deploy: docker run --rm -it azuresdk/azure-cli-python 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 5a282c15e..25b99956f 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -6,26 +6,26 @@ set -o errexit -o nounset # 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 -v \ - $(pwd):/data -w /data \ +docker run --rm -it \ + -v $(pwd):/data -w /data \ hashicorp/terraform:light \ get -docker run --rm -it -v \ - -e $ARM_CLIENT_ID \ - -e $ARM_CLIENT_SECRET \ - -e $ARM_SUBSCRIPTION_ID \ - -e $ARM_TENANT_ID \ - $(pwd):/data -w /data \ +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data -w /data \ hashicorp/terraform:light \ plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan -docker run --rm -it -v \ - -e $ARM_CLIENT_ID \ - -e $ARM_CLIENT_SECRET \ - -e $ARM_SUBSCRIPTION_ID \ - -e $ARM_TENANT_ID \ - $(pwd):/data -w /data \ +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data -w /data \ hashicorp/terraform:light \ apply out.tfplan @@ -35,7 +35,6 @@ docker run --rm -it -v \ # # terraform apply out.tfplan - # TODO: determine external validation, possibly Azure CLI # echo "Setting git user name" From 6c3c85d05f1281decc13bba9b65ac80916c30b2b Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 20 Apr 2017 19:46:42 -0500 Subject: [PATCH 52/82] simplified deploy.sh, fixed after_deploy delete via cli --- .travis.yml | 2 +- examples/azure-vm-simple-linux/deploy.sh | 25 +++--------------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 933db6b24..a6bedbcc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ deploy: 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 az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID; az group delete -y -n $KEY +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.sh b/examples/azure-vm-simple-linux/deploy.sh index 25b99956f..899385f27 100755 --- a/examples/azure-vm-simple-linux/deploy.sh +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -6,34 +6,15 @@ set -o errexit -o nounset # 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 \ - -v $(pwd):/data -w /data \ - hashicorp/terraform:light \ - get - docker run --rm -it \ -e ARM_CLIENT_ID \ -e ARM_CLIENT_SECRET \ -e ARM_SUBSCRIPTION_ID \ -e ARM_TENANT_ID \ - -v $(pwd):/data -w /data \ + -v $(pwd):/data \ + --entrypoint "/bin/sh" \ hashicorp/terraform:light \ - plan -var dns_name=$KEY -var resource_group=$KEY -var admin_username=$KEY -var admin_password=$PASSWORD -out=out.tfplan - -docker run --rm -it \ - -e ARM_CLIENT_ID \ - -e ARM_CLIENT_SECRET \ - -e ARM_SUBSCRIPTION_ID \ - -e ARM_TENANT_ID \ - -v $(pwd):/data -w /data \ - hashicorp/terraform:light \ - apply out.tfplan - -# terraform get -# -# terraform plan -var 'dns_name='$KEY -var 'admin_password='$PASSWORD -var 'admin_username='$KEY -var 'resource_group='$KEY -out=out.tfplan -# -# terraform apply out.tfplan + -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 From 34d0c450ff3c0efdb2b75b0e93664110bdeed65e Mon Sep 17 00:00:00 2001 From: anniehedgpeth Date: Sat, 22 Apr 2017 17:27:49 -0500 Subject: [PATCH 53/82] updated to best practices/conventions --- examples/azure-vm-simple-linux/.gitignore | 4 +-- examples/azure-vm-simple-linux/README.md | 34 +++++++++++++++++-- .../{main.tf => azuredeploy.tf} | 0 .../azure-vm-simple-linux/provider.tf.example | 6 ++++ .../terraform.tfvars.example | 7 ++++ examples/azure-vm-simple-linux/variables.tf | 19 +++++------ 6 files changed, 54 insertions(+), 16 deletions(-) rename examples/azure-vm-simple-linux/{main.tf => azuredeploy.tf} (100%) create mode 100644 examples/azure-vm-simple-linux/provider.tf.example create mode 100644 examples/azure-vm-simple-linux/terraform.tfvars.example diff --git a/examples/azure-vm-simple-linux/.gitignore b/examples/azure-vm-simple-linux/.gitignore index 352c8a2b9..7773fa9ec 100644 --- a/examples/azure-vm-simple-linux/.gitignore +++ b/examples/azure-vm-simple-linux/.gitignore @@ -1,3 +1,3 @@ terraform.tfstate* -terraform.tfvars* -creds.tf* +terraform.tfvars +provider.tf diff --git a/examples/azure-vm-simple-linux/README.md b/examples/azure-vm-simple-linux/README.md index 92446ee9e..ee0a39667 100644 --- a/examples/azure-vm-simple-linux/README.md +++ b/examples/azure-vm-simple-linux/README.md @@ -1,8 +1,36 @@ -# Deploy a simple Linux VM -**ubuntu** +# Very simple deployment of a Linux VM + + + + + + + This template allows you to deploy a simple Linux VM using a few different options for the Ubuntu version, using the latest patched version. This will deploy a A1 size VM in the resource group location and return the FQDN of the VM. This template takes a minimum amount of parameters and deploys a Linux VM, using the latest patched version. -Azure requires that an application is added to Azure Active Directory to generate the client_id, client_secret, and tenant_id needed by Terraform (subscription_id can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this. \ No newline at end of file +## azuredeploy.tf +The `azuredeploy.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. + +## outputs.tf +This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command. + +## provider.tf +Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. + +## terraform.tfvars +If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. + +## variables.tf +The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. + +## .gitignore +If you are committing this template to source control, please insure that the following files are added to your `.gitignore` file. + +``` +terraform.tfstate* +terraform.tfvars +provider.tf* +``` \ No newline at end of file diff --git a/examples/azure-vm-simple-linux/main.tf b/examples/azure-vm-simple-linux/azuredeploy.tf similarity index 100% rename from examples/azure-vm-simple-linux/main.tf rename to examples/azure-vm-simple-linux/azuredeploy.tf diff --git a/examples/azure-vm-simple-linux/provider.tf.example b/examples/azure-vm-simple-linux/provider.tf.example new file mode 100644 index 000000000..327ceb55e --- /dev/null +++ b/examples/azure-vm-simple-linux/provider.tf.example @@ -0,0 +1,6 @@ +provider "azurerm" { + subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" + client_id = "REPLACE-WITH-YOUR-CLIENT-ID" + client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" + tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" +} \ No newline at end of file diff --git a/examples/azure-vm-simple-linux/terraform.tfvars.example b/examples/azure-vm-simple-linux/terraform.tfvars.example new file mode 100644 index 000000000..715f259dc --- /dev/null +++ b/examples/azure-vm-simple-linux/terraform.tfvars.example @@ -0,0 +1,7 @@ +resource_group = "myresourcegroup" +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 915751c8c..72680c74f 100644 --- a/examples/azure-vm-simple-linux/variables.tf +++ b/examples/azure-vm-simple-linux/variables.tf @@ -4,12 +4,18 @@ 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" { + description = "VM name referenced also in storage-related names." +} + +variable "dns_name" { + description = " Label for the Domain Name. Will be used to make up the FQDN. If a domain name label is specified, an A DNS record is created for the public IP in the Microsoft Azure DNS system." } 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" { @@ -57,15 +63,6 @@ variable "image_version" { default = "latest" } -variable "hostname" { - description = "VM name referenced also in storage-related names." - default = "myvm" -} - -variable "dns_name" { - description = " Label for the Domain Name. Will be used to make up the FQDN. If a domain name label is specified, an A DNS record is created for the public IP in the Microsoft Azure DNS system." -} - variable "admin_username" { description = "administrator user name" } From 277683833eaaa5dbb6d8e2840920ca29f1f479f5 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 09:23:15 -0500 Subject: [PATCH 54/82] cleanup --- .travis.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index c34013696..f4e8130d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,29 +3,12 @@ language: generic # establish environment variables env: - TEST_DIR=examples/101-vm-simple-linux -# global: -# - GH_USER_NAME="travis-ci" -# - GH_USER_EMAIL="mikedball@gmail.com" -# - GH_REPO="10thmagnitude/terraform" -# # encrypted GH_TOKEN and AWS credentials -# - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" branches: only: - master - /^(?i:topic)-.*$/ - -##todo: switch to before_script and script - -# install terraform -before_deploy: - - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip - - sudo unzip terraform.zip -d /opt/terraform - - sudo ln -s /opt/terraform/terraform /usr/bin/terraform - - rm -f terraform.zip - -# terraform apply deploy: - provider: script skip_cleanup: true @@ -33,4 +16,4 @@ deploy: on: repo: 10thmagnitude/terraform branch: 101-vm-simple-linux - condition: false # re-enable when examples exist in master + condition: false # re-enable when examples exist in master From 9a7e42459bf80892d3b35b42e7c898d4dcc26244 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 11:45:24 -0500 Subject: [PATCH 55/82] cleanup; sane defaults --- .travis.yml | 9 ++++-- examples/azure-vm-simple-linux/deploy.mac.sh | 14 ++++++++ examples/azure-vm-simple-linux/deploy.sh | 32 +++---------------- .../{azuredeploy.tf => main.tf} | 6 ++-- .../terraform.tfvars.example | 1 - examples/azure-vm-simple-linux/variables.tf | 3 ++ 6 files changed, 32 insertions(+), 33 deletions(-) create mode 100755 examples/azure-vm-simple-linux/deploy.mac.sh rename examples/azure-vm-simple-linux/{azuredeploy.tf => main.tf} (95%) 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" { From 3e498199e9efb30794446f52015c8134c8439198 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 12:02:06 -0500 Subject: [PATCH 56/82] fixed broken syntax for travis --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9d863c4e6..be16bb0ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,4 @@ deploy: # 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" + - 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" From 02952cac6f902f2dcbcfb5f9ada1a3f0ba35c895 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 12:14:07 -0500 Subject: [PATCH 57/82] cleanup/reorg --- .travis.yml | 9 ++------- examples/azure-vm-simple-linux/before_deploy.sh | 6 ++++++ examples/azure-vm-simple-linux/cleanup.sh | 9 +++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 examples/azure-vm-simple-linux/before_deploy.sh create mode 100755 examples/azure-vm-simple-linux/cleanup.sh diff --git a/.travis.yml b/.travis.yml index be16bb0ba..d225e6eea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,19 +15,14 @@ branches: # install terraform 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) - + - cd $TEST_DIR && ./before_deploy.sh # terraform deploy script deploy: - provider: script skip_cleanup: true script: cd $TEST_DIR && ./deploy.sh - on: - repo: 10thmagnitude/terraform - branch: topic-101-vm-simple-linux # 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" + - cd $TEST_DIR && ./after_deploy.sh diff --git a/examples/azure-vm-simple-linux/before_deploy.sh b/examples/azure-vm-simple-linux/before_deploy.sh new file mode 100644 index 000000000..d20bda914 --- /dev/null +++ b/examples/azure-vm-simple-linux/before_deploy.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -o errexit -o nounset + +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) diff --git a/examples/azure-vm-simple-linux/cleanup.sh b/examples/azure-vm-simple-linux/cleanup.sh new file mode 100755 index 000000000..245aba380 --- /dev/null +++ b/examples/azure-vm-simple-linux/cleanup.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -o errexit -o nounset + +# cleanup deployed azure resources +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" From ccfdc3c6c33c34603ddf0cf4b76098941addc0d2 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 12:17:22 -0500 Subject: [PATCH 58/82] branch restrictions --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d225e6eea..6d1a4da80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,9 @@ deploy: - provider: script skip_cleanup: true script: cd $TEST_DIR && ./deploy.sh + on: + repo: 10thmagnitude/terraform + branch: topic-101-vm-simple-linux # destroy resources with Azure CLI after_deploy: From 9232165e203097777852cda9cae6555b90ed22dc Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 12:22:54 -0500 Subject: [PATCH 59/82] rename; and execute perms --- examples/azure-vm-simple-linux/{cleanup.sh => after_deploy.sh} | 0 examples/azure-vm-simple-linux/before_deploy.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename examples/azure-vm-simple-linux/{cleanup.sh => after_deploy.sh} (100%) mode change 100644 => 100755 examples/azure-vm-simple-linux/before_deploy.sh diff --git a/examples/azure-vm-simple-linux/cleanup.sh b/examples/azure-vm-simple-linux/after_deploy.sh similarity index 100% rename from examples/azure-vm-simple-linux/cleanup.sh rename to examples/azure-vm-simple-linux/after_deploy.sh diff --git a/examples/azure-vm-simple-linux/before_deploy.sh b/examples/azure-vm-simple-linux/before_deploy.sh old mode 100644 new mode 100755 From 986b0682ea904b33a03c2fdb9ea964a90553b119 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 12:50:47 -0500 Subject: [PATCH 60/82] travis syntax changes --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6d1a4da80..ccd74d4fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,9 @@ branches: # install terraform before_deploy: - - cd $TEST_DIR && ./before_deploy.sh + - provider: script + skip_cleanup: true + script: cd $TEST_DIR && ./before_deploy.sh # terraform deploy script deploy: @@ -28,4 +30,6 @@ deploy: # destroy resources with Azure CLI after_deploy: - - cd $TEST_DIR && ./after_deploy.sh + - provider: script + skip_cleanup: true + script: cd $TEST_DIR && ./after_deploy.sh From d0e8c2816c8f60ab10ecabd60bac640a0f0ebfe3 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 13:09:53 -0500 Subject: [PATCH 61/82] fixed travis cfg --- .travis.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index ccd74d4fd..351fe664c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,10 +14,7 @@ branches: - /^(?i:topic)-.*$/ # install terraform -before_deploy: - - provider: script - skip_cleanup: true - script: cd $TEST_DIR && ./before_deploy.sh +before_deploy: cd $TEST_DIR && ./before_deploy.sh # terraform deploy script deploy: @@ -29,7 +26,4 @@ deploy: branch: topic-101-vm-simple-linux # destroy resources with Azure CLI -after_deploy: - - provider: script - skip_cleanup: true - script: cd $TEST_DIR && ./after_deploy.sh +after_deploy: cd $TEST_DIR && ./after_deploy.sh From d4ea91a029ac3d69bbb5dc180731d09f588ba8a6 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 13:14:02 -0500 Subject: [PATCH 62/82] removal of extra cd --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 351fe664c..75da4d033 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,10 +20,10 @@ before_deploy: cd $TEST_DIR && ./before_deploy.sh deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && ./deploy.sh + script: ./deploy.sh on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux # destroy resources with Azure CLI -after_deploy: cd $TEST_DIR && ./after_deploy.sh +after_deploy: ./after_deploy.sh From fcffe2d82bd4d36696cc7c570289913c6d5ccc3d Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 13:27:00 -0500 Subject: [PATCH 63/82] easier to export in before_deploy block --- .travis.yml | 4 +++- examples/azure-vm-simple-linux/before_deploy.sh | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100755 examples/azure-vm-simple-linux/before_deploy.sh diff --git a/.travis.yml b/.travis.yml index 75da4d033..6cbee27e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,9 @@ branches: - /^(?i:topic)-.*$/ # install terraform -before_deploy: cd $TEST_DIR && ./before_deploy.sh +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: diff --git a/examples/azure-vm-simple-linux/before_deploy.sh b/examples/azure-vm-simple-linux/before_deploy.sh deleted file mode 100755 index d20bda914..000000000 --- a/examples/azure-vm-simple-linux/before_deploy.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -o errexit -o nounset - -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) From 679aa2e01453ddc1308f820b516e357c52ed8057 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 13:30:03 -0500 Subject: [PATCH 64/82] run script in wrong dir --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6cbee27e1..077ea7749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: ./deploy.sh + script: cd $TEST_DIR && ./deploy.sh on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux From 441b86ac869519b97922bfae3a81d8e169b74b1c Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 13:40:07 -0500 Subject: [PATCH 65/82] explicit build dirs --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 077ea7749..e4b2c4103 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,10 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && ./deploy.sh + script: cd cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.sh on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux # destroy resources with Azure CLI -after_deploy: ./after_deploy.sh +after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.sh From 938402edbafbaa865efaf8880795e9c81723dfb9 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 13:43:38 -0500 Subject: [PATCH 66/82] bad syntax --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e4b2c4103..5401a6d72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.sh + script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.sh on: repo: 10thmagnitude/terraform branch: topic-101-vm-simple-linux From 5850bc8cf9732bfaab225febff5a9c1d71cc0399 Mon Sep 17 00:00:00 2001 From: anniehedgpeth Date: Mon, 24 Apr 2017 14:38:14 -0500 Subject: [PATCH 67/82] azuredeploy.tf to main.tf in README --- examples/azure-vm-simple-linux/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/azure-vm-simple-linux/README.md b/examples/azure-vm-simple-linux/README.md index ee0a39667..a0ab5f634 100644 --- a/examples/azure-vm-simple-linux/README.md +++ b/examples/azure-vm-simple-linux/README.md @@ -11,8 +11,8 @@ This template allows you to deploy a simple Linux VM using a few different optio This template takes a minimum amount of parameters and deploys a Linux VM, using the latest patched version. -## azuredeploy.tf -The `azuredeploy.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. +## main.tf +The `main.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. ## outputs.tf This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command. From afb164b79a65e560be1a03a4644bd1f9ca36dd5f Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Mon, 24 Apr 2017 14:57:28 -0500 Subject: [PATCH 68/82] Topic 101 vm simple linux (#1) * added .travis.yml and deploy.sh * added deploy script, updated travis.yml to build topic- branches * generate random string for hostname * plan now produces output plan, apply now consumes outputted plan * cleanup; sane defaults * explicit build dirs --- .travis.yml | 32 +++-- examples/azure-vm-simple-linux/.gitignore | 3 + examples/azure-vm-simple-linux/README.md | 36 ++++++ .../azure-vm-simple-linux/after_deploy.sh | 9 ++ examples/azure-vm-simple-linux/deploy.mac.sh | 14 +++ examples/azure-vm-simple-linux/deploy.sh | 17 +++ examples/azure-vm-simple-linux/main.tf | 112 ++++++++++++++++++ examples/azure-vm-simple-linux/outputs.tf | 11 ++ .../azure-vm-simple-linux/provider.tf.example | 6 + .../terraform.tfvars.example | 6 + examples/azure-vm-simple-linux/variables.tf | 75 ++++++++++++ 11 files changed, 303 insertions(+), 18 deletions(-) create mode 100644 examples/azure-vm-simple-linux/.gitignore create mode 100644 examples/azure-vm-simple-linux/README.md create mode 100755 examples/azure-vm-simple-linux/after_deploy.sh create mode 100755 examples/azure-vm-simple-linux/deploy.mac.sh create mode 100755 examples/azure-vm-simple-linux/deploy.sh create mode 100644 examples/azure-vm-simple-linux/main.tf create mode 100644 examples/azure-vm-simple-linux/outputs.tf create mode 100644 examples/azure-vm-simple-linux/provider.tf.example create mode 100644 examples/azure-vm-simple-linux/terraform.tfvars.example create mode 100644 examples/azure-vm-simple-linux/variables.tf diff --git a/.travis.yml b/.travis.yml index c34013696..9bf07f695 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,36 +1,32 @@ +sudo: required + +services: + - docker + language: generic # establish environment variables env: - - TEST_DIR=examples/101-vm-simple-linux -# global: -# - GH_USER_NAME="travis-ci" -# - GH_USER_EMAIL="mikedball@gmail.com" -# - GH_REPO="10thmagnitude/terraform" -# # encrypted GH_TOKEN and AWS credentials -# - secure: "EBtNoRGUNjgom7lk6+O7Zh9A33X/251Cg7j5C+HqfkPMQcQwS6MEAXPT1vbnh1HoQixR1e6VTHdXxvWyE/14+98qtJiHnSbGiY67ZvQNDuFLb2+PKx7xhhl9heNj8Xk1K1SYJtfYQZIvZNl32V9db6eR3r7kKlWlpUVmnSnXrnm4ztI8se45OX/XPjAnARdBvkpbcTSprrAf7Qudc5R86ain18tJah6PICd12TIH4Cpdcr6CVL8kRK808VH+AS2oii7QcKXc084gBOJJLCiwa2DrcSEPOOk0AIn5ft+XVcaCsV6oOc6NliFKEPoJkaxbYWtunDlnqgB6epuaGrf99TfCg4E9R8sXBFqJwdMGDu3xM6Nddw87tMj/oCbUmjrNnl4qAxIMBD2TdjwFS1lNaXAML8W/jx3bNGSEg5MAYrqLL32eJta/vxRJwpCVnXUHxef9JcZMNZcvuKMdHC98JQIYbGRRFZ0cFtqMe63tgWafCi3WS+FIqSWnGdiKZ7dS110ANHaiQkDAZKTlh/9YJpzR9LyOoq7xXYtQIUovyDD2j498mAkcgByEbyZ39k6xMvLHHXsdUq25tdaMvqE3ZUASIDWqDk1QPfxkXX6n62Tj2X1HCA+3JI/DKyEfzt3QV4rntiP4Qv9jSuxNpd47rgsgVFg+HGJmko9QzAA/g+E=" + - TEST_DIR=examples/azure-vm-simple-linux branches: only: - master - /^(?i:topic)-.*$/ - -##todo: switch to before_script and script - # install terraform before_deploy: - - curl -fSL "https://releases.hashicorp.com/terraform/0.9.3/terraform_0.9.3_linux_amd64.zip" -o terraform.zip - - sudo unzip terraform.zip -d /opt/terraform - - sudo ln -s /opt/terraform/terraform /usr/bin/terraform - - rm -f terraform.zip + - 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 apply +# terraform deploy script deploy: - provider: script skip_cleanup: true - script: cd $TEST_DIR && "./deploy.sh" + script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.sh on: repo: 10thmagnitude/terraform - branch: 101-vm-simple-linux - condition: false # re-enable when examples exist in master + branch: topic-101-vm-simple-linux + +# destroy resources with Azure CLI +after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.sh \ No newline at end of file diff --git a/examples/azure-vm-simple-linux/.gitignore b/examples/azure-vm-simple-linux/.gitignore new file mode 100644 index 000000000..7773fa9ec --- /dev/null +++ b/examples/azure-vm-simple-linux/.gitignore @@ -0,0 +1,3 @@ +terraform.tfstate* +terraform.tfvars +provider.tf diff --git a/examples/azure-vm-simple-linux/README.md b/examples/azure-vm-simple-linux/README.md new file mode 100644 index 000000000..a0ab5f634 --- /dev/null +++ b/examples/azure-vm-simple-linux/README.md @@ -0,0 +1,36 @@ +# Very simple deployment of a Linux VM + + + + + + + + +This template allows you to deploy a simple Linux VM using a few different options for the Ubuntu version, using the latest patched version. This will deploy a A1 size VM in the resource group location and return the FQDN of the VM. + +This template takes a minimum amount of parameters and deploys a Linux VM, using the latest patched version. + +## main.tf +The `main.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. + +## outputs.tf +This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command. + +## provider.tf +Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. + +## terraform.tfvars +If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. + +## variables.tf +The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. + +## .gitignore +If you are committing this template to source control, please insure that the following files are added to your `.gitignore` file. + +``` +terraform.tfstate* +terraform.tfvars +provider.tf* +``` \ No newline at end of file diff --git a/examples/azure-vm-simple-linux/after_deploy.sh b/examples/azure-vm-simple-linux/after_deploy.sh new file mode 100755 index 000000000..245aba380 --- /dev/null +++ b/examples/azure-vm-simple-linux/after_deploy.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -o errexit -o nounset + +# cleanup deployed azure resources +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 new file mode 100755 index 000000000..5347f3a83 --- /dev/null +++ b/examples/azure-vm-simple-linux/deploy.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -o errexit -o nounset + +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data \ + --entrypoint "/bin/sh" \ + hashicorp/terraform:light \ + -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/main.tf b/examples/azure-vm-simple-linux/main.tf new file mode 100644 index 000000000..cf931d0f9 --- /dev/null +++ b/examples/azure-vm-simple-linux/main.tf @@ -0,0 +1,112 @@ +resource "azurerm_resource_group" "rg" { + name = "${var.resource_group}" + location = "${var.location}" +} + +resource "azurerm_virtual_network" "vnet" { + name = "${var.virtual_network_name}" + location = "${var.location}" + address_space = ["${var.address_space}"] + resource_group_name = "${azurerm_resource_group.rg.name}" +} + +resource "azurerm_subnet" "subnet" { + name = "${var.rg_prefix}subnet" + virtual_network_name = "${azurerm_virtual_network.vnet.name}" + resource_group_name = "${azurerm_resource_group.rg.name}" + address_prefix = "${var.subnet_prefix}" +} + +resource "azurerm_network_interface" "nic" { + name = "${var.rg_prefix}nic" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + + ip_configuration { + name = "${var.rg_prefix}ipconfig" + subnet_id = "${azurerm_subnet.subnet.id}" + private_ip_address_allocation = "Dynamic" + public_ip_address_id = "${azurerm_public_ip.pip.id}" + } +} + +resource "azurerm_public_ip" "pip" { + name = "${var.rg_prefix}-ip" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + public_ip_address_allocation = "dynamic" + domain_name_label = "${var.dns_name}" +} + +resource "azurerm_storage_account" "stor" { + name = "${var.dns_name}stor" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + account_type = "${var.storage_account_type}" +} + +resource "azurerm_storage_container" "storc" { + name = "${var.hostname}-vhds" + resource_group_name = "${azurerm_resource_group.rg.name}" + storage_account_name = "${azurerm_storage_account.stor.name}" + container_access_type = "private" +} + +resource "azurerm_managed_disk" "disk1" { + name = "${var.hostname}-osdisk1" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "30" +} + +resource "azurerm_managed_disk" "disk2" { + name = "${var.hostname}-disk2" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1023" +} + +resource "azurerm_virtual_machine" "vm" { + name = "${var.rg_prefix}vm" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + vm_size = "${var.vm_size}" + network_interface_ids = ["${azurerm_network_interface.nic.id}"] + + storage_image_reference { + publisher = "${var.image_publisher}" + offer = "${var.image_offer}" + sku = "${var.image_sku}" + version = "${var.image_version}" + } + + storage_os_disk { + name = "${var.hostname}-osdisk1" + vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-osdisk1.vhd" + caching = "ReadWrite" + create_option = "FromImage" + } + + storage_data_disk { + name = "${var.hostname}-disk2" + vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-disk2.vhd" + disk_size_gb = "1023" + create_option = "Empty" + lun = 0 + } + + os_profile { + computer_name = "${var.hostname}" + admin_username = "${var.admin_username}" + admin_password = "${var.admin_password}" + } + + boot_diagnostics { + enabled = "true" + storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}" + } +} diff --git a/examples/azure-vm-simple-linux/outputs.tf b/examples/azure-vm-simple-linux/outputs.tf new file mode 100644 index 000000000..9e3c2f071 --- /dev/null +++ b/examples/azure-vm-simple-linux/outputs.tf @@ -0,0 +1,11 @@ +output "hostname" { + value = "${var.hostname}" +} + +output "vm_fqdn" { + value = "${azurerm_public_ip.pip.fqdn}" +} + +output "sshCommand" { + value = "ssh ${var.admin_username}@${azurerm_public_ip.pip.fqdn}" +} diff --git a/examples/azure-vm-simple-linux/provider.tf.example b/examples/azure-vm-simple-linux/provider.tf.example new file mode 100644 index 000000000..327ceb55e --- /dev/null +++ b/examples/azure-vm-simple-linux/provider.tf.example @@ -0,0 +1,6 @@ +provider "azurerm" { + subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" + client_id = "REPLACE-WITH-YOUR-CLIENT-ID" + client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" + tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" +} \ No newline at end of file diff --git a/examples/azure-vm-simple-linux/terraform.tfvars.example b/examples/azure-vm-simple-linux/terraform.tfvars.example new file mode 100644 index 000000000..262093ba5 --- /dev/null +++ b/examples/azure-vm-simple-linux/terraform.tfvars.example @@ -0,0 +1,6 @@ +resource_group = "myresourcegroup" +rg_prefix = "rg" +hostname = "myvm" +dns_name = "mydnsname" +location = "southcentralus" +admin_password = "T3rr@f0rmP@ssword" diff --git a/examples/azure-vm-simple-linux/variables.tf b/examples/azure-vm-simple-linux/variables.tf new file mode 100644 index 000000000..6d65a0277 --- /dev/null +++ b/examples/azure-vm-simple-linux/variables.tf @@ -0,0 +1,75 @@ +variable "resource_group" { + description = "The name of the resource group in which to create the virtual network." +} + +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" { + description = "VM name referenced also in storage-related names." +} + +variable "dns_name" { + description = " Label for the Domain Name. Will be used to make up the FQDN. If a domain name label is specified, an A DNS record is created for the public IP in the Microsoft Azure DNS system." +} + +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" { + description = "The name for the virtual network." + default = "vnet" +} + +variable "address_space" { + description = "The address space that is used by the virtual network. You can supply more than one address space. Changing this forces a new resource to be created." + default = "10.0.0.0/16" +} + +variable "subnet_prefix" { + description = "The address prefix to use for the subnet." + default = "10.0.10.0/24" +} + +variable "storage_account_type" { + description = "Specifies the name of the storage account. Changing this forces a new resource to be created. This must be unique across the entire Azure service, not just within the resource group." + default = "Standard_LRS" +} + +variable "vm_size" { + description = "Specifies the name of the virtual machine resource. Changing this forces a new resource to be created." + default = "Standard_A0" +} + +variable "image_publisher" { + description = "name of the publisher of the image (az vm image list)" + default = "Canonical" +} + +variable "image_offer" { + description = "the name of the offer (az vm image list)" + default = "UbuntuServer" +} + +variable "image_sku" { + description = "image sku to apply (az vm image list)" + default = "16.04-LTS" +} + +variable "image_version" { + description = "version of the image to apply (az vm image list)" + default = "latest" +} + +variable "admin_username" { + description = "administrator user name" + default = "vmadmin" +} + +variable "admin_password" { + description = "administrator password (recommended to disable password auth)" +} From 1ce99f692975656d45c0c9d299204b90dde03069 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 26 Apr 2017 14:53:15 -0500 Subject: [PATCH 69/82] added deployment script for mac; ensured managed disks are being used --- .../README.md | 0 .../after_deploy.sh | 0 .../deploy.mac.sh | 23 +++++++++++++ .../deploy.sh | 0 .../main.tf | 32 +++++++------------ .../outputs.tf | 0 .../provider.tf | 0 .../terraform.tfvars | 0 .../variables.tf | 0 9 files changed, 35 insertions(+), 20 deletions(-) rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/README.md (100%) rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/after_deploy.sh (100%) create mode 100755 examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/deploy.sh (100%) rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/main.tf (76%) rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/outputs.tf (100%) rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/provider.tf (100%) rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/terraform.tfvars (100%) rename examples/{azure-vm-simple-linux => azure-vm-simple-linux-managed-disk}/variables.tf (100%) diff --git a/examples/azure-vm-simple-linux/README.md b/examples/azure-vm-simple-linux-managed-disk/README.md similarity index 100% rename from examples/azure-vm-simple-linux/README.md rename to examples/azure-vm-simple-linux-managed-disk/README.md diff --git a/examples/azure-vm-simple-linux/after_deploy.sh b/examples/azure-vm-simple-linux-managed-disk/after_deploy.sh similarity index 100% rename from examples/azure-vm-simple-linux/after_deploy.sh rename to examples/azure-vm-simple-linux-managed-disk/after_deploy.sh diff --git a/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh new file mode 100755 index 000000000..ab076afdb --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh @@ -0,0 +1,23 @@ +#!/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 + +### capture vm image +# 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 vm deallocate --name rgvm --resource-group permanent; \ +# az vm generalize --name rgvm --resource-group permanent; \ +# az image create --name customImage --source rgvm --resource-group permanent" + +### cleanup +# 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-managed-disk/deploy.sh similarity index 100% rename from examples/azure-vm-simple-linux/deploy.sh rename to examples/azure-vm-simple-linux-managed-disk/deploy.sh diff --git a/examples/azure-vm-simple-linux/main.tf b/examples/azure-vm-simple-linux-managed-disk/main.tf similarity index 76% rename from examples/azure-vm-simple-linux/main.tf rename to examples/azure-vm-simple-linux-managed-disk/main.tf index cf931d0f9..e9c0877d5 100644 --- a/examples/azure-vm-simple-linux/main.tf +++ b/examples/azure-vm-simple-linux-managed-disk/main.tf @@ -52,17 +52,8 @@ resource "azurerm_storage_container" "storc" { container_access_type = "private" } -resource "azurerm_managed_disk" "disk1" { - name = "${var.hostname}-osdisk1" - location = "${var.location}" - resource_group_name = "${azurerm_resource_group.rg.name}" - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "30" -} - -resource "azurerm_managed_disk" "disk2" { - name = "${var.hostname}-disk2" +resource "azurerm_managed_disk" "datadisk" { + name = "${var.hostname}-datadisk" location = "${var.location}" resource_group_name = "${azurerm_resource_group.rg.name}" storage_account_type = "Standard_LRS" @@ -85,18 +76,19 @@ resource "azurerm_virtual_machine" "vm" { } storage_os_disk { - name = "${var.hostname}-osdisk1" - vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-osdisk1.vhd" - caching = "ReadWrite" - create_option = "FromImage" + name = "${var.hostname}-osdisk" + managed_disk_type = "Standard_LRS" + caching = "ReadWrite" + create_option = "FromImage" } storage_data_disk { - name = "${var.hostname}-disk2" - vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-disk2.vhd" - disk_size_gb = "1023" - create_option = "Empty" - lun = 0 + name = "${var.hostname}-datadisk" + managed_disk_id = "${azurerm_managed_disk.datadisk.id}" + managed_disk_type = "Standard_LRS" + disk_size_gb = "1023" + create_option = "Attach" + lun = 0 } os_profile { diff --git a/examples/azure-vm-simple-linux/outputs.tf b/examples/azure-vm-simple-linux-managed-disk/outputs.tf similarity index 100% rename from examples/azure-vm-simple-linux/outputs.tf rename to examples/azure-vm-simple-linux-managed-disk/outputs.tf diff --git a/examples/azure-vm-simple-linux/provider.tf b/examples/azure-vm-simple-linux-managed-disk/provider.tf similarity index 100% rename from examples/azure-vm-simple-linux/provider.tf rename to examples/azure-vm-simple-linux-managed-disk/provider.tf diff --git a/examples/azure-vm-simple-linux/terraform.tfvars b/examples/azure-vm-simple-linux-managed-disk/terraform.tfvars similarity index 100% rename from examples/azure-vm-simple-linux/terraform.tfvars rename to examples/azure-vm-simple-linux-managed-disk/terraform.tfvars diff --git a/examples/azure-vm-simple-linux/variables.tf b/examples/azure-vm-simple-linux-managed-disk/variables.tf similarity index 100% rename from examples/azure-vm-simple-linux/variables.tf rename to examples/azure-vm-simple-linux-managed-disk/variables.tf From f635bbd0312a1fb1766e62f7aa49af9650e37a88 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 26 Apr 2017 20:48:45 -0500 Subject: [PATCH 70/82] updated build dir --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5afb53c89..7a97c1e91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ language: generic # establish environment variables env: - - TEST_DIR=examples/azure-vm-simple-linux + - TEST_DIR=examples/azure-vm-simple-linux-managed-disk branches: only: From 56f6aa16c4148b097c5ad8edac9ca3034554cdcc Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Wed, 26 Apr 2017 21:53:25 -0500 Subject: [PATCH 71/82] renamed scripts to be more intuitive; added check for docker --- .travis.yml | 4 ++-- .../{after_deploy.sh => after_deploy.ci.sh} | 0 .../{deploy.sh => deploy.ci.sh} | 4 ++-- .../deploy.mac.sh | 24 +++++++------------ 4 files changed, 12 insertions(+), 20 deletions(-) rename examples/azure-vm-simple-linux-managed-disk/{after_deploy.sh => after_deploy.ci.sh} (100%) rename examples/azure-vm-simple-linux-managed-disk/{deploy.sh => deploy.ci.sh} (90%) diff --git a/.travis.yml b/.travis.yml index 7a97c1e91..9c9210904 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,10 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.sh + script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.ci.sh on: repo: harijayms/terraform branch: master # handle cleanup of resources -after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.sh +after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.ci.sh diff --git a/examples/azure-vm-simple-linux-managed-disk/after_deploy.sh b/examples/azure-vm-simple-linux-managed-disk/after_deploy.ci.sh similarity index 100% rename from examples/azure-vm-simple-linux-managed-disk/after_deploy.sh rename to examples/azure-vm-simple-linux-managed-disk/after_deploy.ci.sh diff --git a/examples/azure-vm-simple-linux-managed-disk/deploy.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh similarity index 90% rename from examples/azure-vm-simple-linux-managed-disk/deploy.sh rename to examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh index 5347f3a83..8fa08573f 100755 --- a/examples/azure-vm-simple-linux-managed-disk/deploy.sh +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh @@ -8,10 +8,10 @@ docker run --rm -it \ -e ARM_SUBSCRIPTION_ID \ -e ARM_TENANT_ID \ -v $(pwd):/data \ + --workdir=/data \ --entrypoint "/bin/sh" \ hashicorp/terraform:light \ - -c "cd /data; \ - /bin/terraform get; \ + -c "/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-managed-disk/deploy.mac.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh index ab076afdb..9c6563f07 100755 --- a/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh @@ -2,22 +2,14 @@ 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) +if docker -v; then -/bin/sh ./deploy.sh + # 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) -### capture vm image -# 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 vm deallocate --name rgvm --resource-group permanent; \ -# az vm generalize --name rgvm --resource-group permanent; \ -# az image create --name customImage --source rgvm --resource-group permanent" + /bin/sh ./deploy.ci.sh -### cleanup -# 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" +else + echo "Docker is used to run terraform commands, please install before run: https://docs.docker.com/docker-for-mac/install/" +fi From 829b69625b1162cb5b9624a92ef731dd08ca96ea Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 11:40:53 -0500 Subject: [PATCH 72/82] early prep for CI of examples (#7) * early prep for CI of examples * added note to prevent moving upstream --- .travis.yml | 65 ++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04cc6f309..686656f9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,42 +1,35 @@ -dist: trusty -sudo: false -language: go -go: -- 1.8 +#################################################################################### +## NOT FOR UPSTREAM PROPOSAL; INTENDED FOR CI OF AZURE EXAMPLES IN THIS REPO ONLY ## +#################################################################################### + +sudo: required + +services: + - docker + +language: generic -# add TF_CONSUL_TEST=1 to run consul tests -# they were causing timouts in travis env: - - CONSUL_VERSION=0.7.5 GOMAXPROCS=4 + - TEST_DIR=examples/azure-vm-simple-linux -# Fetch consul for the backend and provider tests -before_install: - - curl -sLo consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip - - unzip consul.zip - - mkdir ~/bin - - mv consul ~/bin - - export PATH="~/bin:$PATH" - -install: -# This script is used by the Travis build to install a cookie for -# go.googlesource.com so rate limits are higher when using `go get` to fetch -# packages that live there. -# See: https://github.com/golang/go/issues/12933 -- bash scripts/gogetcookie.sh -- go get github.com/kardianos/govendor -script: -- make vet vendor-status test -- GOOS=windows go build branches: only: - master -notifications: - irc: - channels: - - irc.freenode.org#terraform-tool - skip_join: true - use_notice: true -matrix: - fast_finish: true - allow_failures: - - go: tip + +# install terraform +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 + skip_cleanup: true + script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.sh + on: + repo: harijayms/terraform + branch: master + condition: false + +# destroy resources with Azure CLI +after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.sh From 77775462ff802257fece757fc8ef7a86423e0f85 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 12:16:00 -0500 Subject: [PATCH 73/82] consolidated deploy and after_deploy into a single script; simplified ci process; added os_profile_linux_config --- .travis.yml | 5 +---- .../after_deploy.ci.sh | 9 --------- .../deploy.ci.sh | 20 +++++++++++++++++++ .../main.tf | 4 ++++ 4 files changed, 25 insertions(+), 13 deletions(-) delete mode 100755 examples/azure-vm-simple-linux-managed-disk/after_deploy.ci.sh diff --git a/.travis.yml b/.travis.yml index e1e60f70e..95eea8d31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,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 +# terraform deploy + script deploy: - provider: script skip_cleanup: true @@ -30,6 +30,3 @@ deploy: on: repo: harijayms/terraform branch: master - -# handle cleanup of resources -after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.ci.sh diff --git a/examples/azure-vm-simple-linux-managed-disk/after_deploy.ci.sh b/examples/azure-vm-simple-linux-managed-disk/after_deploy.ci.sh deleted file mode 100755 index 245aba380..000000000 --- a/examples/azure-vm-simple-linux-managed-disk/after_deploy.ci.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -set -o errexit -o nounset - -# cleanup deployed azure resources -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-managed-disk/deploy.ci.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh index 8fa08573f..f3f20ba1d 100755 --- a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh @@ -15,3 +15,23 @@ docker run --rm -it \ /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" + + +# cleanup deployed azure resources via terraform +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data \ + --workdir=/data \ + --entrypoint "/bin/sh" \ + hashicorp/terraform:light \ + -c "/bin/terraform destroy -force -var dns_name=$KEY -var hostname=$KEY -var resource_group=$KEY -var admin_password=$PASSWORD;" + + +# cleanup deployed azure resources via azure-cli +# 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-managed-disk/main.tf b/examples/azure-vm-simple-linux-managed-disk/main.tf index e9c0877d5..b476042c7 100644 --- a/examples/azure-vm-simple-linux-managed-disk/main.tf +++ b/examples/azure-vm-simple-linux-managed-disk/main.tf @@ -97,6 +97,10 @@ resource "azurerm_virtual_machine" "vm" { admin_password = "${var.admin_password}" } + os_profile_linux_config { + disable_password_authentication = false + } + boot_diagnostics { enabled = "true" storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}" From 7a34501edfc93abb91caf3b83856ea5f48b24959 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 17:13:19 -0500 Subject: [PATCH 74/82] removed container resource; added terraform show --- examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh | 3 ++- examples/azure-vm-simple-linux-managed-disk/main.tf | 7 ------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh index f3f20ba1d..80c14cd5b 100755 --- a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh @@ -14,7 +14,8 @@ docker run --rm -it \ -c "/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" + /bin/terraform apply out.tfplan; \ + /bin/terraform show;" # cleanup deployed azure resources via terraform diff --git a/examples/azure-vm-simple-linux-managed-disk/main.tf b/examples/azure-vm-simple-linux-managed-disk/main.tf index b476042c7..17a5c23e9 100644 --- a/examples/azure-vm-simple-linux-managed-disk/main.tf +++ b/examples/azure-vm-simple-linux-managed-disk/main.tf @@ -45,13 +45,6 @@ resource "azurerm_storage_account" "stor" { account_type = "${var.storage_account_type}" } -resource "azurerm_storage_container" "storc" { - name = "${var.hostname}-vhds" - resource_group_name = "${azurerm_resource_group.rg.name}" - storage_account_name = "${azurerm_storage_account.stor.name}" - container_access_type = "private" -} - resource "azurerm_managed_disk" "datadisk" { name = "${var.hostname}-datadisk" location = "${var.location}" From 714076043e8688233065a867401e46200f15d519 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 17:32:49 -0500 Subject: [PATCH 75/82] updated incorrect descriptions --- examples/azure-vm-simple-linux-managed-disk/variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/azure-vm-simple-linux-managed-disk/variables.tf b/examples/azure-vm-simple-linux-managed-disk/variables.tf index 6d65a0277..17fbe337d 100644 --- a/examples/azure-vm-simple-linux-managed-disk/variables.tf +++ b/examples/azure-vm-simple-linux-managed-disk/variables.tf @@ -36,12 +36,12 @@ variable "subnet_prefix" { } variable "storage_account_type" { - description = "Specifies the name of the storage account. Changing this forces a new resource to be created. This must be unique across the entire Azure service, not just within the resource group." + description = "Defines the type of storage account to be created. Valid options are Standard_LRS, Standard_ZRS, Standard_GRS, Standard_RAGRS, Premium_LRS. Changing this is sometimes valid - see the Azure documentation for more information on which types of accounts can be converted into other types." default = "Standard_LRS" } variable "vm_size" { - description = "Specifies the name of the virtual machine resource. Changing this forces a new resource to be created." + description = "Specifies the size of the virtual machine." default = "Standard_A0" } From 121a60192f92181ef8b85b9c7ba41feba45b13eb Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 18:00:43 -0500 Subject: [PATCH 76/82] Enabled CI runs for master This should enable CI on PRs for examples (until an example PR is merged) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 686656f9b..814cc864a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: branches: only: - master + - /^(?i:topic)-.*$/ # install terraform before_deploy: @@ -29,7 +30,6 @@ deploy: on: repo: harijayms/terraform branch: master - condition: false # destroy resources with Azure CLI after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.sh From 5f577c7b3a34aaee334b2f942a65a2aff3b3f3ae Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 18:10:17 -0500 Subject: [PATCH 77/82] added az vm show between apply & destroy --- .../azure-vm-simple-linux-managed-disk/deploy.ci.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh index 80c14cd5b..a81f0979f 100755 --- a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh @@ -17,6 +17,11 @@ docker run --rm -it \ /bin/terraform apply out.tfplan; \ /bin/terraform show;" +# cleanup deployed azure resources via azure-cli +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 vm show -g $KEY -n rgvm" # cleanup deployed azure resources via terraform docker run --rm -it \ @@ -29,10 +34,3 @@ docker run --rm -it \ --entrypoint "/bin/sh" \ hashicorp/terraform:light \ -c "/bin/terraform destroy -force -var dns_name=$KEY -var hostname=$KEY -var resource_group=$KEY -var admin_password=$PASSWORD;" - - -# cleanup deployed azure resources via azure-cli -# 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" From 291305bddb40d2d1710dbe5b27ab663bc98351f7 Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 19:47:01 -0500 Subject: [PATCH 78/82] run CI on branch prior to merge --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dc362203e..6fa53b484 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,4 +30,4 @@ deploy: script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.ci.sh on: repo: harijayms/terraform - branch: master + branch: topic-101-vm-simple-linux From 4438a06891f318bb1e483232617f433c0d8f308f Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Thu, 27 Apr 2017 19:51:24 -0500 Subject: [PATCH 79/82] merge branch topic-101-vm-simple-linux --- .travis.yml | 10 +- .../README.md | 24 +++++ .../deploy.ci.sh | 36 +++++++ .../deploy.mac.sh | 15 +++ .../main.tf | 101 ++++++++++++++++++ .../outputs.tf | 11 ++ .../provider.tf | 7 ++ .../terraform.tfvars | 8 ++ .../variables.tf | 75 +++++++++++++ 9 files changed, 281 insertions(+), 6 deletions(-) create mode 100644 examples/azure-vm-simple-linux-managed-disk/README.md create mode 100755 examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh create mode 100755 examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh create mode 100644 examples/azure-vm-simple-linux-managed-disk/main.tf create mode 100644 examples/azure-vm-simple-linux-managed-disk/outputs.tf create mode 100644 examples/azure-vm-simple-linux-managed-disk/provider.tf create mode 100644 examples/azure-vm-simple-linux-managed-disk/terraform.tfvars create mode 100644 examples/azure-vm-simple-linux-managed-disk/variables.tf diff --git a/.travis.yml b/.travis.yml index 814cc864a..dc362203e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,9 @@ services: language: generic +# establish environment variables env: - - TEST_DIR=examples/azure-vm-simple-linux + - TEST_DIR=examples/azure-vm-simple-linux-managed-disk branches: only: @@ -22,14 +23,11 @@ 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 +# terraform deploy + script deploy: - provider: script skip_cleanup: true - script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.sh + script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.ci.sh on: repo: harijayms/terraform branch: master - -# destroy resources with Azure CLI -after_deploy: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./after_deploy.sh diff --git a/examples/azure-vm-simple-linux-managed-disk/README.md b/examples/azure-vm-simple-linux-managed-disk/README.md new file mode 100644 index 000000000..0492e3edc --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/README.md @@ -0,0 +1,24 @@ +# Very simple deployment of a Linux VM + + + + + +This template allows you to deploy a simple Linux VM using a few different options for the Ubuntu version, using the latest patched version. This will deploy a A1 size VM in the resource group location and return the FQDN of the VM. + +This template takes a minimum amount of parameters and deploys a Linux VM, using the latest patched version. + +## main.tf +The `main.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. + +## outputs.tf +This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command. + +## provider.tf +Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file. + +## terraform.tfvars +If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it. + +## variables.tf +The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. diff --git a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh new file mode 100755 index 000000000..a81f0979f --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +set -o errexit -o nounset + +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data \ + --workdir=/data \ + --entrypoint "/bin/sh" \ + hashicorp/terraform:light \ + -c "/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; \ + /bin/terraform show;" + +# cleanup deployed azure resources via azure-cli +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 vm show -g $KEY -n rgvm" + +# cleanup deployed azure resources via terraform +docker run --rm -it \ + -e ARM_CLIENT_ID \ + -e ARM_CLIENT_SECRET \ + -e ARM_SUBSCRIPTION_ID \ + -e ARM_TENANT_ID \ + -v $(pwd):/data \ + --workdir=/data \ + --entrypoint "/bin/sh" \ + hashicorp/terraform:light \ + -c "/bin/terraform destroy -force -var dns_name=$KEY -var hostname=$KEY -var resource_group=$KEY -var admin_password=$PASSWORD;" diff --git a/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh new file mode 100755 index 000000000..9c6563f07 --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.mac.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -o errexit -o nounset + +if docker -v; then + + # 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.ci.sh + +else + echo "Docker is used to run terraform commands, please install before run: https://docs.docker.com/docker-for-mac/install/" +fi diff --git a/examples/azure-vm-simple-linux-managed-disk/main.tf b/examples/azure-vm-simple-linux-managed-disk/main.tf new file mode 100644 index 000000000..17a5c23e9 --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/main.tf @@ -0,0 +1,101 @@ +resource "azurerm_resource_group" "rg" { + name = "${var.resource_group}" + location = "${var.location}" +} + +resource "azurerm_virtual_network" "vnet" { + name = "${var.virtual_network_name}" + location = "${var.location}" + address_space = ["${var.address_space}"] + resource_group_name = "${azurerm_resource_group.rg.name}" +} + +resource "azurerm_subnet" "subnet" { + name = "${var.rg_prefix}subnet" + virtual_network_name = "${azurerm_virtual_network.vnet.name}" + resource_group_name = "${azurerm_resource_group.rg.name}" + address_prefix = "${var.subnet_prefix}" +} + +resource "azurerm_network_interface" "nic" { + name = "${var.rg_prefix}nic" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + + ip_configuration { + name = "${var.rg_prefix}ipconfig" + subnet_id = "${azurerm_subnet.subnet.id}" + private_ip_address_allocation = "Dynamic" + public_ip_address_id = "${azurerm_public_ip.pip.id}" + } +} + +resource "azurerm_public_ip" "pip" { + name = "${var.rg_prefix}-ip" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + public_ip_address_allocation = "dynamic" + domain_name_label = "${var.dns_name}" +} + +resource "azurerm_storage_account" "stor" { + name = "${var.dns_name}stor" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + account_type = "${var.storage_account_type}" +} + +resource "azurerm_managed_disk" "datadisk" { + name = "${var.hostname}-datadisk" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1023" +} + +resource "azurerm_virtual_machine" "vm" { + name = "${var.rg_prefix}vm" + location = "${var.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + vm_size = "${var.vm_size}" + network_interface_ids = ["${azurerm_network_interface.nic.id}"] + + storage_image_reference { + publisher = "${var.image_publisher}" + offer = "${var.image_offer}" + sku = "${var.image_sku}" + version = "${var.image_version}" + } + + storage_os_disk { + name = "${var.hostname}-osdisk" + managed_disk_type = "Standard_LRS" + caching = "ReadWrite" + create_option = "FromImage" + } + + storage_data_disk { + name = "${var.hostname}-datadisk" + managed_disk_id = "${azurerm_managed_disk.datadisk.id}" + managed_disk_type = "Standard_LRS" + disk_size_gb = "1023" + create_option = "Attach" + lun = 0 + } + + os_profile { + computer_name = "${var.hostname}" + admin_username = "${var.admin_username}" + admin_password = "${var.admin_password}" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + boot_diagnostics { + enabled = "true" + storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}" + } +} diff --git a/examples/azure-vm-simple-linux-managed-disk/outputs.tf b/examples/azure-vm-simple-linux-managed-disk/outputs.tf new file mode 100644 index 000000000..9e3c2f071 --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/outputs.tf @@ -0,0 +1,11 @@ +output "hostname" { + value = "${var.hostname}" +} + +output "vm_fqdn" { + value = "${azurerm_public_ip.pip.fqdn}" +} + +output "sshCommand" { + value = "ssh ${var.admin_username}@${azurerm_public_ip.pip.fqdn}" +} diff --git a/examples/azure-vm-simple-linux-managed-disk/provider.tf b/examples/azure-vm-simple-linux-managed-disk/provider.tf new file mode 100644 index 000000000..79291f7ca --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/provider.tf @@ -0,0 +1,7 @@ +# provider "azurerm" { +# subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" +# client_id = "REPLACE-WITH-YOUR-CLIENT-ID" +# client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" +# tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" +# } + diff --git a/examples/azure-vm-simple-linux-managed-disk/terraform.tfvars b/examples/azure-vm-simple-linux-managed-disk/terraform.tfvars new file mode 100644 index 000000000..bee98e4e1 --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/terraform.tfvars @@ -0,0 +1,8 @@ +# Replace with relevant values + +# resource_group = "myresourcegroup" +# rg_prefix = "rg" +# hostname = "myvm" +# dns_name = "mydnsname" +# location = "southcentralus" +# admin_password = "T3rr@f0rmP@ssword" diff --git a/examples/azure-vm-simple-linux-managed-disk/variables.tf b/examples/azure-vm-simple-linux-managed-disk/variables.tf new file mode 100644 index 000000000..17fbe337d --- /dev/null +++ b/examples/azure-vm-simple-linux-managed-disk/variables.tf @@ -0,0 +1,75 @@ +variable "resource_group" { + description = "The name of the resource group in which to create the virtual network." +} + +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" { + description = "VM name referenced also in storage-related names." +} + +variable "dns_name" { + description = " Label for the Domain Name. Will be used to make up the FQDN. If a domain name label is specified, an A DNS record is created for the public IP in the Microsoft Azure DNS system." +} + +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" { + description = "The name for the virtual network." + default = "vnet" +} + +variable "address_space" { + description = "The address space that is used by the virtual network. You can supply more than one address space. Changing this forces a new resource to be created." + default = "10.0.0.0/16" +} + +variable "subnet_prefix" { + description = "The address prefix to use for the subnet." + default = "10.0.10.0/24" +} + +variable "storage_account_type" { + description = "Defines the type of storage account to be created. Valid options are Standard_LRS, Standard_ZRS, Standard_GRS, Standard_RAGRS, Premium_LRS. Changing this is sometimes valid - see the Azure documentation for more information on which types of accounts can be converted into other types." + default = "Standard_LRS" +} + +variable "vm_size" { + description = "Specifies the size of the virtual machine." + default = "Standard_A0" +} + +variable "image_publisher" { + description = "name of the publisher of the image (az vm image list)" + default = "Canonical" +} + +variable "image_offer" { + description = "the name of the offer (az vm image list)" + default = "UbuntuServer" +} + +variable "image_sku" { + description = "image sku to apply (az vm image list)" + default = "16.04-LTS" +} + +variable "image_version" { + description = "version of the image to apply (az vm image list)" + default = "latest" +} + +variable "admin_username" { + description = "administrator user name" + default = "vmadmin" +} + +variable "admin_password" { + description = "administrator password (recommended to disable password auth)" +} From 1e80f4ff61138c7bac00d9d5aff13786a6f63ddc Mon Sep 17 00:00:00 2001 From: Scott Nowicki Date: Fri, 28 Apr 2017 15:45:00 -0500 Subject: [PATCH 80/82] redirect output of az login to /dev/null to hide SPN detail (#11) --- examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh index a81f0979f..03e56e00a 100755 --- a/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh +++ b/examples/azure-vm-simple-linux-managed-disk/deploy.ci.sh @@ -20,7 +20,7 @@ docker run --rm -it \ # cleanup deployed azure resources via azure-cli 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; \ + sh -c "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID > /dev/null; \ az vm show -g $KEY -n rgvm" # cleanup deployed azure resources via terraform From 0f1af30c789e1f61ebc5e0c32fd10eec456d6620 Mon Sep 17 00:00:00 2001 From: anniehedgpeth Date: Tue, 2 May 2017 14:09:41 -0500 Subject: [PATCH 81/82] removed tfvars & provider; minor changes to main & outputs per PR --- examples/azure-vm-simple-linux-managed-disk/README.md | 6 +----- examples/azure-vm-simple-linux-managed-disk/main.tf | 11 +++++++++-- .../azure-vm-simple-linux-managed-disk/outputs.tf | 2 +- .../azure-vm-simple-linux-managed-disk/provider.tf | 7 ------- .../terraform.tfvars | 8 -------- 5 files changed, 11 insertions(+), 23 deletions(-) delete mode 100644 examples/azure-vm-simple-linux-managed-disk/provider.tf delete mode 100644 examples/azure-vm-simple-linux-managed-disk/terraform.tfvars diff --git a/examples/azure-vm-simple-linux-managed-disk/README.md b/examples/azure-vm-simple-linux-managed-disk/README.md index 0492e3edc..b8d0706a1 100644 --- a/examples/azure-vm-simple-linux-managed-disk/README.md +++ b/examples/azure-vm-simple-linux-managed-disk/README.md @@ -1,10 +1,6 @@ # Very simple deployment of a Linux VM - - - - -This template allows you to deploy a simple Linux VM using a few different options for the Ubuntu version, using the latest patched version. This will deploy a A1 size VM in the resource group location and return the FQDN of the VM. +This template allows you to deploy a simple Linux VM using a few different options for the Ubuntu version, using the latest patched version. This will deploy an A0 size VM in the resource group location and return the FQDN of the VM. This template takes a minimum amount of parameters and deploys a Linux VM, using the latest patched version. diff --git a/examples/azure-vm-simple-linux-managed-disk/main.tf b/examples/azure-vm-simple-linux-managed-disk/main.tf index 17a5c23e9..ee44db013 100644 --- a/examples/azure-vm-simple-linux-managed-disk/main.tf +++ b/examples/azure-vm-simple-linux-managed-disk/main.tf @@ -1,3 +1,10 @@ +# provider "azurerm" { +# subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" +# client_id = "REPLACE-WITH-YOUR-CLIENT-ID" +# client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" +# tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" +# } + resource "azurerm_resource_group" "rg" { name = "${var.resource_group}" location = "${var.location}" @@ -34,7 +41,7 @@ resource "azurerm_public_ip" "pip" { name = "${var.rg_prefix}-ip" location = "${var.location}" resource_group_name = "${azurerm_resource_group.rg.name}" - public_ip_address_allocation = "dynamic" + public_ip_address_allocation = "Dynamic" domain_name_label = "${var.dns_name}" } @@ -95,7 +102,7 @@ resource "azurerm_virtual_machine" "vm" { } boot_diagnostics { - enabled = "true" + enabled = true storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}" } } diff --git a/examples/azure-vm-simple-linux-managed-disk/outputs.tf b/examples/azure-vm-simple-linux-managed-disk/outputs.tf index 9e3c2f071..13768e554 100644 --- a/examples/azure-vm-simple-linux-managed-disk/outputs.tf +++ b/examples/azure-vm-simple-linux-managed-disk/outputs.tf @@ -6,6 +6,6 @@ output "vm_fqdn" { value = "${azurerm_public_ip.pip.fqdn}" } -output "sshCommand" { +output "ssh_command" { value = "ssh ${var.admin_username}@${azurerm_public_ip.pip.fqdn}" } diff --git a/examples/azure-vm-simple-linux-managed-disk/provider.tf b/examples/azure-vm-simple-linux-managed-disk/provider.tf deleted file mode 100644 index 79291f7ca..000000000 --- a/examples/azure-vm-simple-linux-managed-disk/provider.tf +++ /dev/null @@ -1,7 +0,0 @@ -# provider "azurerm" { -# subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" -# client_id = "REPLACE-WITH-YOUR-CLIENT-ID" -# client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" -# tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" -# } - diff --git a/examples/azure-vm-simple-linux-managed-disk/terraform.tfvars b/examples/azure-vm-simple-linux-managed-disk/terraform.tfvars deleted file mode 100644 index bee98e4e1..000000000 --- a/examples/azure-vm-simple-linux-managed-disk/terraform.tfvars +++ /dev/null @@ -1,8 +0,0 @@ -# Replace with relevant values - -# resource_group = "myresourcegroup" -# rg_prefix = "rg" -# hostname = "myvm" -# dns_name = "mydnsname" -# location = "southcentralus" -# admin_password = "T3rr@f0rmP@ssword" From 93164799e7608a6030b76859748a434e1f631024 Mon Sep 17 00:00:00 2001 From: anniehedgpeth Date: Tue, 2 May 2017 14:33:52 -0500 Subject: [PATCH 82/82] .travis.yml reverted back to hashicorp's master .travis.yml --- .travis.yml | 63 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6fa53b484..1c60d74d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,33 +1,42 @@ -#################################################################################### -## NOT FOR UPSTREAM PROPOSAL; INTENDED FOR CI OF AZURE EXAMPLES IN THIS REPO ONLY ## -#################################################################################### +dist: trusty +sudo: false +language: go +go: +- 1.8.x -sudo: required - -services: - - docker - -language: generic - -# establish environment variables +# add TF_CONSUL_TEST=1 to run consul tests +# they were causing timouts in travis env: - - TEST_DIR=examples/azure-vm-simple-linux-managed-disk + - CONSUL_VERSION=0.7.5 GOMAXPROCS=4 +# Fetch consul for the backend and provider tests +before_install: + - curl -sLo consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip + - unzip consul.zip + - mkdir ~/bin + - mv consul ~/bin + - export PATH="~/bin:$PATH" + +install: +# This script is used by the Travis build to install a cookie for +# go.googlesource.com so rate limits are higher when using `go get` to fetch +# packages that live there. +# See: https://github.com/golang/go/issues/12933 +- bash scripts/gogetcookie.sh +- go get github.com/kardianos/govendor +script: +- make vendor-status test vet +- GOOS=windows go build branches: only: - master - - /^(?i:topic)-.*$/ - -# install terraform -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 - skip_cleanup: true - script: cd $TRAVIS_BUILD_DIR/$TEST_DIR && ./deploy.ci.sh - on: - repo: harijayms/terraform - branch: topic-101-vm-simple-linux +notifications: + irc: + channels: + - irc.freenode.org#terraform-tool + skip_join: true + use_notice: true +matrix: + fast_finish: true + allow_failures: + - go: tip \ No newline at end of file