diff --git a/modules/terraform-setup/README.md b/modules/terraform-setup/README.md index 361b2f0..626886b 100644 --- a/modules/terraform-setup/README.md +++ b/modules/terraform-setup/README.md @@ -3,4 +3,7 @@ Module for creating terraform state bucket and locks. The output ```provider-config-block``` shows how to configure terraform provider. -Please enable terraform default tags. See https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider \ No newline at end of file +Please enable terraform default tags. See https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider + +## Examples +See examples in the examples directory. diff --git a/modules/terraform-setup/examples/.terraform.lock.hcl b/modules/terraform-setup/examples/.terraform.lock.hcl new file mode 100644 index 0000000..8953a5b --- /dev/null +++ b/modules/terraform-setup/examples/.terraform.lock.hcl @@ -0,0 +1,10 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "4.26.0" + constraints = ">= 3.25.0" + hashes = [ + "h1:jt8jLpFFhaapdbBqw4WQpDuLN8y7zF8/iLyCzypDxSQ=", + ] +} diff --git a/modules/terraform-setup/examples/main.tf b/modules/terraform-setup/examples/main.tf new file mode 100644 index 0000000..7c2e800 --- /dev/null +++ b/modules/terraform-setup/examples/main.tf @@ -0,0 +1,44 @@ +variable "aws-region" {} +variable "aws-region-short" {} +variable "customer-name" {} +variable "project" {} +variable "application" {} +variable "environment" {} + +provider "aws" { + region = var.aws-region + default_tags { + tags = { + Environment = var.environment + Project = var.project + Application = var.application + TerraformMode = "managed" + TerraformDir = path.cwd + BuildDate = formatdate("YYYYMMDD", timestamp()) + } + } +} + +terraform { + required_version = ">= 0.14" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 3.25" + } + } +} + +locals { + resource-prefix = "${var.environment}-${var.aws-region-short}-${var.customer-name}-${var.project}" +} + +module "terraform-state-store" { + source = "git::https://xpk.headdesk.me/git/xpk/terraform.aws-baseline-infra//modules/terraform-setup" + enable-bucket-versioning = true + transition-ia-days = 30 + bucket-acl = "private" + resource-prefix = local.resource-prefix + ddb-table-name = "${local.resource-prefix}-tflock" + bucket-name = "${local.resource-prefix}-tfstate" +} \ No newline at end of file diff --git a/modules/terraform-setup/variables.tf b/modules/terraform-setup/variables.tf index 2bdaa07..eb2070e 100644 --- a/modules/terraform-setup/variables.tf +++ b/modules/terraform-setup/variables.tf @@ -1,6 +1,4 @@ -variable resource-prefix {} -variable ddb-table-name {} - +variable "ddb-table-name" {} variable "transition-ia-days" {} variable "bucket-retain-days" { default = 0 @@ -8,12 +6,11 @@ variable "bucket-retain-days" { variable "bucket-enable-lifecycle" { default = true } - variable "bucket-acl" { default = "private" } variable "enable-bucket-versioning" { default = true } - variable "bucket-name" {} +variable "resource-prefix" {} \ No newline at end of file