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

Fix terraform validation issues #931

Merged
merged 6 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions examples/terraform-aws-dynamodb-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# PIN TERRAFORM VERSION TO >= 0.12
# The examples have been upgraded to 0.12 syntax
# ---------------------------------------------------------------------------------------------------------------------
provider "aws" {
region = var.region
}

terraform {
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
Expand Down
9 changes: 8 additions & 1 deletion examples/terraform-aws-dynamodb-example/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ---------------------------------------------------------------------------------------------------------------------
# REQUIRED PARAMETERS
# ---------------------------------------------------------------------------------------------------------------------
variable "region" {
description = "The AWS region to deploy to"
type = string
}

# ---------------------------------------------------------------------------------------------------------------------
# OPTIONAL PARAMETERS
# These parameters have reasonable defaults.
Expand All @@ -8,4 +16,3 @@ variable "table_name" {
type = string
default = "terratest-example"
}

3 changes: 3 additions & 0 deletions examples/terraform-aws-ecs-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# PIN TERRAFORM VERSION TO >= 0.12
# The examples have been upgraded to 0.12 syntax
# ---------------------------------------------------------------------------------------------------------------------
provider "aws" {
region = var.region
}

terraform {
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
Expand Down
3 changes: 3 additions & 0 deletions examples/terraform-aws-lambda-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# AWS LAMBDA TERRAFORM EXAMPLE
# See test/terraform_aws_lambda_example_test.go for how to write automated tests for this code.
# ---------------------------------------------------------------------------------------------------------------------
provider "aws" {
region = var.region
}

terraform {
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
Expand Down
5 changes: 4 additions & 1 deletion examples/terraform-aws-lambda-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
# REQUIRED PARAMETERS
# You must provide a value for each of these parameters.
# ---------------------------------------------------------------------------------------------------------------------

variable "region" {
description = "The AWS region to deploy to"
type = string
}

variable "function_name" {
description = "The name of the function to provision"
Expand Down
5 changes: 4 additions & 1 deletion examples/terraform-aws-rds-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# The examples have been upgraded to 0.12 syntax
# ---------------------------------------------------------------------------------------------------------------------

provider "aws" {
region = var.region
}

terraform {
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
Expand Down Expand Up @@ -119,4 +123,3 @@ resource "aws_db_instance" "example" {
Name = var.name
}
}

4 changes: 4 additions & 0 deletions examples/terraform-aws-rds-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# You must provide a value for each of these parameters.
# Given these are credentials, security of the values should be considered.
# ---------------------------------------------------------------------------------------------------------------------
variable "region" {
description = "The AWS region to deploy to"
type = string
}

variable "username" {
description = "Master username of the DB"
Expand Down
3 changes: 3 additions & 0 deletions examples/terraform-aws-s3-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# PIN TERRAFORM VERSION TO >= 0.12
# The examples have been upgraded to 0.12 syntax
# ---------------------------------------------------------------------------------------------------------------------
provider "aws" {
region = var.region
}

terraform {
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
Expand Down
4 changes: 4 additions & 0 deletions examples/terraform-aws-s3-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
# REQUIRED PARAMETERS
# You must provide a value for each of these parameters.
# ---------------------------------------------------------------------------------------------------------------------
variable "region" {
description = "The AWS region to deploy to"
type = string
}

# ---------------------------------------------------------------------------------------------------------------------
# OPTIONAL PARAMETERS
Expand Down
6 changes: 5 additions & 1 deletion modules/terraform/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ func TestValidateAllTerraformModulesOnTerratest(t *testing.T) {

projectRootDir := filepath.Join(cwd, "../..")

opts, optsErr := NewValidationOptions(projectRootDir, []string{}, []string{"test/fixtures/terraform-with-plan-error", "examples/terraform-backend-example"})
opts, optsErr := NewValidationOptions(projectRootDir, []string{}, []string{
"test/fixtures/terraform-with-plan-error",
"test/fixtures/terragrunt/terragrunt-with-plan-error",
"examples/terraform-backend-example",
})
require.NoError(t, optsErr)

ValidateAllTerraformModules(t, opts)
Expand Down
6 changes: 1 addition & 5 deletions test/terraform_aws_dynamodb_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ func TestTerraformAwsDynamoDBExample(t *testing.T) {
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"table_name": expectedTableName,
},

// Environment variables to set when running Terraform
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
"region": awsRegion,
},
})

Expand Down
6 changes: 1 addition & 5 deletions test/terraform_aws_ecs_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ func TestTerraformAwsEcsExample(t *testing.T) {
Vars: map[string]interface{}{
"cluster_name": expectedClusterName,
"service_name": expectedServiceName,
},

// Environment variables to set when running Terraform
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
"region": awsRegion,
},
})

Expand Down
12 changes: 2 additions & 10 deletions test/terraform_aws_lambda_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ func TestTerraformAwsLambdaExample(t *testing.T) {
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"function_name": functionName,
},

// Environment variables to set when running Terraform
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
"region": awsRegion,
},
})

Expand Down Expand Up @@ -93,11 +89,7 @@ func TestTerraformAwsLambdaWithParamsExample(t *testing.T) {
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"function_name": functionName,
},

// Environment variables to set when running Terraform
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
"region": awsRegion,
},
})

Expand Down
6 changes: 1 addition & 5 deletions test/terraform_aws_rds_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ func TestTerraformAwsRdsExample(t *testing.T) {
"engine_version": "5.7.21",
"port": expectedPort,
"database_name": expectedDatabaseName,
},

// Environment variables to set when running Terraform
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
"region": awsRegion,
},
})

Expand Down
6 changes: 1 addition & 5 deletions test/terraform_aws_s3_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ func TestTerraformAwsS3Example(t *testing.T) {
"tag_bucket_name": expectedName,
"tag_bucket_environment": expectedEnvironment,
"with_policy": "true",
},

// Environment variables to set when running Terraform
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
"region": awsRegion,
},
})

Expand Down