infisical_gateway resource. The gateway process runs on your own machine, and you install it with the CLI or the Helm chart pointed at the ID that resource produces.
Managing the record in Terraform means the same configuration that creates the EC2 instance or the GKE node pool also creates the gateway it enrolls as. Nothing has to be copied by hand from the Infisical UI into your infrastructure code.
This page covers the Terraform equivalent of the steps in Gateway deployment, using the same authentication methods and the same CLI flags. Read that page first if you haven’t deployed a gateway before.
Prerequisites
- Terraform 1.0 or later
- An Infisical machine identity with permission to create gateways in your organization
- A relay, if you’re using relay mode. See Relay deployment.
Configure the provider
Create a gateway
Set exactly one authentication block on the resource. AWS, GCP, and Kubernetes authentication re-authenticate on every start and put no secret in Terraform state, so use one of those wherever the platform can vouch for the host. Use token authentication for the rest, such as a server in your own data center. Every method takes an allowlist, and only a machine matching it can enroll as the gateway. Gateway deployment describes what each field is checked against.- AWS
- GCP
- Kubernetes
- Token
The host authenticates by signing an STS request with whatever AWS credentials it can resolve, such as an instance role.At least one of The role behind
allowed_account_ids or allowed_principal_arns is required. An account ID on its own trusts every principal in that account, so prefer the ARN where you can.Pass the gateway’s name and ID to the instance that runs it:aws_iam_instance_profile.gateway has to match the allowlist above.Enrollment tokens
An enrollment token is single-use and expires after an hour. The gateway consumes the token the first time it enrolls, and holds credentials of its own from then on. Terraform can’t tell whether a token has already been used, soinfisical_gateway_enrollment_token never mints a new one on its own. keepers is how you say when it should. List the inputs that force the machine consuming the token to be rebuilt, and a change to any of them mints a fresh token before the replacement machine boots.
In the example above, those inputs are the AMI, the instance type, and the subnet, because changing any of them replaces the EC2 instance. You can’t reference the instance itself, since the instance depends on the token, so list what the instance is built from instead.
Manage an existing gateway
You can import a gateway created in the UI. Copy its ID from the gateway’s detail page:token_reviewer_jwt, so it’s empty on an imported Kubernetes gateway. Add it back to your configuration if you set one. Gateways bound to a machine identity predate authentication methods and can’t be imported.
Changing name renames the gateway in place. It keeps its ID, and app connections, dynamic secrets, and rotations that use it keep working.
On the host, the config file and the systemd unit are named after the gateway as it was at install time, and a rename in Infisical doesn’t change either. Re-run the install command on the host if you want the names to match.
Next steps
Gateway deployment
Connection modes, host requirements, and troubleshooting.
Gateway pools
Group gateways for redundancy and failover.