Skip to content

mulecode/tool-set-terraform-mod

Repository files navigation

tool-set-terraform-mod

This repository houses Docker images equipped with tool-set-terraform-mod, designed to be versatile across different pipeline solutions. These images adhere to the 3musketeers pattern, ensuring compatibility and promoting a standardized approach to tool usage.

Why use docker for pipelines?

Using Docker in pipelines streamlines software development and deployment by encapsulating applications and dependencies in containers, ensuring consistent environments throughout the development lifecycle. This eliminates the "it works on my machine" problem and fosters collaboration across teams.

Docker's lightweight design enables efficient resource utilization, facilitating scalable applications. The isolation in containers minimizes tool conflicts in the pipeline, enhancing stability. Moreover, Docker's compatibility with popular CI/CD platforms simplifies integration, offering faster deployment, simplified dependency management, and improved collaboration.

Overall, Docker enables organizations to create secure, standardized environments, accelerating time-to-market for software products and features.

Benefits of adhering to the 3musketeers pattern

  1. Consistency Across Environments: The pattern encourages a consistent approach to defining and running commands, promoting uniformity across development, testing, and production environments. This consistency helps mitigate issues related to environment-specific discrepancies.
  2. Simplified Dependency Management: By encapsulating tool commands within Docker containers, the organization can manage dependencies more effectively. This simplification reduces the likelihood of conflicts and ensures that each tool operates in an isolated, well-defined environment.
  3. Reproducibility in Workflows: The pattern facilitates reproducibility in workflows by encapsulating tool configurations and dependencies. This ensures that the same set of tools and versions are utilized throughout the development lifecycle, enhancing predictability in software development.
  4. Ease of Collaboration: Adopting the 3musketeers pattern promotes ease of collaboration among development teams. The standardized approach to tooling and containerization makes it straightforward for team members to share and collaborate on projects without the complexities associated with varied development setups.
  5. Scalability and Flexibility: The pattern's containerized approach enhances scalability and flexibility in handling different tools and their versions. This adaptability is particularly valuable in dynamic development environments, allowing teams to scale projects efficiently.
  6. Enhanced Security: By encapsulating tools within Docker containers, security can be improved. Containers provide isolation, reducing the risk of conflicts between tools and enhancing the overall security posture of the development and deployment process.
  7. Efficient CI/CD Integration: The pattern aligns well with continuous integration and continuous deployment (CI/CD) practices. Docker containers with encapsulated tools can be seamlessly integrated into CI/CD pipelines, ensuring a smooth and reliable automation process.
  8. Standardized Development Practices: Standardizing on the 3musketeers pattern establishes a common set of practices within the organization. This shared approach helps in onboarding new team members more efficiently and reduces the learning curve associated with diverse development setups.

How to use this image

In the root of your project create a docker-compose.yml file with the following content:

services:
  terraform:
    image: ghcr.io/mulecode/tool-set-terraform-mod:1.7.0
    working_dir: /opt/app
    volumes:
      - .:/opt/app
    environment:
      - ENV
      - ROOT_DIR=/opt/app
      - TERRAFORM_DIR=/modules/terraform
      - AWS_REGION
      - AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN

by the given environment variables above, you must have your terraform configuration in the following structure:

/modules
   /terraform
      /config
         /${ENV}
            remote.tfvars
            main.tfvars
            ...

and a makefile with the following content:

COMPOSE_RUN_TERRAFORM = docker compose run --no-deps --rm terraform

.PHONY: version
version:
  $(COMPOSE_RUN_TERRAFORM) version

.PHONY: test
test: prepare
  $(COMPOSE_RUN_TERRAFORM) test

.PHONY: lint
lint:
  $(COMPOSE_RUN_TERRAFORM) lint

.PHONY: deploy
deploy: prepare
  $(COMPOSE_RUN_TERRAFORM) deploy

.PHONY: destroy
destroy:
  $(COMPOSE_RUN_TERRAFORM) destroy

Check for more patterns at 3musketeers

Requirements

Name Version
terraform ~> 1.11.4
aws ~> 5.94.1

Providers

