Skip to content

Commit

Permalink
Enable Rake workflow for loadbalancer module (Azure#8)
Browse files Browse the repository at this point in the history
* Enable Rake workflow for loadbalancer module

* Added newlines per PR comments

* Removed the unused TERRAFORM_VERSION variable

* Added terraform runtime version support to docker image

* Fixed build-arg  typo
  • Loading branch information
WodansSon authored Jan 18, 2018
1 parent 274de48 commit ee83ff3
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 11 deletions.
19 changes: 15 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,32 @@ terraform.tfvars
# Module directory
.terraform/


### https://raw.github.com/github/gitignore/abad92dac5a4306f72242dae3bca6e277bce3615/Global/Vim.gitignore

# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim

# temporary
.netrwhist
*~

# auto-generated tag files
tags

# Dependencies from microsoft/terraform-test Docker image
Gemfile
Rakefile
build/
build/

# IDE configs
.idea

# Ruby download package lock file.
Gemfile.lock

# Test Kitchen files.
.kitchen

# Mac folder attribute file
.DS_Store
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
sudo: true
dist: trusty
# Build matrix / environment variable are explained on:
# http://about.travis-ci.org/docs/user/build-configuration/
# This file can be validated on:
# http://lint.travis-ci.org/
sudo: required

language: ruby

rvm:
- 2.3

services:
- docker

env:
- TERRAFORM_VERSION=0.11.1 IMAGE_NAME=azure-loadbalancer-module

jobs:
include:
- stage: rake build
install: true
script:
- docker run -v $PWD:/tf-test/module --rm microsoft/terraform-test rake -f ../Rakefile build
- docker build --build-arg BUILD_TERRAFORM_VERSION=${TERRAFORM_VERSION} -t ${IMAGE_NAME} .
- docker run ${IMAGE_NAME} rake build
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Pull the base image with passed terraform runtime version
ARG BUILD_TERRAFORM_VERSION="0.11.1"
FROM microsoft/terraform-test:${BUILD_TERRAFORM_VERSION}

ARG MODULE_NAME="terraform-azurerm-loadbalancer"

# Declare default environment variable values for terraform runtime.
ARG BUILD_ARM_SUBSCRIPTION_ID=""
ARG BUILD_ARM_CLIENT_ID=""
ARG BUILD_ARM_CLIENT_SECRET=""
ARG BUILD_ARM_TENANT_ID=""
ARG BUILD_ARM_TEST_LOCATION="WestEurope"
ARG BUILD_ARM_TEST_LOCATION_ALT="WestUS"

# Set environment variables for terraform runtime.
ENV ARM_SUBSCRIPTION_ID=${BUILD_ARM_SUBSCRIPTION_ID}
ENV ARM_CLIENT_ID=${BUILD_ARM_CLIENT_ID}
ENV ARM_CLIENT_SECRET=${BUILD_ARM_CLIENT_SECRET}
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}

RUN mkdir /usr/src/${MODULE_NAME}
COPY . /usr/src/${MODULE_NAME}

WORKDIR /usr/src/${MODULE_NAME}
RUN ["bundle", "install", "--gemfile", "./Gemfile"]
11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ruby "~> 2.3.0"

source 'https://rubygems.org/'

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

A terraform module to provide load balancers in Azure.
Create a basic load balancer in Azure
===========

This Terraform module deploys a load balancer in Azure.

Usage
-----
Expand All @@ -25,10 +27,52 @@ module "mylb" {
}
```

Test
-----
### Configurations
- [Configure Terraform for Azure](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure)

We provide 2 ways to build, run, and test module on local dev box:

### 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)

#### Environment setup
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
```
#### Run test
Then simply run it in local shell:
```sh
$ bundle install
$ rake build
```

### Docker
We provide Dockerfile to build and run module development environment locally:

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

#### Build the image
```sh
docker build -t azure-loadbalancer .
```
#### Run test
```sh
$ docker run -it azure-loadbalancer /bin/sh
$ rake build
```

Authors
=======

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

License
=======
Expand Down
40 changes: 40 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Official gems.
require 'colorize'
require 'rspec/core/rake_task'

# Git repo gems.
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
end
task :lint do
lint_tf
end
task :format do
format_tf
end
end

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

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

task :format => [ 'static:format' ]

task :build => [ 'prereqs', 'validate' ]

task :unit => []

task :default => [ 'build' ]

task :full => [ 'build']

0 comments on commit ee83ff3

Please sign in to comment.