Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build test #2

Merged
merged 9 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .kitchen.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ services:
- docker

env:
- TERRAFORM_VERSION=0.11.3 IMAGE_NAME=azure-compute-module
- TERRAFORM_VERSION=0.11.1 IMAGE_NAME=azure-compute-module

jobs:
include:
- stage: rake full
install: true
script:
- docker build --build-arg BUILD_TERRAFORM_VERSION=${TERRAFORM_VERSION} --build-arg BUILD_ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID --build-arg BUILD_ARM_CLIENT_ID=$ARM_CLIENT_ID --build-arg BUILD_ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET --build-arg BUILD_ARM_TENANT_ID=$ARM_TENANT_ID -t ${IMAGE_NAME} .
- docker build --build-arg BUILD_TERRAFORM_VERSION=${TERRAFORM_VERSION} -t ${IMAGE_NAME} .
- docker run ${IMAGE_NAME} rake full
30 changes: 23 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ FROM microsoft/terraform-test:${BUILD_TERRAFORM_VERSION}
ARG MODULE_NAME="terraform-azurerm-compute"

# Declare default build configurations for terraform.
ARG BUILD_ARM_SUBSCRIPTION_ID=""
ARG BUILD_ARM_CLIENT_ID=""
ARG BUILD_ARM_CLIENT_SECRET=""
ARG BUILD_ARM_TENANT_ID=""
ARG BUILD_ARM_SUBSCRIPTION_ID="85b3dbca-5974-4067-9669-67a141095a76"
ARG BUILD_ARM_CLIENT_ID="27419052-4753-4544-a684-ec356a9e5ec2"
ARG BUILD_ARM_CLIENT_SECRET="a67a709e-e595-40e0-812e-fe47342b4452"
ARG BUILD_ARM_TENANT_ID="72f988bf-86f1-41af-91ab-2d7cd011db47"
ARG BUILD_ARM_TEST_LOCATION="WestEurope"
ARG BUILD_ARM_TEST_LOCATION_ALT="WestUS"

Expand All @@ -20,10 +20,26 @@ ENV ARM_TENANT_ID=${BUILD_ARM_TENANT_ID}
ENV ARM_TEST_LOCATION=${BUILD_ARM_TEST_LOCATION}
ENV ARM_TEST_LOCATION_ALT=${BUILD_ARM_TEST_LOCATION_ALT}

# Set work directory and generate ssh key
RUN mkdir /usr/src/${MODULE_NAME}
COPY . /usr/src/${MODULE_NAME}

WORKDIR /usr/src/${MODULE_NAME}
RUN ssh-keygen -q -t rsa -b 4096 -f $HOME/.ssh/id_rsa

WORKDIR /usr/src/${MODULE_NAME}
RUN ["bundle", "install", "--gemfile", "./Gemfile"]
# Install new version of terraform and golang
RUN apt-get install -y unzip >/dev/null
RUN wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip >/dev/null 2>&1
RUN unzip terraform_0.11.7_linux_amd64.zip >/dev/null
RUN wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz >/dev/null 2>&1
RUN tar -zxvf go1.9.2.linux-amd64.tar.gz -C /usr/local/ >/dev/null
RUN mv terraform /usr/local/bin

# Install required go packages
ENV GOPATH $HOME/terratest/ssh
ENV PATH /usr/local/go/bin:/usr/local/bin:/usr/bin
RUN /bin/bash -c "go get github.com/gruntwork-io/terratest/modules/ssh"
RUN /bin/bash -c "go get github.com/gruntwork-io/terratest/modules/retry"
RUN /bin/bash -c "go get github.com/gruntwork-io/terratest/modules/terraform"
RUN /bin/bash -c "go get github.com/gruntwork-io/terratest/modules/test-structure"

RUN ["bundle", "install", "--gemfile", "./Gemfile"]
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ source 'https://rubygems.org/'

