Use Case
By default, the Terraform Enterprise proxy configurations are injected into the TFC Agent containers.
This article can be useful in case you need to build a new Agent with a custom proxy configuration, which will overwrite the default one.
Procedure
-
Create a directory to make the image:
$ mkdir test
-
Switch to the new directory:
$ cd test
-
Create an empty file named
Dockerfile
:
$ touch Dockerfile
-
Using a text or code editor, add the following contents to the
Dockerfile
and replace the values of environment variables in thehttp://IP:PORT
format:
$ vim Dockerfile
FROM hashicorp/tfc-agent:latest
USER root
# Add environment variables to use custom proxy
ENV HTTP_PROXY=http://xxx.xxx.xxx.xxx:xxxx
ENV HTTPS_PROXY=http://xxx.xxx.xxx.xxx:xxxx
ENV http_proxy=http://xxx.xxx.xxx.xxx:xxxx
ENV https_proxy=http://xxx.xxx.xxx.xxx:xxxx
# Install sudo. The container runs as a non-root user, but people may rely on the ability to apt-get install things.
RUN apt-get -y install sudo
# Permit tfc-agent to use sudo apt-get commands.
RUN echo 'tfc-agent ALL=NOPASSWD: /usr/bin/apt-get , /usr/bin/apt' >> /etc/sudoers.d/50-tfc-agent
USER tfc-agent
- Run Docker build to compile the image:
$ docker build -t custom-tfc-agent .
- To start using this newly built Custom Agent for TFE runs, execute the following command:
$ replicatedctl app-config set custom_agent_image_tag --value 'custom-tfc-agent:latest'
- To apply the settings and restart Replicated service:
$ replicatedctl app apply-config
- Once TFE is up and running, test a
terraform plan
andterraform apply