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

terraform version upgrade to v0.12 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- docker

env:
- TERRAFORM_VERSION=0.11.7 IMAGE_NAME=azure-manageddisk-module
- TERRAFORM_VERSION=0.12.10 IMAGE_NAME=azure-manageddisk-module

jobs:
include:
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pull the base image with given version.
ARG BUILD_TERRAFORM_VERSION="0.11.7"
FROM microsoft/terraform-test:${BUILD_TERRAFORM_VERSION}
ARG BUILD_TERRAFORM_VERSION="0.12.10"
FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION}

ARG MODULE_NAME="terraform-azurerm-manageddisk"

Expand Down Expand Up @@ -32,5 +32,6 @@ WORKDIR /go/src/${MODULE_NAME}
ENV GOPATH /go
ENV PATH /usr/local/go/bin:$GOPATH/bin:$PATH
RUN /bin/bash -c "curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh"
RUN terraform init

RUN ["bundle", "install", "--gemfile", "./Gemfile"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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.3.0'
end
end
34 changes: 15 additions & 19 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
#Azure Managed Disk Module
provider "azurerm" {
#version = "~> 0.3"
}

data "azurerm_resource_group" "passed" {
name = "${var.resource_group_name}"
name = var.resource_group_name
}

locals {
# set flags depending on inputs
import_vhd = "${length(var.source_uri)>0 ? 1 : 0}"
copy_disk = "${length(var.source_resource_id)>0 ? 1 : 0}"
copy_image = "${length(var.image_reference_id)>0 ? 1 : 0}"
import_vhd = length(var.source_uri) > 0 ? 1 : 0
copy_disk = length(var.source_resource_id) > 0 ? 1 : 0
copy_image = length(var.image_reference_id) > 0 ? 1 : 0

# if exactly one of the previous is set, then not empty disk, but import or copy as denoted.
# if 0 or >1 of the previous set, default to empty disk.
create_empty = "${local.import_vhd+local.copy_disk+local.copy_image==1 ? 0 : 1}"
create_empty = local.import_vhd + local.copy_disk + local.copy_image == 1 ? 0 : 1

# figure out the create_option for the azurerm_managed_disk resource
create_option = "${local.create_empty==1 ? "Empty" : (local.import_vhd==1 ? "Import" : (local.copy_disk==1 ? "Copy" : "FromImage"))}"
create_option = local.create_empty == 1 ? "Empty" : (local.import_vhd == 1 ? "Import" : (local.copy_disk == 1 ? "Copy" : "FromImage"))
}

resource "azurerm_managed_disk" "disk" {
name = "${var.managed_disk_name}"
resource_group_name = "${data.azurerm_resource_group.passed.name}"
name = var.managed_disk_name
resource_group_name = data.azurerm_resource_group.passed.name

# you can put the managed disk in another location
# if you don't specify location, it'll be created in resource group location
location = "${coalesce(var.location, data.azurerm_resource_group.passed.location)}"
location = coalesce(var.location, data.azurerm_resource_group.passed.location)

storage_account_type = "${var.storage_account_type}"
create_option = "${local.create_option}"
source_uri = "${var.source_uri}"
source_resource_id = "${var.source_resource_id}"
image_reference_id = "${var.image_reference_id}"
disk_size_gb = "${var.disk_size_gb}"
storage_account_type = var.storage_account_type
create_option = local.create_option
source_uri = var.source_uri
source_resource_id = var.source_resource_id
image_reference_id = var.image_reference_id
disk_size_gb = var.disk_size_gb
}
14 changes: 7 additions & 7 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
output "managed_disk_id" {
description = "The id of the newly created managed disk"
value = "${azurerm_managed_disk.disk.id}"
value = azurerm_managed_disk.disk.id
}

output "import_vhd" {
description = "Says that a source_uri was provided."
value = "${local.import_vhd}"
value = local.import_vhd
}

output "copy_disk" {
description = "Says that a source_resource_id was provided."
value = "${local.copy_disk}"
value = local.copy_disk
}

output "copy_image" {
description = "Says that a image_resource_id was provided."
value = "${local.copy_image}"
value = local.copy_image
}

output "create_empty" {
description = "Says that a new empty disk will be created."
value = "${local.create_empty}"
value = local.create_empty
}

output "create_option" {
description = "Tells the create option for the managed disk resource."
value = "${local.create_option}"
value = local.create_option
}

output "disk_size_gb" {
description = "Tells the disk_size_gb provided by input."
value = "${var.disk_size_gb}"
value = var.disk_size_gb
}
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "disk_size_gb" {

variable "tags" {
description = "The tags to associate with your managed disk."
type = "map"
type = map(string)

default = {
tag1 = ""
Expand Down