Reputation: 53
I'm doing a pretty basic devcontainer for terraform work in VSCode on Windows. Every time I start it up or rebuild the container for use, it prompts me to install the experimental language server where I end up picking the latest tag for it (v0.0.9).
I have the following setting configured in my default settings.json file
{
"terraform.languageServer.enabled": true
}
and my .devcontainer/devcontainer.json is taken and minimized from the Azure terraform container.
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-existing-dockerfile
{
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
"name": "DevOps Projects IaC With Terraform",
"context": "..",
"dockerFile": "Dockerfile",
"runArgs": [
"-v", "${env:USERPROFILE}/.ssh:/root/.ssh-localhost:ro",
"-v", "${env:USERPROFILE}/.aws:/root/.aws:ro"
],
"postCreateCommand": "mkdir -p ~/.ssh && cp -r ~/.ssh-localhost/* ~/.ssh && chmod 700 ~/.ssh && chmod 600 ~/.ssh/*",
// Add the IDs of any extensions you want installed in the array below.
"extensions": ["mauve.terraform"]
}
How do I include the experimental language server into my build/devcontainer config?
Upvotes: 3
Views: 958
Reputation: 6440
I've been trying to figure out the answer to this for a while, for my own purposes. I decided today that I was going to figure it out and I believe I have it working (installing terraform, the LSP and the AWS provider) using
# Terraform, LSP and AWS Provider
ENV TERRAFORM_VERSION=0.12.24
ENV TERRAFORM_LSP_VERSION=0.0.10
ENV TERRAFORM_AWS_PROVIDER_VERSION=2.59.0
RUN wget -c https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
&& unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
&& mv terraform /usr/local/bin \
&& wget -c https://releases.hashicorp.com/terraform-provider-aws/${TERRAFORM_AWS_PROVIDER_VERSION}/terraform-provider-aws_${TERRAFORM_AWS_PROVIDER_VERSION}_linux_amd64.zip \
&& unzip terraform-provider-aws_${TERRAFORM_AWS_PROVIDER_VERSION}_linux_amd64.zip \
&& mv terraform-provider-aws_v${TERRAFORM_AWS_PROVIDER_VERSION}* /usr/local/bin \
&& echo "provider \"aws\" {}" >> /usr/local/bin/providers.tf \
&& wget -c https://github.com/juliosueiras/terraform-lsp/releases/download/v${TERRAFORM_LSP_VERSION}/terraform-lsp_${TERRAFORM_LSP_VERSION}_linux_amd64.tar.gz -O - | tar -zx \
&& mv terraform-lsp /usr/local/bin \
&& rm terraform*.zip
because I'm installing this to /usr/local/bin and I'm creating a containerUser
which wouldn't have access to install these components, I needed to add the following to the settings
section of my devcontainer.json
"terraform.indexing": {
"enabled": false
},
"terraform.languageServer": {
"enabled": true,
"installCommonProviders": false,
"pathToBinary": "/usr/local/bin"
},
Obviously you need to make adjustments if you want other providers, or to install it elsewhere, or different versions of terraform, the LSP or the AWS provider, but they all should be simple changes.
The latest releases can be found at the following links:
Upvotes: 2