Name Version
aws ~> 5.94.1

Modules

Name Source Version
aws_aim_policy ./modules/iam-policy n/a
aws_aim_role ./modules/iam-role n/a
aws_api_gateway_rest ./modules/api-gateway-rest n/a
aws_dynamodb_table ./modules/dynamo-db n/a
bucket ./modules/bucket n/a
bucket_policy ./modules/bucket-policy n/a
cloudfront ./modules/cloudfront n/a
cognito ./modules/cognito n/a
lambda ./modules/lambda-function n/a

Resources

Name Type
aws_s3_object.upload_files2 resource

Inputs

Name Description Type Default Required
account_id AWS account ID string n/a yes
aws_api_gateways AWS API Gateways configurations
map(object({
description = string
disable_execute_api_endpoint = optional(bool, false)
api_body = string
api_body_params = optional(map(string), {})
custom_domain = optional(any)
quotas = optional(map(object({
enable_api_key = bool
quota_limit = optional(number, 500)
quota_offset = optional(number, 2)
quota_period = optional(string, "WEEK")
throttle_burst_limit = optional(number, 10)
throttle_rate_limit = optional(number, 20)
})), null)
}))
{} no
aws_cloudfront_distributions AWS CloudFront distributions configurations
map(object({
description = string
default_root_object = optional(string, "index.html")
origins = optional(map(object({
connection_attempts = optional(number)
connection_timeout = optional(number)
domain_name = string
origin_path = optional(string)
origin_access_control_id_as_oai = optional(bool, false)
origin_access_control_id_as_oac = optional(bool, false)
s3_origin_config = optional(bool, false)
custom_origin_config = optional(object({
http_port = optional(number, 80)
https_port = optional(number, 443)
origin_keepalive_timeout = optional(number, 5)
origin_protocol_policy = optional(string, "http-only")
origin_read_timeout = optional(number, 30)
origin_ssl_protocols = optional(list(string), [
"SSLv3",
"TLSv1",
"TLSv1.1",
"TLSv1.2",
])
}))
})), {})
viewer_certificate = optional(object({
cloudfront_default_certificate = optional(bool, true)
acm_certificate_arn = optional(string, null)
ssl_support_method = optional(string, "sni-only")
minimum_protocol_version = optional(string, "TLSv1.2_2019")
}), null)
default_cache_behavior = object({
allowed_methods = optional(list(string), [
"DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"
])
cached_methods = optional(list(string), [
"HEAD", "GET"
])
target_origin_id = string
viewer_protocol_policy = optional(string, "redirect-to-https")
min_ttl = optional(number, 0) # 0 seconds
default_ttl = optional(number, 3600) # 1 hour
max_ttl = optional(number, 86400) # 24 hours
cache_policy_id = string
origin_request_policy_id = optional(string, null)
})
origin_access_controls = optional(map(object({
description = string
signing_behavior = optional(string, "always")
signing_protocol = optional(string, "sigv4")
origin_access_control_origin_type = optional(string, "s3")
})), {})
custom_error_responses = optional(map(object({
error_code = number
response_page_path = string
response_code = number
error_caching_min_ttl = string
})), {})
ordered_cache_behaviors = optional(map(object({
path_pattern = optional(string, "/api/*")
allowed_methods = optional(list(string), ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"])
cached_methods = optional(list(string), ["HEAD", "GET"])
viewer_protocol_policy = optional(string, "redirect-to-https")
cache_policy_id = optional(string, null)
origin_request_policy_id = optional(string, null)
min_ttl = optional(number, 0)
default_ttl = optional(number, 3600)
max_ttl = optional(number, 86400)
forwarded_values = optional(object({
query_string = optional(bool, false)
headers = optional(list(string), null)
cookies = optional(object({
forward = optional(string, "none")
}), null)
}), null)
})), {})
cache_policies = optional(map(object({
name = string
min_ttl = optional(number, 0)
max_ttl = optional(number, 31536000)
default_ttl = optional(number, 86400)
comment = optional(string, "Cache policy for cloudfront")
cookies_config = object({
cookie_behavior = optional(string, "none")
cookies = optional(list(string), null)
})
headers_config = object({
header_behavior = optional(string, "none")
headers = optional(list(string), null)
})
query_strings_config = object({
query_strings_behavior = optional(string, "none")
query_strings = optional(list(string), null)
})
})), {})
origin_request_policies = optional(map(object({
name = string
comment = optional(string, "Origin Request policies")
cookies_config = object({
cookie_behavior = optional(string, "none")
cookies = optional(list(string), null)
})
headers_config = object({
header_behavior = optional(string, "none")
headers = optional(list(string), null)
})
query_strings_config = object({
query_strings_behavior = optional(string, "none")
query_strings = optional(list(string), null)
})
})), {})
tags = optional(map(string), {})
}))
{} no
aws_cognito_configs AWS Cognito configurations
map(object({
description = string
admin_create_user_config = optional(object({
allow_admin_create_user_only = bool
}), null)
custom_ui = optional(object({
css = string
logo = string
}), null)
callback_urls = optional(list(string), [])
generate_client_secret = optional(bool, false)
allowed_oauth_flows_user_pool_client = optional(bool, false)
allowed_oauth_flows = optional(list(string), [])
allowed_oauth_scopes = optional(list(string), [])
cognito_domain = optional(object({
domain = string
}), null)
custom_domain = optional(object({
domain = string
zone_id = string
certificate_arn = string
}), null)
resource_server = optional(object({
identifier = string
name = string
scopes = list(object({
description = string
scope_name = string
}))
}), null)
schemas = optional(map(object({
attribute_data_type = string
developer_only_attribute = optional(bool, false)
mutable = optional(bool, false)
required = optional(bool, false)
string_attribute_constraints = optional(object({
max_length = optional(number, 0)
min_length = optional(number, 0)
}), null)
})), {})
tags = optional(map(string), {})
}))
{} no
aws_dynamodb_tables AWS DynamoDB tables configurations
map(object({
billing_mode = string
hash_key = string
range_key = string
read_capacity = optional(number, null)
write_capacity = optional(number, null)
stream_enabled = optional(bool, false)
stream_view_type = optional(string, null)
tags = optional(map(string), {})
attribute = list(object({
name = string
type = string
}))
global_secondary_index = optional(set(object({
hash_key = string
name = string
non_key_attributes = optional(list(string), null)
projection_type = string
range_key = optional(string, null)
read_capacity = optional(number, null)
write_capacity = optional(number, null)
})), [])
local_secondary_index = optional(set(object({
name = string
non_key_attributes = list(string)
projection_type = string
range_key = string
})), [])
timeouts = optional(set(object({
create = string
delete = string
update = string
})), [])
ttl = optional(set(object({
attribute_name = string
enabled = bool
})), [])
}))
{} no
aws_iam_policies AWS IAM policies configurations
map(object({
description = string
policy = string
policy_vars = optional(map(string), {})
}))
{} no
aws_iam_roles AWS IAM Roles configurations
map(object({
description = string
assume_role_policy = string
aim_attachment_role_policies = list(string)
}))
{} no
aws_lambda_functions AWS Lambda functions configurations
map(object({
description = string
handler = string
runtime = optional(string, "python3.9")
artefact_path = string
role_arn = string
environment_variables = optional(map(string), {})
permissions = optional(list(any), [])
layers = optional(list(string), [])
}))
{} no
aws_s3_bucket_policies AWS S3 bucket policy configurations
map(object({
policy = string
policy_vars = optional(map(string), {})
}))
{} no
aws_s3_buckets AWS S3 bucket configurations
map(object({
acl = optional(string, "private")
versioning = optional(string, "Disabled")
tags = optional(map(string), {})
}))
{} no
aws_s3_buckets_put_files AWS S3 bucket put files configurations
map(object({
folder_path = string
tags = optional(map(string), {})
}))
{} no
project_prefix Project prefix - prefix for all resources string n/a yes
region AWS Region value string n/a yes

Outputs

No outputs.

About

Tool set for terraform modules

Topics

Resources

License

Stars

Watchers

Forks

Packages