doc/user/workspace/set_up_infrastructure.md
This tutorial guides you through the GitLab workspaces infrastructure setup on AWS using OpenTofu, an open-source fork of Terraform through Infrastructure as Code (IaC).
To follow this tutorial, you must have:
To set up GitLab workspaces infrastructure:
First, you need to create your own copy of the infrastructure setup repository so that you can configure it for your environment.
[!note] It is not possible to create workspaces from projects in your personal namespace. Instead, fork the repository to a top-level group or subgroup.
To fork the repository:
Next, set up the necessary permissions in AWS so the infrastructure can be properly provisioned.
To set up AWS credentials:
Assign the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:*",
"eks:*",
"elasticloadbalancing:*",
"autoscaling:*",
"cloudwatch:*",
"logs:*",
"kms:DescribeKey",
"kms:TagResource",
"kms:UntagResource",
"kms:ListResourceTags",
"kms:CreateKey",
"kms:CreateAlias",
"kms:ListAliases",
"kms:DeleteAlias",
"iam:AddRoleToInstanceProfile",
"iam:AttachRolePolicy",
"iam:CreateInstanceProfile",
"iam:CreateRole",
"iam:CreateServiceLinkedRole",
"iam:GetRole",
"iam:ListAttachedRolePolicies",
"iam:ListRolePolicies",
"iam:ListRoles",
"iam:PassRole",
"iam:DetachRolePolicy",
"iam:ListInstanceProfilesForRole",
"iam:DeleteRole",
"iam:CreateOpenIDConnectProvider",
"iam:CreatePolicy",
"iam:TagOpenIDConnectProvider",
"iam:GetPolicy",
"iam:GetPolicyVersion",
"iam:GetOpenIDConnectProvider",
"iam:DeleteOpenIDConnectProvider",
"iam:ListPolicyVersions",
"iam:DeletePolicy"
],
"Resource": "*"
}
]
}
Create an access key for the user or role.
Save your access key ID and secret access key. You'll need them when configuring CI/CD variables later.
For your workspaces to be accessible, you'll need a domain and TLS certificates to secure the connections.
To prepare your domain and certificates:
workspaces.example.dev.*.workspaces.example.dev.For more information, see generate TLS certificates.
Now you need to create security keys for authentication and SSH connections.
To create the required keys:
Generate a signing key consisting of random letters, numbers, and special characters. For example, run:
openssl rand -base64 32
Generate an SSH host key:
ssh-keygen -f ssh-host-key -N '' -t rsa
The GitLab agent for Kubernetes connects your AWS Kubernetes cluster to GitLab.
To create a token for the agent:
gitlab-workspaces-agentk-eks.Next, set up OAuth authentication to securely access workspaces.
To configure GitLab OAuth:
In the upper-right corner, select your avatar.
Select Edit profile.
In the left sidebar, select Access > Applications.
Scroll down to OAuth applications.
Select Add new application.
Update the following settings:
https://workspaces.example.dev/auth/callback. Replace with your
user-defined domain.api, read_user, openid, and profile.Select Save application.
Save the Application ID and Secret for your CI/CD variables.
Select Continue.
Now, you need to add the necessary variables to your CI/CD configuration so the infrastructure pipeline can run.
To configure CI/CD variables:
In the top bar, select Search or go to and find your project.
Select Settings > CI/CD.
Expand Variables.
In the Project variables section, add the following required variables:
| Variable | Value |
|---|---|
AWS_ACCESS_KEY_ID | AWS access key ID. |
AWS_SECRET_ACCESS_KEY | AWS secret access key. |
TF_VAR_agent_token | GitLab agent for Kubernetes token. |
TF_VAR_kas_address | GitLab Relay (KAS) address. Required if on a GitLab Self-Managed instance. For example, wss://kas.gitlab.com. |
TF_VAR_workspaces_proxy_auth_client_id | OAuth application client ID. |
TF_VAR_workspaces_proxy_auth_client_secret | OAuth application secret. |
TF_VAR_workspaces_proxy_auth_redirect_uri | OAuth callback URL. For example, https://workspaces.example.dev/auth/callback. |
TF_VAR_workspaces_proxy_auth_signing_key | Your generated signing key. |
TF_VAR_workspaces_proxy_domain | Domain for the workspaces proxy. |
TF_VAR_workspaces_proxy_domain_cert | TLS certificate for the proxy domain. |
TF_VAR_workspaces_proxy_domain_key | TLS key for the proxy domain. |
TF_VAR_workspaces_proxy_ssh_host_key | Your generated SSH host key. |
TF_VAR_workspaces_proxy_wildcard_domain | Wildcard domain for workspaces. |
TF_VAR_workspaces_proxy_wildcard_domain_cert | TLS certificate for the wildcard domain. |
TF_VAR_workspaces_proxy_wildcard_domain_key | TLS key for the wildcard domain. |
Optional. Add any of these variables to customize your deployment:
| Variable | Value |
|---|---|
TF_VAR_region | AWS region. |
TF_VAR_zones | AWS availability zones. |
TF_VAR_name | Name prefix for resources. |
TF_VAR_cluster_endpoint_public_access | Public access to cluster endpoint. |
TF_VAR_cluster_node_instance_type | EC2 instance type for Kubernetes nodes. |
TF_VAR_cluster_node_count_min | Minimum number of worker nodes. |
TF_VAR_cluster_node_count_max | Maximum number of worker nodes. |
TF_VAR_cluster_node_count | Number of worker nodes. |
TF_VAR_cluster_node_labels | Map of labels to apply on the cluster nodes. |
TF_VAR_agent_namespace | Kubernetes namespace for the agent. |
TF_VAR_workspaces_proxy_namespace | Kubernetes namespace for workspaces proxy. |
TF_VAR_workspaces_proxy_ingress_class_name | Ingress class name. |
TF_VAR_ingress_nginx_namespace | Kubernetes namespace for Ingress-NGINX. |
Great job! You've configured all the necessary variables for your infrastructure deployment.
Now, you need to configure the GitLab agent for Kubernetes to support workspaces.
To update the agent configuration:
In your forked repository, open the .gitlab/agents/gitlab-workspaces-agentk-eks/config.yaml file.
[!note] The directory that contains the
config.yamlfile must match the agent name you created in the create a GitLab agent for Kubernetes token step.
Update the file with the following required fields:
remote_development:
enabled: true
dns_zone: "workspaces.example.dev" # Replace with your domain
For more configuration options, see workspace settings.
Commit and push these changes to your repository.
It's time to deploy your infrastructure. You'll run the CI/CD pipeline to create all the necessary resources in AWS.
To run the pipeline:
plan job succeeds, then manually trigger the apply job.When the OpenTofu code runs, it creates these resources in AWS:
Excellent! Your infrastructure is now being deployed. This might take some time to complete.
Now that your infrastructure is deployed, you need to configure DNS records to point to your new environment.
To configure DNS records:
Get the Ingress-NGINX load balancer address from the pipeline output:
kubectl get services -n ingress-nginx ingress-nginx-controller
Create DNS records that point your domains to this address. For example:
workspaces.example.dev → Load balancer IP address*.workspaces.example.dev → Load balancer IP addressNext, you'll authorize the GitLab agent for Kubernetes to connect to your GitLab instance.
To authorize the agent:
Finally, let's make sure everything is working correctly by creating a test workspace.
To verify your workspace setup:
Congratulations! You've successfully set up GitLab workspaces infrastructure on AWS. Your users can now create development workspace environments for their projects.
If you encounter any issues, check the logs for additional details and refer to troubleshooting workspaces for guidance.