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

Visual Studio Code Dev Container support ? #1524

Closed
1 task
N7K4 opened this issue Jun 29, 2023 · 4 comments
Closed
1 task

Visual Studio Code Dev Container support ? #1524

N7K4 opened this issue Jun 29, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@N7K4
Copy link

N7K4 commented Jun 29, 2023

Extension Version

v2.26.1

Problem Statement

I can use the extension fine on my Windows 10 directly with terraform and also fine on my WSL 2 Ubuntu system. On all mentioned systems terraform v1.5.1 is installed. The terraform explorer works fine.

Now I tried to use the extension inside a Visual Studio Code (vscode) developer container (devContainer). But here the extension do not list providers or modules.

My .devcontainer/Dockerfile

FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-22.04

My .devcontainer/devcontainer.json

{
    "name": "Terraform GCP",
    "build": {
		"dockerfile": "Dockerfile"
    },
    "runArgs": [
		"--init"
    ],
    "features": {
        "ghcr.io/devcontainers/features/terraform:1": {
            "version": "latest",
            "tflint": "latest",
            "terragrunt": "latest"
        },
        "ghcr.io/dhoeric/features/terraform-docs:1": {
            "version": "latest"
        }
    },
    "customizations": {
        "vscode": {
            "extensions": [
                "hashicorp.terraform"
            ],
            "settings": {
                "terraform.languageServer": {
                    "enabled": true,
                    "args": ["serve"]
                }
            }
        }
    },
    "remoteEnv": {
        "TF_LOG": "INFO",
        "TF_LOG_PATH": "./terraform.log"
    }
}

The extension explorer shows:
image

On Windows and WSL I got the provider information listed. I use the "default" folders src and modules nothing special.

I tryed to install the terraform language server myself inside the Dockerfile with

# https://www.hashicorp.com/official-packaging-guide
RUN wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
RUN gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
RUN apt update
# RUN apt install -d /usr/local/bin terraform-ls
RUN apt install terraform-ls

Also I "played" with the configurtaion

"vscode": {
            "extensions": [
                "hashicorp.terraform"
            ],
            "settings": {
                "terraform.languageServer": {
                    "enabled": true,
                    "args": ["serve"],
                    "external": true,
                    "pathToBinary": "/usr/bin",
                    "maxNumberOfProblems": 100,
                    "trace.server": "off"
                }
            }
        }

but I was not able to get the extension running.

Expected User Experience

I would love to have my "native" Winodws or Ubuntu (WSL) experince inside the devContainer as well. So it would be easier to share the environment with my teammates.

Proposal

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@N7K4 N7K4 added the enhancement New feature or request label Jun 29, 2023
@jpogran
Copy link
Contributor

jpogran commented Jun 30, 2023

Hi @N7K4 thanks for reporting this and having such great reproduction steps. I've used your example configs with a minimal main.tf file, and everything pops up as expected:

image

There are some suggestions I have for your devcontainer.json, to help narrow down where the issue is.

The ghcr.io/devcontainers/features/terraform:1 feature already includes the HashiCorp Terraform extension and default settings, so you do not need to include that in the customizations section. In addition, what you included was the old setting names, which we changed in v2.24.X. This should leave your devcontainer.json looking like:

{
    "name": "Terraform GCP",
    "build": {
        "dockerfile": "Dockerfile"
    },
    "runArgs": [
        "--init"
    ],
    "features": {
        "ghcr.io/devcontainers/features/terraform:1": {
            "version": "latest",
            "tflint": "latest",
            "terragrunt": "latest"
        },
        "ghcr.io/dhoeric/features/terraform-docs:1": {
            "version": "latest"
        }
    },
    "customizations": {
    },
    "remoteEnv": {
        "TF_LOG": "INFO",
        "TF_LOG_PATH": "./terraform.log"
    }
}

Be sure to rebuild your container when you change any setting related to VS Code or Docker, as it won't take effect otherwise:

image

One more thing to consider, which is a very big reach, is to make sure your terraform feature is up to date. We fixed their config file awhile back, but if you're using latest this shouldn't be an issue.

To the address the Terraform Providers view not populating part. This requires network access, do your Docker containers have the ability to resolve to the Terraform Registry? If not, that view will not be able to work.

If things still do not work, please send us a copy of the log in the HashiCorp Terraform Output panel. If would prefer sending it outside of Github, let us know and we can provide an address.

@N7K4
Copy link
Author

N7K4 commented Jul 3, 2023

Hi @jpogran, thanks for responding to my request.

I tryed the cleaner dockercontainer.json, no success so far. I will setup a clean project with no company and personal data and will send here the output content.

To the address the Terraform Providers view not populating part. This requires network access, do your Docker containers have the ability to resolve to the Terraform Registry? If not, that view will not be able to work.

--> How can I verify if that works? I did terrform init and all providers was downloaded fine. So I assume here no error.

Update 2023-07-05:

Now it works on all my systems. Great. Many thanks. :-) The providers appear when I open a tf-file.
image

In my old devcontainer.json there was wrong line, on some of my devcontainers. "overrideCommand": false, this line needs to be removed.

IPOV the issue can be closed.

@jpogran
Copy link
Contributor

jpogran commented Jul 7, 2023

Glad to hear this was resolved!

@jpogran jpogran closed this as completed Jul 7, 2023
@github-actions
Copy link

github-actions bot commented Aug 7, 2023

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 Aug 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants