Skip to content

Commit

Permalink
Merge pull request #873 from gruntwork-io/tf15
Browse files Browse the repository at this point in the history
Update to Terraform 0.15
  • Loading branch information
brikis98 authored Apr 23, 2021
2 parents 737e05c + cdb010a commit adca4a8
Show file tree
Hide file tree
Showing 29 changed files with 96 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ env: &env
GRUNTWORK_INSTALLER_VERSION: v0.0.34
MODULE_CI_VERSION: v0.29.2
MODULE_GCP_CI_VERSION: v0.1.1
TERRAFORM_VERSION: 0.14.0
TERRAGRUNT_VERSION: v0.24.2
TERRAFORM_VERSION: 0.15.0
TERRAGRUNT_VERSION: v0.28.24
PACKER_VERSION: 1.6.6
GO_VERSION: 1.14
K8S_VERSION: v1.15.0 # Same as EKS
Expand Down
2 changes: 1 addition & 1 deletion examples/terraform-asg-scp-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ provider "aws" {
resource "aws_launch_template" "sample_launch_template" {
name_prefix = var.instance_name
image_id = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
instance_type = var.instance_type
vpc_security_group_ids = [aws_security_group.example.id]
key_name = var.key_pair_name
}
Expand Down
5 changes: 5 additions & 0 deletions examples/terraform-asg-scp-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ variable "ssh_port" {
default = 22
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion examples/terraform-aws-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {

resource "aws_instance" "example" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
instance_type = var.instance_type

tags = {
Name = var.instance_name
Expand Down
5 changes: 5 additions & 0 deletions examples/terraform-aws-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ variable "instance_name" {
default = "terratest-example"
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion examples/terraform-aws-ssm-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ data "aws_ami" "amazon_linux_2" {

resource "aws_instance" "example" {
ami = data.aws_ami.amazon_linux_2.id
instance_type = "t2.micro"
instance_type = var.instance_type
associate_public_ip_address = true
iam_instance_profile = aws_iam_instance_profile.example.name
}
6 changes: 6 additions & 0 deletions examples/terraform-aws-ssm-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ variable "region" {
description = "The AWS region to deploy into"
default = "us-east-1"
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion examples/terraform-http-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ provider "aws" {

resource "aws_instance" "example" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
instance_type = var.instance_type
user_data = data.template_file.user_data.rendered
vpc_security_group_ids = [aws_security_group.example.id]

Expand Down
5 changes: 5 additions & 0 deletions examples/terraform-http-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ variable "instance_text" {
default = "Hello, World!"
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion examples/terraform-packer-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ provider "aws" {

resource "aws_instance" "example" {
ami = var.ami_id
instance_type = "t2.micro"
instance_type = var.instance_type
user_data = data.template_file.user_data.rendered
vpc_security_group_ids = [aws_security_group.example.id]

Expand Down
5 changes: 5 additions & 0 deletions examples/terraform-packer-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ variable "instance_text" {
default = "Hello, World!"
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion examples/terraform-redeploy-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ resource "aws_autoscaling_group" "web_servers" {

resource "aws_launch_configuration" "web_servers" {
image_id = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
instance_type = var.instance_type
security_groups = [aws_security_group.web_server.id]
user_data = data.template_file.user_data.rendered
key_name = var.key_pair_name
Expand Down
5 changes: 5 additions & 0 deletions examples/terraform-redeploy-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ variable "key_pair_name" {
default = ""
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
4 changes: 2 additions & 2 deletions examples/terraform-ssh-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ provider "aws" {

resource "aws_instance" "example_public" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
instance_type = var.instance_type
vpc_security_group_ids = [aws_security_group.example.id]
key_name = var.key_pair_name

Expand All @@ -43,7 +43,7 @@ resource "aws_instance" "example_public" {

resource "aws_instance" "example_private" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
instance_type = var.instance_type
vpc_security_group_ids = [aws_security_group.example.id]
key_name = var.key_pair_name

Expand Down
5 changes: 5 additions & 0 deletions examples/terraform-ssh-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ variable "ssh_port" {
default = 22
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion examples/terraform-ssh-password-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ provider "aws" {

resource "aws_instance" "example_public" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
instance_type = var.instance_type
user_data = data.template_file.user_data.rendered

vpc_security_group_ids = [
Expand Down
5 changes: 5 additions & 0 deletions examples/terraform-ssh-password-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ variable "ssh_port" {
default = 22
}

variable "instance_type" {
description = "The EC2 instance type to run."
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion modules/terraform/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestInitAndPlanWithPlanFile(t *testing.T) {
out, err := InitAndPlanE(t, options)
require.NoError(t, err)
assert.Contains(t, out, "1 to add, 0 to change, 0 to destroy.")
assert.Contains(t, out, fmt.Sprintf("This plan was saved to: %s", planFilePath))
assert.Contains(t, out, fmt.Sprintf("Saved the plan to: %s", planFilePath))
assert.FileExists(t, planFilePath, "Plan file was not saved to expected location:", planFilePath)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/terraform/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestShowWithInlinePlan(t *testing.T) {
}

out := InitAndPlan(t, options)
require.Contains(t, out, fmt.Sprintf("This plan was saved to: %s", planFilePath))
require.Contains(t, out, fmt.Sprintf("Saved the plan to: %s", planFilePath))
require.FileExists(t, planFilePath, "Plan file was not saved to expected location:", planFilePath)

// show command does not accept Vars
Expand Down
5 changes: 5 additions & 0 deletions test/azure/terraform_azure_postgresql_example_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// +build azure

// NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for
// CircleCI.

package test

import (
Expand Down
4 changes: 4 additions & 0 deletions test/terraform_aws_example_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func TestTerraformAwsExamplePlan(t *testing.T) {
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomStableRegion(t, nil, nil)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// website::tag::1::Configure Terraform setting path to Terraform code, EC2 instance name, and AWS Region. We also
// configure the options with default retryable errors to handle the most common retryable errors encountered in
// terraform testing.
Expand All @@ -39,6 +42,7 @@ func TestTerraformAwsExamplePlan(t *testing.T) {
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"instance_name": expectedName,
"instance_type": instanceType,
},

// Environment variables to set when running Terraform
Expand Down
4 changes: 4 additions & 0 deletions test/terraform_aws_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func TestTerraformAwsExample(t *testing.T) {
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomStableRegion(t, nil, nil)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// website::tag::1::Configure Terraform setting path to Terraform code, EC2 instance name, and AWS Region. We also
// configure the options with default retryable errors to handle the most common retryable errors encountered in
// terraform testing.
Expand All @@ -36,6 +39,7 @@ func TestTerraformAwsExample(t *testing.T) {
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"instance_name": expectedName,
"instance_type": instanceType,
},

// Environment variables to set when running Terraform
Expand Down
6 changes: 5 additions & 1 deletion test/terraform_aws_ssm_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ func TestTerraformAwsSsmExample(t *testing.T) {
t.Parallel()
region := aws.GetRandomStableRegion(t, nil, nil)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, region, []string{"t2.micro", "t3.micro"})

terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples/terraform-aws-ssm-example",
Vars: map[string]interface{}{
"region": region,
"region": region,
"instance_type": instanceType,
},
})
defer terraform.Destroy(t, terraformOptions)
Expand Down
4 changes: 4 additions & 0 deletions test/terraform_http_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func TestTerraformHttpExample(t *testing.T) {
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomStableRegion(t, nil, nil)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// Construct the terraform options with default retryable errors to handle the most common retryable errors in
// terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
Expand All @@ -41,6 +44,7 @@ func TestTerraformHttpExample(t *testing.T) {
"aws_region": awsRegion,
"instance_name": instanceName,
"instance_text": instanceText,
"instance_type": instanceType,
},
})

Expand Down
4 changes: 4 additions & 0 deletions test/terraform_packer_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func deployUsingTerraform(t *testing.T, awsRegion string, workingDir string) {
// Specify the text the EC2 Instance will return when we make HTTP requests to it.
instanceText := fmt.Sprintf("Hello, %s!", uniqueID)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// Load the AMI ID saved by the earlier build_ami stage
amiID := test_structure.LoadAmiId(t, workingDir)

Expand All @@ -133,6 +136,7 @@ func deployUsingTerraform(t *testing.T, awsRegion string, workingDir string) {
"aws_region": awsRegion,
"instance_name": instanceName,
"instance_text": instanceText,
"instance_type": instanceType,
"ami_id": amiID,
},
})
Expand Down
4 changes: 4 additions & 0 deletions test/terraform_redeploy_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func initialDeploy(t *testing.T, awsRegion string, workingDir string) {
// Specify the text the ASG will return when we make HTTP requests to it.
text := fmt.Sprintf("Hello, %s!", uniqueID)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// Construct the terraform options with default retryable errors to handle the most common retryable errors in
// terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
Expand All @@ -99,6 +102,7 @@ func initialDeploy(t *testing.T, awsRegion string, workingDir string) {
"aws_region": awsRegion,
"instance_name": name,
"instance_text": text,
"instance_type": instanceType,
"key_pair_name": keyPair.Name,
},
})
Expand Down
4 changes: 4 additions & 0 deletions test/terraform_scp_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func createTerraformOptions(t *testing.T, exampleFolder string) (*terraform.Opti
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomStableRegion(t, nil, nil)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// Create an EC2 KeyPair that we can use for SSH access
keyPairName := fmt.Sprintf("terratest-asg-scp-example-%s", uniqueID)
keyPair := aws.CreateAndImportEC2KeyPair(t, awsRegion, keyPairName)
Expand All @@ -97,6 +100,7 @@ func createTerraformOptions(t *testing.T, exampleFolder string) (*terraform.Opti
"aws_region": awsRegion,
"instance_name": instanceName,
"key_pair_name": keyPairName,
"instance_type": instanceType,
},
})

Expand Down
4 changes: 4 additions & 0 deletions test/terraform_ssh_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func configureTerraformOptions(t *testing.T, exampleFolder string) (*terraform.O
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomStableRegion(t, nil, nil)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// Create an EC2 KeyPair that we can use for SSH access
keyPairName := fmt.Sprintf("terratest-ssh-example-%s", uniqueID)
keyPair := aws.CreateAndImportEC2KeyPair(t, awsRegion, keyPairName)
Expand All @@ -86,6 +89,7 @@ func configureTerraformOptions(t *testing.T, exampleFolder string) (*terraform.O
Vars: map[string]interface{}{
"aws_region": awsRegion,
"instance_name": instanceName,
"instance_type": instanceType,
"key_pair_name": keyPairName,
},
})
Expand Down
4 changes: 4 additions & 0 deletions test/terraform_ssh_password_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func configureTerraformSshPasswordOptions(t *testing.T, exampleFolder string) *t
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomStableRegion(t, nil, nil)

// Some AWS regions are missing certain instance types, so pick an available type based on the region we picked
instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro", "t3.micro"})

// Create a random password that we can use for SSH access.
password := random.UniqueId()

Expand All @@ -73,6 +76,7 @@ func configureTerraformSshPasswordOptions(t *testing.T, exampleFolder string) *t
Vars: map[string]interface{}{
"aws_region": awsRegion,
"instance_name": instanceName,
"instance_type": instanceType,
"terratest_password": password,
},
})
Expand Down

0 comments on commit adca4a8

Please sign in to comment.