Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.
Open
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: 12 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
FROM ruby:2.3
ARG tfver
ARG gover
ENV TERRAFORM_VERSION=$tfver
ENV GOLANG_VERSION=$gover
FROM golang:1.10.4-alpine3.8

COPY ["Gemfile", "Rakefile", "/tf-test/"]
COPY build/ /tf-test/build/
RUN apt-get update && gem update --system && apt-get install unzip \
&& curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
&& curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS \
&& curl https://keybase.io/hashicorp/pgp_keys.asc | gpg --import \
&& curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig \
&& gpg --verify terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig terraform_${TERRAFORM_VERSION}_SHA256SUMS \
&& shasum -a 256 -c terraform_${TERRAFORM_VERSION}_SHA256SUMS 2>&1 | grep "${TERRAFORM_VERSION}_linux_amd64.zip:\sOK" \
&& unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin
ENV TERRAFORM_VERSION=0.11.7-r0

WORKDIR /tf-test/
RUN gem install rake --version =12.3.0 \
&& gem install colorize --version =0.8.1 \
&& gem install rspec --version =3.7.0
WORKDIR /tf-test/module
RUN apk add terraform=$TERRAFORM_VERSION bash git

RUN curl -Os https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz >/dev/null 2>&1 \
&& tar -zxvf go${GOLANG_VERSION}.linux-amd64.tar.gz -C /usr/local/ >/dev/null
ENV PATH /usr/local/go/bin:$PATH
ENV GOPATH $HOME/go
RUN /bin/bash -c "wget -O - https://raw.githubusercontent.com/golang/dep/master/install.sh | sh"

COPY ./azure-terraform-module-test.sh /bin/
RUN chmod 744 /bin/azure-terraform-module-test.sh

RUN mkdir -p /go/src/module
WORKDIR /go/src/module

ENTRYPOINT ["azure-terraform-module-test.sh"]
12 changes: 0 additions & 12 deletions Gemfile

This file was deleted.

9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export MODULE_PATH=/user/me/source/Azure/terraform-azurerm-modulename
Now run the lint tests:

```shell
docker run -v $MODULE_PATH:/tf-test/module --rm microsoft/terraform-test rake -f ../Rakefile build
docker run -v $MODULE_PATH:/go/src/module --rm microsoft/terraform-test azure-terraform-module-test.sh validate
```

## End to End Tests
Expand All @@ -42,9 +42,6 @@ The container uses Azure SPN Keys to access Azure. The following environment var
ARM_TEST_LOCATION_ALT=westus
```

Log Setup
The logs generated by the test will be stored in the `/tf-test/.kitchen` directory in the container. Mount this directory to the location of your choice so you can keep the logs once the test have completed.

Secret Setup
Some test may require SSH keys or other secrets to be passed to the container. For SSH keys, mount the directory where they are located as `/root/.ssh` in the container. If you are reusing your keys, the above command should be:

Expand All @@ -59,11 +56,9 @@ export MODULE_PATH=/user/me/source/Azure/terraform-azurerm-modulename
Now run the tests using this docker command:

```shell
docker run -v ~/.ssh:/root/.ssh/ -v $MODULE_PATH/logs:/tf-test/module/.kitchen -v $MODULE_PATH:/tf-test/module -e ARM_CLIENT_ID -e ARM_TENANT_ID -e ARM_SUBSCRIPTION_ID -e ARM_CLIENT_SECRET -e ARM_TEST_LOCATION -e ARM_TEST_LOCATION_ALT --rm microsoft/terraform-test rake -f ../Rakefile e2e
docker run -v $MODULE_PATH:/go/src/module -e ARM_CLIENT_ID -e ARM_TENANT_ID -e ARM_SUBSCRIPTION_ID -e ARM_CLIENT_SECRET -e ARM_TEST_LOCATION -e ARM_TEST_LOCATION_ALT --rm microsoft/terraform-test azure-terraform-module-test.sh full
```

This may take a number of minutes depending on the size of the module and there will be no output to the terminal until the tests complete. To see progress, look at the files being generated and updated under the local `$MODULE_PATH/logs` directory.

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
67 changes: 0 additions & 67 deletions Rakefile

This file was deleted.

35 changes: 35 additions & 0 deletions azure-terraform-module-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /bin/bash
if [ $# != 1 ] || [ $1 != "validate" -a $1 != "full" ]; then
echo "Please pass 'validate' or 'full' parameter."
exit 1
fi

run_command()
{
echo "Running: $1"
$1
if [ $? != 0 ]; then
echo "Failed: $1"
exit 1
else
echo "Passed: $1"
fi
}

COMMANDS=()

if [ $1 == "validate" ] || [ $1 == "full" ]
then
COMMANDS+=("terraform fmt -check=true -diff=true")
COMMANDS+=("terraform validate -check-variables=false")
COMMANDS+=("dep ensure")
fi

if [ $1 == "full" ]; then
COMMANDS+=("go test -v ./test/ -timeout 20m")
fi

for command in "${COMMANDS[@]}"
do
run_command "$command"
done
15 changes: 0 additions & 15 deletions build/file_utils.rb

This file was deleted.

41 changes: 0 additions & 41 deletions build/static_utils.rb

This file was deleted.