From 2315645e656add51f39eedee3727419cdc1ac308 Mon Sep 17 00:00:00 2001 From: theprashantyadav Date: Tue, 1 Aug 2023 15:12:58 +0530 Subject: [PATCH] feat: fix tflint and added vpc and subnet tag --- .github/CODEOWNERS | 2 + .github/PULL_REQUEST_TEMPLATE.md | 12 ++++ .github/workflows/auto_assignee.yml | 14 +++++ .github/workflows/changelog.yml | 2 +- .github/workflows/readme.yml | 22 ++++---- .github/workflows/terraform.yml | 85 ----------------------------- .github/workflows/terratest.yml | 51 ----------------- .github/workflows/tf-checks.yml | 20 +++++++ .github/workflows/tflint.yml | 11 ++++ .github/workflows/tfsec.yml | 2 +- README.yaml | 18 +++--- _example/basic_example/example.tf | 2 +- _example/basic_example/outputs.tf | 2 +- _example/basic_example/versions.tf | 11 ++++ _example/ebs_mount/example.tf | 2 +- _example/ebs_mount/outputs.tf | 2 +- _example/ebs_mount/versions.tf | 11 ++++ _example/spot_instance/example.tf | 4 +- _example/spot_instance/outputs.tf | 4 +- _example/spot_instance/versions.tf | 11 ++++ main.tf | 40 ++++++-------- outputs.tf | 26 ++++----- variables.tf | 51 ----------------- versions.tf | 4 +- 24 files changed, 152 insertions(+), 257 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/auto_assignee.yml delete mode 100644 .github/workflows/terraform.yml delete mode 100644 .github/workflows/terratest.yml create mode 100644 .github/workflows/tf-checks.yml create mode 100644 .github/workflows/tflint.yml create mode 100644 _example/basic_example/versions.tf create mode 100644 _example/ebs_mount/versions.tf create mode 100644 _example/spot_instance/versions.tf diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..231c9a6 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# These owners will be the default owners for everything in the repo. +* @anmolnagpal @clouddrove/approvers @clouddrove-ci diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..e414e28 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +## what +* Describe high-level what changed as a result of these commits (i.e. in plain-english, what do these changes mean?) +* Use bullet points to be concise and to the point. + +## why +* Provide the justifications for the changes (e.g. business case). +* Describe why these changes were made (e.g. why do these commits fix the problem?) +* Use bullet points to be concise and to the point. + +## references +* Link to any supporting jira issues or helpful documentation to add some context (e.g. stackoverflow). +* Use `closes #123`, if this PR closes a Jira issue `#123` diff --git a/.github/workflows/auto_assignee.yml b/.github/workflows/auto_assignee.yml new file mode 100644 index 0000000..f8b8bcd --- /dev/null +++ b/.github/workflows/auto_assignee.yml @@ -0,0 +1,14 @@ +name: Auto Assign PRs + +on: + pull_request: + types: [opened, reopened] + + workflow_dispatch: +jobs: + assignee: + uses: clouddrove/github-shared-workflows/.github/workflows/auto_assignee.yml@master + secrets: + GITHUB: ${{ secrets.GITHUB }} + with: + assignees: 'clouddrove-ci' diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 4b735f5..1ee6f78 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -10,4 +10,4 @@ jobs: uses: clouddrove/github-shared-workflows/.github/workflows/changelog.yml@master secrets: inherit with: - branch: 'master' \ No newline at end of file + branch: 'master' diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml index f2f68a1..9961649 100644 --- a/.github/workflows/readme.yml +++ b/.github/workflows/readme.yml @@ -5,15 +5,15 @@ on: - master jobs: - readme-create: + readme: name: 'readme-create' runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v2.3.4 + uses: actions/checkout@master - - name: Set up Python 3.7. - uses: actions/setup-python@v2 + - name: 'Set up Python 3.7' + uses: actions/setup-python@v4 with: python-version: '3.x' @@ -21,17 +21,17 @@ jobs: uses: 'clouddrove/github-actions@v9.0.2' with: actions_subcommand: 'readme' - github_token: '${{ secrets.GITHUB}}' + github_token: '${{ secrets.GITHUB }}' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: pre-commit check errors - uses: pre-commit/action@v2.0.0 + - name: 'pre-commit check errors' + uses: pre-commit/action@v3.0.0 continue-on-error: true - - name: pre-commit fix erros - uses: pre-commit/action@v2.0.0 + - name: 'pre-commit fix erros' + uses: pre-commit/action@v3.0.0 continue-on-error: true - name: 'push readme' @@ -40,7 +40,7 @@ jobs: with: actions_subcommand: 'push' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Slack Notification' uses: clouddrove/action-slack@v2 diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml deleted file mode 100644 index a165b95..0000000 --- a/.github/workflows/terraform.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: static-checks - -on: - pull_request: - -jobs: - versionExtract: - name: Get min/max versions - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Terraform min/max versions - id: minMax - uses: clowdhaus/terraform-min-max@main - outputs: - minVersion: ${{ steps.minMax.outputs.minVersion }} - maxVersion: ${{ steps.minMax.outputs.maxVersion }} - - - versionEvaluate: - name: Evaluate Terraform versions - runs-on: ubuntu-latest - needs: versionExtract - strategy: - fail-fast: false - matrix: - version: - - ${{ needs.versionExtract.outputs.minVersion }} - - ${{ needs.versionExtract.outputs.maxVersion }} - directory: - - _example/basic_example - - _example/ebs_mount - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Install Terraform v${{ matrix.version }} - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: ${{ matrix.version }} - - - name: 'Configure AWS Credentials' - uses: clouddrove/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }} - aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }} - aws-region: us-east-2 - - - name: Init & validate v${{ matrix.version }} - run: | - cd ${{ matrix.directory }} - terraform init - terraform validate - terraform plan -input=false -no-color - - - name: tflint - uses: reviewdog/action-tflint@master - with: - tflint_version: v0.29.0 - github_token: ${{ secrets.GITHUB }} - working_directory: ${{ matrix.directory }} - fail_on_error: 'true' - filter_mode: 'nofilter' - flags: '--module' - - format: - name: Check code format - runs-on: ubuntu-latest - needs: versionExtract - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Install Terraform v${{ needs.versionExtract.outputs.maxVersion }} - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: ${{ needs.versionExtract.outputs.maxVersion }} - - - name: Check Terraform format changes - run: terraform fmt --recursive diff --git a/.github/workflows/terratest.yml b/.github/workflows/terratest.yml deleted file mode 100644 index c4221ee..0000000 --- a/.github/workflows/terratest.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: 'Terratest GitHub Actions' -on: - pull_request: - branches: - - master - types: [labeled] - -jobs: - terraform: - name: 'Terraform' - runs-on: ubuntu-latest - steps: - - - name: 'Checkout' - uses: actions/checkout@master - - - name: Configure AWS Credentials - uses: clouddrove/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }} - aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }} - aws-region: us-east-2 - - - name: 'Terratest Basic' - if: ${{ github.event.label.name == 'terratest' }} - uses: 'clouddrove/github-actions@v9.0.2' - with: - actions_subcommand: 'terratest' - tf_actions_working_dir: '_test/basic_example' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: 'Terratest Secure' - if: ${{ github.event.label.name == 'terratest' }} - uses: 'clouddrove/github-actions@v9.0.2' - with: - actions_subcommand: 'terratest' - tf_actions_working_dir: '_test/ebs_mount' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: 'Slack Notification' - uses: clouddrove/action-slack@v2 - with: - status: ${{ job.status }} - fields: repo,author - author_name: 'CloudDrove' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required - if: always() diff --git a/.github/workflows/tf-checks.yml b/.github/workflows/tf-checks.yml new file mode 100644 index 0000000..add1f13 --- /dev/null +++ b/.github/workflows/tf-checks.yml @@ -0,0 +1,20 @@ +name: tf-checks +on: + push: + branches: [ master ] + pull_request: + workflow_dispatch: +jobs: + basic_example: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master + with: + working_directory: './_example/basic_example/' + ebs_mount: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master + with: + working_directory: './_example/ebs_mount/' + spot_instance: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master + with: + working_directory: './_example/spot_instance/' + diff --git a/.github/workflows/tflint.yml b/.github/workflows/tflint.yml new file mode 100644 index 0000000..5b8aa91 --- /dev/null +++ b/.github/workflows/tflint.yml @@ -0,0 +1,11 @@ +name: tf-lint +on: + push: + branches: [ master ] + pull_request: + workflow_dispatch: +jobs: + tflint: + uses: clouddrove/test-tfsec/.github/workflows/tflint.yaml@master + secrets: + GITHUB: ${{ secrets.GITHUB }} diff --git a/.github/workflows/tfsec.yml b/.github/workflows/tfsec.yml index 9aaf588..c203751 100644 --- a/.github/workflows/tfsec.yml +++ b/.github/workflows/tfsec.yml @@ -8,4 +8,4 @@ jobs: uses: clouddrove/github-shared-workflows/.github/workflows/tfsec.yml@master secrets: inherit with: - working_directory: '.' \ No newline at end of file + working_directory: '.' diff --git a/README.yaml b/README.yaml index c96d08f..09371bf 100644 --- a/README.yaml +++ b/README.yaml @@ -15,21 +15,17 @@ github_repo: clouddrove/terraform-aws-ec2 # Badges to display badges: - - name: "Terraform" - image: "https://img.shields.io/badge/Terraform-v1.1.7-green" - url: "https://www.terraform.io" - - name: "Licence" - image: "https://img.shields.io/badge/License-APACHE-blue.svg" - url: "LICENSE.md" + - name: "Latest Release" + image: "https://img.shields.io/github/release/clouddrove/terraform-aws-ec2.svg" + url: "https://github.com/clouddrove/terraform-aws-ec2/releases/latest" - name: "tfsec" image: "https://github.com/clouddrove/terraform-aws-ec2/actions/workflows/tfsec.yml/badge.svg" url: "https://github.com/clouddrove/terraform-aws-ec2/actions/workflows/tfsec.yml" - - name: "static-checks" - image: "https://github.com/clouddrove/terraform-aws-ec2/actions/workflows/terraform.yml/badge.svg" - url: "https://github.com/clouddrove/terraform-aws-ec2/actions/workflows/terraform.yml" + - name: "Licence" + image: "https://img.shields.io/badge/License-APACHE-blue.svg" + url: "LICENSE.md" # description of this project -# yamllint disable rule:line-length description: |- Terraform module to create an EC2 resource on AWS with ElasticC IP Addresses and Elastic Block Store. @@ -38,7 +34,7 @@ include: - "terraform.md" # How to use this project -# yamllint disable rule:line-length +# How to use this project usage: |- Here is examples of how you can use this module in your inventory structure: ### Basic Example diff --git a/_example/basic_example/example.tf b/_example/basic_example/example.tf index ed39e0b..26ce911 100644 --- a/_example/basic_example/example.tf +++ b/_example/basic_example/example.tf @@ -24,7 +24,7 @@ module "vpc" { ####---------------------------------------------------------------------------------- module "public_subnets" { source = "clouddrove/subnet/aws" - version = "1.3.0" + version = "2.0.0" name = "public-subnet" environment = "test" diff --git a/_example/basic_example/outputs.tf b/_example/basic_example/outputs.tf index abd4267..7f0dbe4 100644 --- a/_example/basic_example/outputs.tf +++ b/_example/basic_example/outputs.tf @@ -1,5 +1,5 @@ output "instance_id" { - value = module.ec2.*.instance_id + value = module.ec2[*].instance_id description = "The instance ID." } diff --git a/_example/basic_example/versions.tf b/_example/basic_example/versions.tf new file mode 100644 index 0000000..5a227cd --- /dev/null +++ b/_example/basic_example/versions.tf @@ -0,0 +1,11 @@ +# Terraform version +terraform { + required_version = ">= 1.5.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.9.0" + } + } +} \ No newline at end of file diff --git a/_example/ebs_mount/example.tf b/_example/ebs_mount/example.tf index 1bd1bc0..6fbb3f6 100644 --- a/_example/ebs_mount/example.tf +++ b/_example/ebs_mount/example.tf @@ -24,7 +24,7 @@ module "vpc" { ####---------------------------------------------------------------------------------- module "public_subnets" { source = "clouddrove/subnet/aws" - version = "1.3.0" + version = "2.0.0" name = "public-subnet" environment = "test" diff --git a/_example/ebs_mount/outputs.tf b/_example/ebs_mount/outputs.tf index 0f70b1d..0bec12f 100644 --- a/_example/ebs_mount/outputs.tf +++ b/_example/ebs_mount/outputs.tf @@ -1,5 +1,5 @@ output "instance_id" { - value = module.ec2.*.instance_id + value = module.ec2[*].instance_id description = "The instance ID." } diff --git a/_example/ebs_mount/versions.tf b/_example/ebs_mount/versions.tf new file mode 100644 index 0000000..5a227cd --- /dev/null +++ b/_example/ebs_mount/versions.tf @@ -0,0 +1,11 @@ +# Terraform version +terraform { + required_version = ">= 1.5.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.9.0" + } + } +} \ No newline at end of file diff --git a/_example/spot_instance/example.tf b/_example/spot_instance/example.tf index 3b70f3c..1d471be 100644 --- a/_example/spot_instance/example.tf +++ b/_example/spot_instance/example.tf @@ -11,7 +11,7 @@ provider "aws" { #tfsec:ignore:aws-ec2-require-vpc-flow-logs-for-all-vpcs module "vpc" { source = "clouddrove/vpc/aws" - version = "1.3.1" + version = "2.0.0" name = "vpc" environment = "test" @@ -25,7 +25,7 @@ module "vpc" { #tfsec:ignore:aws-ec2-no-public-ip-subnet module "public_subnets" { source = "clouddrove/subnet/aws" - version = "1.3.0" + version = "2.0.0" name = "public-subnet" environment = "test" diff --git a/_example/spot_instance/outputs.tf b/_example/spot_instance/outputs.tf index 9e69339..6b666d2 100644 --- a/_example/spot_instance/outputs.tf +++ b/_example/spot_instance/outputs.tf @@ -1,10 +1,10 @@ output "spot_instance_id" { - value = module.spot-ec2.*.spot_instance_id + value = module.spot-ec2[*].spot_instance_id description = "The instance ID." } output "spot_tags" { - value = module.spot-ec2.*.tags + value = module.spot-ec2[*].tags description = "The instance tags." } diff --git a/_example/spot_instance/versions.tf b/_example/spot_instance/versions.tf new file mode 100644 index 0000000..5a227cd --- /dev/null +++ b/_example/spot_instance/versions.tf @@ -0,0 +1,11 @@ +# Terraform version +terraform { + required_version = ">= 1.5.0" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.9.0" + } + } +} \ No newline at end of file diff --git a/main.tf b/main.tf index 73af6ad..939d915 100644 --- a/main.tf +++ b/main.tf @@ -55,12 +55,6 @@ resource "aws_security_group" "default" { } } -data "aws_security_group" "existing" { - count = var.is_external ? 1 : 0 - id = var.existing_sg_id - vpc_id = var.vpc_id -} - ##---------------------------------------------------------------------------------- ## Below resources will create SECURITY-GROUP-RULE and its components. ##---------------------------------------------------------------------------------- @@ -74,7 +68,7 @@ resource "aws_security_group_rule" "egress" { to_port = 65535 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] - security_group_id = join("", aws_security_group.default.*.id) + security_group_id = join("", aws_security_group.default[*].id) } #tfsec:ignore:aws-ec2-no-public-egress-sgr resource "aws_security_group_rule" "egress_ipv6" { @@ -86,7 +80,7 @@ resource "aws_security_group_rule" "egress_ipv6" { to_port = 65535 protocol = "-1" ipv6_cidr_blocks = ["::/0"] - security_group_id = join("", aws_security_group.default.*.id) + security_group_id = join("", aws_security_group.default[*].id) } #tfsec:ignore:aws-ec2-no-public-ingress-sgr resource "aws_security_group_rule" "ssh_ingress" { @@ -98,7 +92,7 @@ resource "aws_security_group_rule" "ssh_ingress" { to_port = element(var.ssh_allowed_ports, count.index) protocol = var.ssh_protocol cidr_blocks = var.ssh_allowed_ip - security_group_id = join("", aws_security_group.default.*.id) + security_group_id = join("", aws_security_group.default[*].id) } #tfsec:ignore:aws-ec2-no-public-ingress-sgr resource "aws_security_group_rule" "ingress" { @@ -110,7 +104,7 @@ resource "aws_security_group_rule" "ingress" { to_port = element(var.allowed_ports, count.index) protocol = var.protocol cidr_blocks = var.allowed_ip - security_group_id = join("", aws_security_group.default.*.id) + security_group_id = join("", aws_security_group.default[*].id) } @@ -135,7 +129,7 @@ resource "aws_kms_alias" "default" { count = var.kms_key_enabled && var.kms_key_id == "" ? 1 : 0 name = coalesce(var.alias, format("alias/%v", module.labels.id)) - target_key_id = var.kms_key_id == "" ? join("", aws_kms_key.default.*.id) : var.kms_key_id + target_key_id = var.kms_key_id == "" ? join("", aws_kms_key.default[*].id) : var.kms_key_id } data "aws_iam_policy_document" "kms" { @@ -163,9 +157,9 @@ resource "aws_instance" "default" { ami = var.ami == "" ? data.aws_ami.ubuntu.id : var.ami ebs_optimized = var.ebs_optimized instance_type = var.instance_type - key_name = join("", aws_key_pair.default.*.key_name) + key_name = join("", aws_key_pair.default[*].key_name) monitoring = var.monitoring - vpc_security_group_ids = length(var.sg_ids) < 1 ? aws_security_group.default.*.id : var.sg_ids + vpc_security_group_ids = length(var.sg_ids) < 1 ? aws_security_group.default[*].id : var.sg_ids subnet_id = element(distinct(compact(concat(var.subnet_ids))), count.index) associate_public_ip_address = var.associate_public_ip_address disable_api_termination = var.disable_api_termination @@ -175,7 +169,7 @@ resource "aws_instance" "default" { host_id = var.host_id cpu_core_count = var.cpu_core_count user_data = var.user_data - iam_instance_profile = join("", aws_iam_instance_profile.default.*.name) + iam_instance_profile = join("", aws_iam_instance_profile.default[*].name) source_dest_check = var.source_dest_check ipv6_address_count = var.ipv6_address_count ipv6_addresses = var.ipv6_addresses @@ -252,7 +246,7 @@ resource "aws_instance" "default" { resource "aws_eip" "default" { count = var.instance_enabled == true && var.assign_eip_address == true ? var.instance_count : 0 - network_interface = element(aws_instance.default.*.primary_network_interface_id, count.index) + network_interface = element(aws_instance.default[*].primary_network_interface_id, count.index) vpc = true tags = merge( @@ -269,13 +263,13 @@ resource "aws_eip" "default" { resource "aws_ebs_volume" "default" { count = var.instance_enabled == true && var.ebs_volume_enabled == true ? var.instance_count : 0 - availability_zone = element(aws_instance.default.*.availability_zone, count.index) + availability_zone = element(aws_instance.default[*].availability_zone, count.index) size = var.ebs_volume_size iops = local.ebs_iops type = var.ebs_volume_type multi_attach_enabled = var.multi_attach_enabled encrypted = true - kms_key_id = var.kms_key_id == "" ? join("", aws_kms_key.default.*.arn) : var.kms_key_id + kms_key_id = var.kms_key_id == "" ? join("", aws_kms_key.default[*].arn) : var.kms_key_id tags = merge(module.labels.tags, { "Name" = format("%s-ebs-volume%s%s", module.labels.id, var.delimiter, (count.index)) }, @@ -290,8 +284,8 @@ resource "aws_volume_attachment" "default" { count = var.instance_enabled == true && var.ebs_volume_enabled == true ? var.instance_count : 0 device_name = element(var.ebs_device_name, count.index) - volume_id = element(aws_ebs_volume.default.*.id, count.index) - instance_id = element(aws_instance.default.*.id, count.index) + volume_id = element(aws_ebs_volume.default[*].id, count.index) + instance_id = element(aws_instance.default[*].id, count.index) } ##---------------------------------------------------------------------------------- @@ -312,7 +306,7 @@ resource "aws_route53_record" "default" { name = format("%s%s%s", var.hostname, var.delimiter, (count.index)) type = var.type ttl = var.ttl - records = [element(aws_instance.default.*.private_dns, count.index)] + records = [element(aws_instance.default[*].private_dns, count.index)] } ##---------------------------------------------------------------------------------- @@ -333,9 +327,9 @@ resource "aws_spot_instance_request" "default" { ami = var.ami == "" ? data.aws_ami.ubuntu.id : var.ami ebs_optimized = var.ebs_optimized instance_type = var.instance_type - key_name = join("", aws_key_pair.default.*.key_name) + key_name = join("", aws_key_pair.default[*].key_name) monitoring = var.monitoring - vpc_security_group_ids = length(var.sg_ids) < 1 ? aws_security_group.default.*.id : var.sg_ids + vpc_security_group_ids = length(var.sg_ids) < 1 ? aws_security_group.default[*].id : var.sg_ids subnet_id = element(distinct(compact(concat(var.subnet_ids))), count.index) associate_public_ip_address = var.associate_public_ip_address disable_api_termination = var.disable_api_termination @@ -345,7 +339,7 @@ resource "aws_spot_instance_request" "default" { host_id = var.host_id cpu_core_count = var.cpu_core_count user_data = var.user_data - iam_instance_profile = join("", aws_iam_instance_profile.default.*.name) + iam_instance_profile = join("", aws_iam_instance_profile.default[*].name) source_dest_check = var.source_dest_check ipv6_address_count = var.ipv6_address_count ipv6_addresses = var.ipv6_addresses diff --git a/outputs.tf b/outputs.tf index d47c4b3..5d0e1cb 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,55 +1,55 @@ #Module : EC2 #Description : Terraform module to create an EC2 resource on AWS with Elastic IP Addresses # and Elastic Block Store. output "instance_id" { - value = aws_instance.default.*.id + value = aws_instance.default[*].id description = "The instance ID." } output "arn" { - value = aws_instance.default.*.arn + value = aws_instance.default[*].arn description = "The ARN of the instance." } output "az" { - value = aws_instance.default.*.availability_zone + value = aws_instance.default[*].availability_zone description = "The availability zone of the instance." } output "public_ip" { - value = concat(aws_eip.default.*.public_ip, aws_instance.default.*.public_ip, [""]) + value = concat(aws_eip.default[*].public_ip, aws_instance.default[*].public_ip, [""]) description = "Public IP of instance (or EIP)." } output "private_ip" { - value = aws_instance.default.*.private_ip + value = aws_instance.default[*].private_ip description = "Private IP of instance." } output "placement_group" { - value = join("", aws_instance.default.*.placement_group) + value = join("", aws_instance.default[*].placement_group) description = "The placement group of the instance." } output "key_name" { - value = join("", aws_instance.default.*.key_name) + value = join("", aws_instance.default[*].key_name) description = "The key name of the instance." } output "ipv6_addresses" { - value = aws_instance.default.*.ipv6_addresses + value = aws_instance.default[*].ipv6_addresses sensitive = true description = "A list of assigned IPv6 addresses." } output "vpc_security_group_ids" { - value = aws_instance.default.*.vpc_security_group_ids + value = aws_instance.default[*].vpc_security_group_ids sensitive = true description = "The associated security groups in non-default VPC." } output "subnet_id" { - value = aws_instance.default.*.subnet_id + value = aws_instance.default[*].subnet_id sensitive = true description = "The EC2 subnet ID." } @@ -59,18 +59,18 @@ output "instance_count" { description = "The count of instances." } output "name" { - value = join("", aws_key_pair.default.*.key_name) + value = join("", aws_key_pair.default[*].key_name) description = "Name of SSH key." } output "spot_instance_id" { - value = aws_spot_instance_request.default.*.spot_instance_id + value = aws_spot_instance_request.default[*].spot_instance_id description = "The instance ID." } output "spot_bid_status" { description = "The current bid status of the Spot Instance Request" - value = join("", aws_spot_instance_request.default.*.spot_bid_status) + value = join("", aws_spot_instance_request.default[*].spot_bid_status) } output "tags" { value = module.labels.tags diff --git a/variables.tf b/variables.tf index 24f0008..de65980 100644 --- a/variables.tf +++ b/variables.tf @@ -30,12 +30,6 @@ variable "label_order" { description = "Label order, e.g. `name`,`application`." } -variable "attributes" { - type = list(any) - default = [] - description = "Additional attributes (e.g. `1`)." -} - variable "delimiter" { type = string default = "-" @@ -73,32 +67,12 @@ variable "instance_type" { description = "The type of instance to start. Updates to this field will trigger a stop/start of the EC2 instance." } -variable "key_name" { - type = string - default = "" - description = "The key name to use for the instance." -} - variable "monitoring" { type = bool default = false description = "If true, the launched EC2 instance will have detailed monitoring enabled. (Available since v0.6.0)." } -variable "vpc_security_group_ids_list" { - type = list(string) - default = [] - description = "A list of security group IDs to associate with." - sensitive = true -} - -variable "subnet" { - type = string - default = null - description = "VPC Subnet ID the instance is launched in." - sensitive = true -} - variable "associate_public_ip_address" { type = bool default = true @@ -106,12 +80,6 @@ variable "associate_public_ip_address" { sensitive = true } -variable "ebs_block_device" { - type = list(any) - default = [] - description = "Additional EBS block devices to attach to the instance." -} - variable "ephemeral_block_device" { type = list(any) default = [] @@ -166,13 +134,6 @@ variable "ebs_iops" { description = "Amount of provisioned IOPS. This must be set with a volume_type of io1." } -variable "availability_zone" { - type = list(any) - default = [] - description = "Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region." - sensitive = true -} - variable "ebs_device_name" { type = list(string) default = ["/dev/xvdb", "/dev/xvdc", "/dev/xvdd", "/dev/xvde", "/dev/xvdf", "/dev/xvdg", "/dev/xvdh", "/dev/xvdi", "/dev/xvdj", "/dev/xvdk", "/dev/xvdl", "/dev/xvdm", "/dev/xvdn", "/dev/xvdo", "/dev/xvdp", "/dev/xvdq", "/dev/xvdr", "/dev/xvds", "/dev/xvdt", "/dev/xvdu", "/dev/xvdv", "/dev/xvdw", "/dev/xvdx", "/dev/xvdy", "/dev/xvdz"] @@ -436,12 +397,6 @@ variable "enable_security_group" { description = "Enable default Security Group with only Egress traffic allowed." } -variable "existing_sg_id" { - type = string - default = null - description = "Provide existing security group id for updating existing rule" -} - variable "egress_rule" { type = bool default = true @@ -535,12 +490,6 @@ variable "spot_instance_enabled" { description = "Flag to control the instance creation." } -variable "spot_ami" { - type = string - default = "" - description = "The AMI to use for the instance." -} - variable "spot_instance_count" { type = number default = 0 diff --git a/versions.tf b/versions.tf index 9317499..5a227cd 100644 --- a/versions.tf +++ b/versions.tf @@ -1,11 +1,11 @@ # Terraform version terraform { - required_version = ">= 1.4.6" + required_version = ">= 1.5.0" required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.1.0" + version = ">= 5.9.0" } } } \ No newline at end of file