This Terraform project is designed to test the input and output handling of AWS Service Catalog, which now offers Terraform support. The purpose is to ensure the correct handling of various Terraform data types in variables and outputs when used with AWS Service Catalog.
-
Product name: terraform-aws-sc-dummy-item
-
Product description (optional): A Terraform Service Catalog item for testing AWS Service Catalog integration with support for various complex input and output data types.
-
Version name (optional): v1.0.0
-
Owner: ACME Cloud Engineering
-
Distributor (optional): ACME Cloud Engineering
Terraform supports several data types for variables and outputs, which include:
string
: Represents a sequence of characters.number
: Represents numeric values, including integers and floating-point numbers.bool
: Represents a boolean value, eithertrue
orfalse
.list(<TYPE>)
ortuple([<TYPE>, ...])
: Represents a sequence of values of the specified type(s).set(<TYPE>)
: Represents an unordered collection of unique values of the specified type.map(<TYPE>)
orobject({key = <TYPE>, ...})
: Represents a collection of key-value pairs, where keys are strings, and values are of the specified type(s).any
: Represents a value of any type.
Terraform allows you to add validation rules to your input variables using the validation
block. This helps to ensure that the values passed to your modules meet specific criteria before they are used in the configuration. You can define custom error messages to provide better feedback when incorrect values are provided.
Example of a validation block:
variable "instance_type" {
type = string
description = "EC2 instance type"
validation {
condition = contains(["t2.micro", "t2.small", "t2.medium"], var.instance_type)
error_message = "The instance_type must be one of: t2.micro, t2.small, t2.medium."
}
}
In this example, the condition checks whether the provided instance_type is one of the allowed types. If not, it will display the custom error_message.
terraform-aws-sc-dummy-item/
├── main.tf
├── providers.tf
├── versions.tf
└── modules/
└── main_module/
├── main.tf
├── variables.tf
└── outputs.tf
This project structure includes a top-level directory with the main Terraform configuration files, and a main_module
within the modules
directory. The main_module
is responsible for retrieving specified environment variables and outputting their values as a map.
For more information on Terraform data types, variables, and validation, refer to the Terraform documentation:
This is a reference output of the variables and outputs defined in the catalog item, with the included tfvars file.
Variable Name | Value | Description | Default Value | Source |
---|---|---|---|---|
simple_string | Test string | A simple string variable without validation and without default value | - | tfvars |
validated_string | Validated string | A string variable with length validation (larger than 5) and no default value | - | tfvars |
default_string | Hello, World! | A string variable with a default value and no validation | Hello, World! | default value |
simple_number | 10 | A simple number variable without validation and without default value | - | tfvars |
validated_number | 25 | A number variable with range validation (1-100) and no default value | - | tfvars |
default_number | 42 | A number variable with a default value and no validation | 42 | default value |
complex_list | ['apple', '2', 'banana', '4'] | A complex list variable containing strings and numbers, with a default value | ['apple', 2, 'banana', 4] | default value |
complex_object | {'field1': 'default_string', 'field2': ['item1', '2', 'item3'], 'field3': {'key1': 'value1', 'key2': 'value2'}} | A complex object variable with nested lists and maps, and a default value | { field1 = "default_string" field2 = ["item1", 2, "item3"] field3 = { key1 = "value1" key2 = "value2" } } |
default value |
without the values provided by the tfvars file. Here's an updated table that reflects this, here we enter the required variables manually.:
Key | Value | Description | Source |
---|---|---|---|
complex_list | ['apple', '2', 'banana', '4'] | A complex list variable containing strings and numbers, with a default value | variables.tf |
complex_object | {'field1': 'default_string', 'field2': ['item1', '2', 'item3'], 'field3': {'key1': 'value1', 'key2': 'value2'}} | A complex object variable with nested lists and maps, and a default value | variables.tf |
default_number | 42 | A number variable with a default value and no validation | variables.tf |
default_string | Hello, World! | A string variable with a default value and no validation | variables.tf |
environment_variables | (sensitive value) | A sensitive string variable that should be populated with a value from an environment variable | variables.tf |
example_variables_sensitive | (sensitive value) | An example of a sensitive string variable | manual |
null_resource_id | 1938533224326765545 | An ID generated by the null_resource | variables.tf |
ResourceGroupARN | arn:aws:resource-groups:eu-north-1:365853257337:group/SC-365853257337-pp-cwsc5kuvszhfg | The ARN of the associated Resource Group | variables.tf |
simple_number | 70 | A simple number variable without validation and without default value | manual |
simple_string | This is a test string | A simple string variable without validation and without default value | manual |
validated_number | 50 | A number variable with range validation (1-100) and no default value | manual |
validated_string | dsfsdfsdfsdf | A string variable with length validation (larger than 5) and no default value | manual |
This module comes with a Makefile to help automate various tasks.
You can exclude the .tfvars file using EXCLUDE_TFVARS=true
when running the make
command for the package
and validate-package
targets.
fmt
: Formats all Terraform files in the project.validate
: Validates the Terraform module usingterraform fmt
andterraform validate
.package
: Packages the contents of the module into a.tar.gz
file, excluding unnecessary files as specified in the.gitignore
file.validate-package
: Extracts the contents of the.tar.gz
file and compares the structure and contents with the original module.clean
: Deletes the packaged archive.
Name | Version |
---|---|
terraform | >= 1.0.0 |
env | 0.0.2 |
null | ~> 3.0 |
No providers.
Name | Source | Version |
---|---|---|
main_module | ./modules/main_module | n/a |
No resources.
Name | Description | Type | Default | Required |
---|---|---|---|---|
complex_list | A complex list variable containing strings and numbers, with a default value | list(any) |
[ |
no |
complex_object | A complex object variable with nested lists and maps, and a default value | object({ |
{ |
no |
default_number | A number variable with a default value and no validation | number |
42 |
no |
default_string | A string variable with a default value and no validation | string |
"Hello, World!" |
no |
env_var_names | A map of environment variable names to retrieve their values | map(string) |
{} |
no |
simple_number | A simple number variable without validation and without default value | number |
n/a | yes |
simple_string | A simple string variable without validation and without default value | string |
n/a | yes |
validated_number | A number variable with range validation (1-100) and no default value | number |
n/a | yes |
validated_string | A string variable with length validation (larger than 5) and no default value | string |
n/a | yes |
Name | Description |
---|---|
complex_list | The value of the complex_list variable |
complex_object | The value of the complex_object variable |
default_number | The value of the default_number variable |
default_string | The value of the default_string variable |
environment_variables | Non-sensitive environment variables of the machine running Terraform |
example_variables_sensitive | Environment variables of the machine running Terraform |
null_resource_id | value of the null_resource_id output |
simple_number | The value of the simple_number variable |
simple_string | The value of the simple_string variable |
validated_number | The value of the validated_number variable |
validated_string | The value of the validated_string variable |