group :test do
git 'https://github.com/Azure/terramodtest.git' do
gem 'terramodtest', :tag => 'v0.2.0'
gem 'terramodtest', :tag => 'v0.1.0'
end
gem 'test-kitchen', '1.16.0'
gem 'kitchen-terraform', '3.0.0'
end
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# terraform-azurerm-compute #
[![Build Status](https://travis-ci.org/Azure/terraform-azurerm-compute.svg?branch=master)](https://travis-ci.org/Azure/terraform-azurerm-compute)
# terraform-azurerm-compute

Deploys 1+ Virtual Machines to your provided VNet
=================================================
[![Build Status](https://travis-ci.org/foreverXZC/terraform-azurerm-compute.svg?branch=master)](https://travis-ci.org/foreverXZC/terraform-azurerm-compute)

## Deploys 1+ Virtual Machines to your provided VNet

This Terraform module deploys Virtual Machines in Azure with the following characteristics:

Expand All @@ -14,8 +14,7 @@ This Terraform module deploys Virtual Machines in Azure with the following chara

> Note: Terraform module registry is incorrect in the number of required parameters since it only deems required based on variables with non-existent values. The actual minimum required variables depends on the configuration and is specified below in the usage.

Simple Usage
-----
## Simple Usage

This contains the bare minimum options to be configured for the VM to be provisioned. The entire code block provisions a Windows and a Linux VM, but feel free to delete one or the other and corresponding outputs. The outputs are also not necessary to provision, but included to make it convenient to know the address to connect to the VMs after provisioning completes.

Expand Down Expand Up @@ -58,8 +57,7 @@ Provisions an Ubuntu Server 16.04-LTS VM and a Windows 2016 Datacenter Server VM
}
```

Advanced Usage
-----
## Advanced Usage

The following example illustrates some of the configuration options available to deploy a virtual machine. Feel free to remove the Linux or Windows modules and corresponding outputs.

Expand All @@ -81,7 +79,7 @@ More specifically this provisions:
- Two Public IP addresses (one for each VM)
- Opens up port 3389 for RDP access using the password as shown

```hcl
```hcl
module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = "terraform-advancedvms"
Expand Down Expand Up @@ -149,10 +147,10 @@ More specifically this provisions:

```

Test
-----
## Test

### Configurations

- [Configure Terraform for Azure](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure)
- [Generate and add SSH Key](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/) Save the key in ~/.ssh/id_rsa. This is not required for Windows deployments.

Expand All @@ -161,6 +159,7 @@ We provide 2 ways to build, run, and test the module on a local development mach
### Native (Mac/Linux)

#### Prerequisites

- [Ruby **(~> 2.3)**](https://www.ruby-lang.org/en/downloads/)
- [Bundler **(~> 1.15)**](https://bundler.io/)
- [Terraform **(~> 0.11.0)**](https://www.terraform.io/downloads.html)
Expand All @@ -170,21 +169,22 @@ We provide 2 ways to build, run, and test the module on a local development mach
We provide simple script to quickly set up module development environment:

```sh
$ curl -sSL https://raw.githubusercontent.com/Azure/terramodtest/master/tool/env_setup.sh | sudo bash
curl -sSL https://raw.githubusercontent.com/Azure/terramodtest/master/tool/env_setup.sh | sudo bash
```

Then simply run it in local shell:

```sh
$ bundle install
$ rake build
$ rake e2e
bundle install
rake build
rake e2e
```

### Docker

We provide a Dockerfile to build a new image based `FROM` the `microsoft/terraform-test` Docker hub image which adds additional tools / packages specific for this module (see Custom Image section). Alternatively use only the `microsoft/terraform-test` Docker hub image [by using these instructions](https://github.com/Azure/terraform-test).

#### Prerequisites
#### Prerequisites (Docker)

- [Docker](https://www.docker.com/community-edition#/download)

Expand All @@ -193,26 +193,31 @@ We provide a Dockerfile to build a new image based `FROM` the `microsoft/terrafo
This builds the custom image:

```sh
$ docker build --build-arg BUILD_ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID --build-arg BUILD_ARM_CLIENT_ID=$ARM_CLIENT_ID --build-arg BUILD_ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET --build-arg BUILD_ARM_TENANT_ID=$ARM_TENANT_ID -t azure-compute .
docker build --build-arg BUILD_ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID --build-arg BUILD_ARM_CLIENT_ID=$ARM_CLIENT_ID --build-arg BUILD_ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET --build-arg BUILD_ARM_TENANT_ID=$ARM_TENANT_ID -t azure-compute .
```

This runs the build and unit tests:

```sh
$ docker run --rm azure-compute /bin/bash -c "bundle install && rake build"
docker run --rm azure-compute /bin/bash -c "bundle install && rake build"
```

This runs the end to end tests:

```sh
$ docker run --rm azure-compute /bin/bash -c "bundle install && rake e2e"
docker run --rm azure-compute /bin/bash -c "bundle install && rake e2e"
```

Authors
=======
This runs the full tests:

```sh
docker run azure-compute rake full
```

## Authors

Originally created by [David Tesar](http://github.com/dtzar)

License
=======
## License

[MIT](LICENSE)
25 changes: 6 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ require 'rspec/core/rake_task'
require 'bundler/setup'
require 'terramodtest'

namespace :presteps do
task :clean_up do
clean_up_kitchen
clean_up_terraform
end
end

namespace :static do
task :style do
style_tf
Expand All @@ -26,21 +19,15 @@ namespace :static do
end

namespace :integration do
task :converge do
kitchen_converge
end
task :verify do
kitchen_verify
end
task :test do
kitchen_test
end
task :destroy do
kitchen_destroy
success = system ("go test -v terratest/ssh/terraform_ssh_example_test.go -timeout 20m -args azureuser ~/.ssh/id_rsa")
if not success
raise "ERROR: Go test failed!\n".red
end
end
end

task :prereqs => [ 'presteps:clean_up' ]
task :prereqs => []

task :validate => [ 'static:style', 'static:lint' ]

Expand All @@ -54,4 +41,4 @@ task :e2e => [ 'integration:test' ]

task :default => [ 'build' ]

task :full => [ 'build', 'unit', 'e2e']
task :full => [ 'build', 'unit', 'e2e' ]
12 changes: 6 additions & 6 deletions terratest/compute/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ resource "random_id" "ip_dns" {
}

module "ubuntuservers" {
source = "Azure/compute/azurerm"
source = "../../"
location = "${var.location}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
vm_os_simple = "${var.vm_os_simple_1}"
public_ip_dns = ["ubuntusimplevmips-${random_id.ip_dns.hex}"]
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
ssh_key = "${var.ssh_key}"
resource_group_name = "${var.resource_group_name}"
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
public_ip_address_allocation = "static"
}

module "debianservers" {
source = "Azure/compute/azurerm"
source = "../../"
location = "${var.location}"
vm_hostname = "mylinvm"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
vm_os_simple = "${var.vm_os_simple_2}"
public_ip_dns = ["debiansimplevmips-${random_id.ip_dns.hex}"] // change to a unique name per datacenter region
public_ip_dns = ["debiansimplevmips-${random_id.ip_dns.hex}"] // change to a unique name per datacenter region
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
ssh_key = "${var.ssh_key}"
resource_group_name = "${var.resource_group_name}"
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
public_ip_address_allocation = "static"
}

module "network" {
source = "Azure/network/azurerm"
version = "2.0.0"
location = "westus2"
resource_group_name = "${var.resource_group_name}"
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
}
2 changes: 1 addition & 1 deletion terratest/compute/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
location = "westus2"
ssh_key = ""
ssh_key = "~/.ssh/id_rsa.pub"
resource_group_name = "terraform-compute"
vm_os_simple_1 = "UbuntuServer"
vm_os_simple_2 = "Debian"
Expand Down
4 changes: 2 additions & 2 deletions terratest/ssh/terraform_ssh_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func testSSHToPublicHost(t *testing.T, terraformOptions *terraform.Options, addr
publicIP := terraform.Output(t, terraformOptions, address)

// Read private key from given file
buffer, err := ioutil.ReadFile(os.Args[2])
buffer, err := ioutil.ReadFile(os.Args[len(os.Args)-1])
if err != nil {
t.Fatal(err)
}
Expand All @@ -74,7 +74,7 @@ func testSSHToPublicHost(t *testing.T, terraformOptions *terraform.Options, addr
publicHost := ssh.Host{
Hostname: publicIP,
SshKeyPair: &keyPair,
SshUserName: os.Args[1],
SshUserName: os.Args[len(os.Args)-2],
}

// It can take a minute or so for the virtual machine to boot up, so retry a few times
Expand Down