Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local variables autocomplete not working within inline block #600

Closed
softveda opened this issue Aug 2, 2021 · 3 comments · Fixed by #607
Closed

local variables autocomplete not working within inline block #600

softveda opened this issue Aug 2, 2021 · 3 comments · Fixed by #607
Labels
bug Something isn't working

Comments

@softveda
Copy link

softveda commented Aug 2, 2021

Extension Version: v2.14.0
Terraform version:
Terraform v1.0.2
on darwin_amd64

  • provider registry.terraform.io/hashicorp/aws v3.52.0
  • provider registry.terraform.io/hashicorp/template v2.2.0

Code in Module, main.tf

provider "aws" {
  region = "ap-southeast-2"
}

locals {
  http_port     = 80
  any_port      = 0
  any_protocol  = "-1"
  tcp_protocol  = "tcp"
  http_protocol = "HTTP"
  all_ips       = ["0.0.0.0/0"]
}

The auto complete for local variables didn't work inside the ingress and egress inline blocks.

resource "aws_security_group" "alb" {
  name = "terraform-example-alb"

  ingress {
    description = "Allow HTTP inbound"
    cidr_blocks = local.all_ips
    from_port   = local.http_port
    to_port     = local.http_port
    protocol    = local.tcp_protocol
  }

  egress {
    description = "Allow All outbound"
    cidr_blocks = local.all_ips
    from_port   = local.any_port
    to_port     = local.any_port
    protocol    = local.any_protocol
  }
}

Screen Shot 2021-08-02 at 8 49 41 pm

Autocomplete works here though. Also notice how the keyword "local" has different colour between the two places.

resource "aws_lb_target_group" "asg" {
  name     = "terraform-asg-example"
  port     = var.server_port
  protocol = local.http_protocol
  vpc_id   = data.aws_vpc.default.id

  health_check {
    path                = "/"
    protocol            = local.http_protocol
    matcher             = "200"
    interval            = 15
    timeout             = 3
    healthy_threshold   = 2
    unhealthy_threshold = 2
  }
}

Screen Shot 2021-08-02 at 8 54 17 pm

@radeksimko radeksimko transferred this issue from hashicorp/vscode-terraform Aug 2, 2021
@radeksimko
Copy link
Member

Reproduced, thank you for the report.

I have transferred this over to the language server repository as LS is responsible for parsing the configuration.

From a brief investigation I can tell that aws_security_group uses a special "compatibility mode" for the ingress and egress blocks, which effectively makes them available as attributes. There are other differences, but to put it simply attributes have the = (equal sign) after the name, blocks do not.

The extension & language server should understand any valid configuration so this is certainly a bug.

I am talking to the SDK team internally to first understand how exactly should the compatibility mode work and which one is the preferred representation of the config.

In the meantime though you may be able to work around this by adding = after ingress and egress.

@radeksimko
Copy link
Member

radeksimko commented Aug 3, 2021

It is my understanding that attributes (i.e. ingress = [{ ... }] and egress = [{ ... }]) is the preferred way of expressing these fields, which is also why I proposed some changes to the relevant docs: hashicorp/terraform-provider-aws#20428

#607 will make it possible for the language server to recognize these fields as blocks too, but it will prefer completion of attributes if you trigger it within the resource body.

@github-actions
Copy link

github-actions bot commented Sep 3, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants