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_variable1、および unused_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 {
}