Search code examples
visual-studio-codeideterraform

Terraform - Auto-populate required attributes in IDE


I took a class recently with the exceptional Yevgeniy Brikman, and as he created Terraform resources, his IDE auto-populated required attributes. For instance, if he typed:

resource "aws_lambda_function" "lambda_example" {

His IDE would auto-populate:

resource "aws_lambda_function" "lambda_example" {
  function_name = ""
  handler       = ""
  runtime       = ""
  role          = ""
}

Now that I'm writing Terraform code frequently this feature would be handy, but I can't find a way to configure my IDE to do this (Visual Studio Code). I'm up for switching IDEs - how does one get this functionality?


Solution

  • Hashicorp (the company behind Terraform) publish a plugin for IntelliJ IDEA that has a lot of spiffy functionality.

    This picture is a result of me defining an empty lambda, then pressing Alt-Enter: empty resource with popup

    Selecting that first entry populates the mandatory properties as you showed. Then after that, I put my cursor inside the resource and press Ctrl-Space, to have IDEA show code completion options for all the other optional properties: populated resource with popup

    I'm a keyboard user, so that's what I know to do. I'm sure you can do all sorts of mousery if that's what floats your boat.

    I use the commercial version of IDEA, but there is a free community version and I assume the Hashicorp plugin would work with that.