Terraform 모듈에서 사용되지 않는 변수와 로컬 및 데이터 소스를 보고하며 이를 제거하는 빠른 수정을 제공합니다.

문제 예:


data "aws_ami" "latest_amazon_linux" {
  most_recent = true

  filter {
    name   = "name"
    values = ["amzn2-ami-hvm-*-x86_64-gp2"]
  }

  owners = ["amazon"]
}

data "aws_vpc" "unused_data_source" {
  default = true
}

resource "aws_instance" "example" {
  ami           = data.aws_ami.latest_amazon_linux.id
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleInstance"
  }
}

variable "used_variable" {
  description = "This variable is used in resource configuration"
  type        = string
  default     = "ami-01456a894f71116f2"
}

locals {
  instance_name = "used-instance"
}

resource "aws_instance" "example1" {
  ami           = var.used_variable
  instance_type = "t2.micro"

  tags = {
    Name = local.instance_name
  }
}

variable "unused_variable1" {
  description = "This variable is not used anywhere in the configuration"
  type        = string
  default     = "default_value1"
}

locals {
  unused_local1 = "This is an unused local value"
}

이 예시에서 unused_data_source, unused_variable1unused_local1은 파일에서 선언되지만 어디에도 사용되지 않습니다.

빠른 수정을 적용한 후:


data "aws_ami" "latest_amazon_linux" {
  most_recent = true

  filter {
    name   = "name"
    values = ["amzn2-ami-hvm-*-x86_64-gp2"]
  }

  owners = ["amazon"]
}

resource "aws_instance" "example" {
  ami           = data.aws_ami.latest_amazon_linux.id
  instance_type = "t2.micro"

  tags = {
    Name = "ExampleInstance"
  }
}

variable "used_variable" {
  description = "This variable is used in resource configuration"
  type        = string
  default     = "ami-01456a894f71116f2"
}

locals {
  instance_name = "used-instance"
}

resource "aws_instance" "example1" {
  ami           = var.used_variable
  instance_type = "t2.micro"

  tags = {
    Name = local.instance_name
  }
}

locals {
}