### Development Setup with Service Domain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md This example shows a typical development setup using a Railway-provided service domain. It's suitable for testing and staging environments where custom domains are not required. ```hcl resource "railway_environment" "dev" { name = "development" project_id = railway_project.app.id } resource "railway_service" "api" { name = "api-service" project_id = railway_project.app.id source_repo = "myorg/api" source_repo_branch = "develop" } resource "railway_service_domain" "api" { subdomain = "dev-api" environment_id = railway_environment.dev.id service_id = railway_service.api.id } output "dev_api_url" { value = "https://${railway_service_domain.api.domain}" } ``` -------------------------------- ### Production Setup with Custom Domain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md This snippet illustrates a production setup using a custom domain, linking it to a specific service and environment. It requires manual DNS configuration. ```hcl resource "railway_environment" "prod" { name = "production" project_id = railway_project.app.id } resource "railway_service" "api" { name = "api-service" project_id = railway_project.app.id source_repo = "myorg/api" source_repo_branch = "main" } resource "railway_custom_domain" "api" { domain = "api.example.com" environment_id = railway_environment.prod.id service_id = railway_service.api.id } ``` -------------------------------- ### Build Terraform Provider Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/CONTRIBUTING.md Builds the Terraform provider using the Go install command. Ensure you have Go and Terraform installed and have cloned the repository. ```shell go install ``` -------------------------------- ### Service from Docker Image Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-service.md Example of creating a Railway service deployed from a Docker image. Specifies the image name and regional deployment configuration. ```hcl resource "railway_service" "web" { name = "web-service" project_id = railway_project.app.id source_image = "nginx:latest" regions { region = "us-west-2" num_replicas = 1 } } ``` -------------------------------- ### Service from GitHub Repository Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-service.md Example of creating a Railway service deployed from a GitHub repository. Specifies the repository, branch, root directory, and regional deployment configuration. ```hcl resource "railway_environment" "prod" { name = "production" project_id = railway_project.app.id } resource "railway_service" "api" { name = "api-service" project_id = railway_project.app.id source_repo = "myorg/myrepo" source_repo_branch = "main" root_directory = "services/api" regions { region = "us-east-1" num_replicas = 2 } } ``` -------------------------------- ### Shared Variable Resource Example with Environment Config Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-variables.md An example of a shared variable used for setting the environment name, demonstrating its application across a project. ```hcl resource "railway_shared_variable" "shared_config" { name = "ENVIRONMENT" value = "production" environment_id = railway_environment.prod.id project_id = railway_project.app.id } ``` -------------------------------- ### PostgreSQL Database Proxy Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-tcp-proxy.md Sets up a TCP proxy for a PostgreSQL service, providing connection details as an output. Ensure the `railway_service` for PostgreSQL is defined. ```hcl resource "railway_service" "postgres" { name = "database" project_id = railway_project.app.id source_image = "postgres:15" regions { region = "us-east-1" num_replicas = 1 } } resource "railway_tcp_proxy" "db" { application_port = 5432 environment_id = railway_environment.prod.id service_id = railway_service.postgres.id } output "database_connection" { value = "${railway_tcp_proxy.db.domain}:${railway_tcp_proxy.db.proxy_port}" description = "Use this address to connect to the database" } ``` -------------------------------- ### Custom Domain with DNS Records Output Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md Example demonstrating how to output DNS record information for a custom domain, useful for manual DNS configuration. ```hcl resource "railway_custom_domain" "app" { domain = "app.example.com" environment_id = railway_environment.prod.id service_id = railway_service.frontend.id } output "dns_record" { value = railway_custom_domain.app.dns_record_value description = "Add this CNAME record: ${railway_custom_domain.app.host_label} CNAME ${railway_custom_domain.app.dns_record_value}" } ``` -------------------------------- ### Setup Custom Domain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/INDEX.md This snippet demonstrates how to set up a custom domain for a Railway service. It defines a `railway_custom_domain` resource and outputs instructions for DNS setup, including the required CNAME target. ```hcl resource "railway_custom_domain" "example" { domain = "api.example.com" environment_id = railway_environment.prod.id service_id = railway_service.api.id } output "dns_setup" { value = "Create CNAME: ${railway_custom_domain.example.host_label} → ${railway_custom_domain.example.dns_record_value}" ``` -------------------------------- ### Basic Project Usage Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-project.md Example of creating a basic Railway project with only the required name argument. ```hcl resource "railway_project" "basic" { name = "my-app" } ``` -------------------------------- ### Multiple TCP Proxies Configuration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-tcp-proxy.md Demonstrates setting up multiple TCP proxies for the same service, potentially for different ports or purposes. This example shows proxies for a main database connection and a replica on an alternate port. ```hcl # Main database connection resource "railway_tcp_proxy" "main_db" { application_port = 5432 environment_id = railway_environment.prod.id service_id = railway_service.postgres.id } # Replica connection on alternate port resource "railway_tcp_proxy" "db_replica" { application_port = 5433 environment_id = railway_environment.prod.id service_id = railway_service.postgres.id } ``` -------------------------------- ### Service Variable Resource Example with Variables Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-variables.md Another example of managing service-scoped variables, demonstrating the use of Terraform variables for sensitive values like API keys. ```hcl resource "railway_variable" "env_vars" { name = "API_KEY" value = var.api_key_secret environment_id = railway_environment.production.id service_id = railway_service.backend.id } ``` -------------------------------- ### Multiple Service Domains Configuration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md This example demonstrates how to configure multiple service domains for different services within the same environment. Each domain is given a unique subdomain. ```hcl resource "railway_service_domain" "api" { subdomain = "api" environment_id = railway_environment.prod.id service_id = railway_service.backend.id } resource "railway_service_domain" "web" { subdomain = "www" environment_id = railway_environment.prod.id service_id = railway_service.frontend.id } output "api_url" { value = railway_service_domain.api.domain } output "web_url" { value = railway_service_domain.web.domain } ``` -------------------------------- ### Project with Custom Configuration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-project.md Example of creating a Railway project with custom configuration including description, privacy, PR deploys, and a named default environment. ```hcl resource "railway_project" "configured" { name = "production-app" description = "Main production application" private = false has_pr_deploys = true default_environment { name = "main" } } ``` -------------------------------- ### Context with Timeout Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Demonstrates how to use context.Context with a timeout for GraphQL operations. Ensure to call the cancel function to release resources. ```go ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() response, err := createProject(ctx, client, input) ``` -------------------------------- ### Basic Custom Domain Usage Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md Example of creating a basic custom domain resource pointing to a service in a specific environment. ```hcl resource "railway_custom_domain" "api" { domain = "api.example.com" environment_id = railway_environment.prod.id service_id = railway_service.backend.id } ``` -------------------------------- ### Get Environments Function Signature Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Defines the function signature for listing all environments within a given project. ```Go func getEnvironments(ctx context.Context, client graphql.Client, projectId string) (*GetEnvironmentsResponse, error) ``` -------------------------------- ### Authentication Header Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Example of the Authorization header used for GraphQL operations, including the Bearer token. This is handled by the authedTransport HTTP round-tripper. ```http Authorization: Bearer ``` -------------------------------- ### Get Service by ID Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Retrieves a service by its ID. Use this function to fetch service configuration details. ```go func getService(ctx context.Context, client graphql.Client, serviceId string) (*GetServiceResponse, error) ``` -------------------------------- ### Configure Database Connection with Variable Collection Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-variables.md This example demonstrates using `railway_variable_collection` to set up a `DATABASE_URL` and `DATABASE_POOL_SIZE` for a service, integrating with external AWS resources. ```hcl resource "railway_variable_collection" "database" { environment_id = railway_environment.prod.id service_id = railway_service.api.id variables { name = "DATABASE_URL" value = "postgresql://${aws_db_instance.main.username}:${aws_db_instance.main.password}@${aws_db_instance.main.endpoint}/${aws_db_instance.main.db_name}" } variables { name = "DATABASE_POOL_SIZE" value = "20" } } ``` -------------------------------- ### Shared Variable Resource Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-variables.md Manages environment-scoped variables accessible to all services within an environment. Use this for configuration shared across multiple services. ```hcl resource "railway_shared_variable" "log_level" { name = "LOG_LEVEL" value = "info" environment_id = railway_environment.prod.id project_id = railway_project.app.id } ``` -------------------------------- ### Get Project Function Signature Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Defines the function signature for retrieving a project by its ID. ```Go func getProject(ctx context.Context, client graphql.Client, projectId string) (*GetProjectResponse, error) ``` -------------------------------- ### Variable Collection Resource Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-variables.md Manages multiple service-scoped variables as a single collection, enabling atomic deployment for related sets of variables. Useful for grouping configuration. ```hcl resource "railway_variable_collection" "env_config" { environment_id = railway_environment.prod.id service_id = railway_service.api.id variables { name = "API_URL" value = "https://api.example.com" } variables { name = "API_KEY" value = var.api_key_secret } variables { name = "LOG_LEVEL" value = "debug" } } ``` -------------------------------- ### Custom Domain with Specific Port Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md Example of configuring a custom domain to route traffic to a specific port on the service. ```hcl resource "railway_custom_domain" "webhook" { domain = "webhook.example.com" target_port = 9000 environment_id = railway_environment.prod.id service_id = railway_service.webhook_handler.id } ``` -------------------------------- ### Get Environment Function Signature Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Defines the function signature for retrieving a specific environment by its ID. ```Go func getEnvironment(ctx context.Context, client graphql.Client, environmentId string) (*GetEnvironmentResponse, error) ``` -------------------------------- ### Get Shared Variables Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Retrieves all shared variables for a given project and environment. Returns a map of variable names to values. ```go func getSharedVariables(ctx context.Context, client graphql.Client, projectId string, environmentId string) (*GetSharedVariablesResponse, error) ``` -------------------------------- ### Get Variables for a Service Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Retrieves all variables associated with a specific service within a project and environment. Returns a map of variable names to values. ```go func getVariables(ctx context.Context, client graphql.Client, projectId string, environmentId string, serviceId string) (*GetVariablesResponse, error) ``` -------------------------------- ### Basic Environment Usage Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-environment.md Example of creating a Railway project and then defining a basic environment within it. The environment's project ID is linked to the created project's ID. ```hcl resource "railway_project" "app" { name = "my-app" } resource "railway_environment" "staging" { name = "staging" project_id = railway_project.app.id } ``` -------------------------------- ### Redis Cache Proxy Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-tcp-proxy.md Configures a TCP proxy for a Redis service and sets a `REDIS_URL` environment variable for the application service. Ensure the `railway_service` for Redis and the application service are defined. ```hcl resource "railway_service" "redis" { name = "cache" project_id = railway_project.app.id source_image = "redis:7-alpine" regions { region = "us-east-1" num_replicas = 1 } } resource "railway_tcp_proxy" "redis_proxy" { application_port = 6379 environment_id = railway_environment.prod.id service_id = railway_service.redis.id } resource "railway_variable" "redis_url" { name = "REDIS_URL" value = "redis://${railway_tcp_proxy.redis_proxy.domain}:${railway_tcp_proxy.redis_proxy.proxy_port}" environment_id = railway_environment.prod.id service_id = railway_service.app.id } ``` -------------------------------- ### Project in Specific Workspace Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-project.md Example of creating a Railway project within a specified workspace by providing the workspace ID. ```hcl resource "railway_project" "workspace_scoped" { name = "workspace-project" workspace_id = "550e8400-e29b-41d4-a716-446655440000" } ``` -------------------------------- ### Service Variable Resource Example Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-variables.md Manages service-scoped environment variables. These variables are available only to the specific service they are associated with. Use this for variables unique to a single service. ```hcl resource "railway_variable" "db_url" { name = "DATABASE_URL" value = "postgresql://user:pass@host/db" environment_id = railway_environment.prod.id service_id = railway_service.api.id } ``` -------------------------------- ### Importing a railway_environment resource Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/docs/resources/environment.md This command demonstrates how to import an existing Railway environment into your Terraform state. Replace the example ID and name with your actual environment details. ```shell terraform import railway_environment.example 0bb01547-570d-4109-a5e8-138691f6a2d1:staging ``` -------------------------------- ### Environment with Service Association Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-environment.md Shows how to define a Railway environment and a Railway service within the same project. This setup is common for deploying services to a specific environment. ```hcl resource "railway_environment" "prod" { name = "production" project_id = railway_project.app.id } resource "railway_service" "api" { name = "api-service" project_id = railway_project.app.id } ``` -------------------------------- ### Type Definitions Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/MANIFEST.txt Documentation for all enumerations, input types, and response types used within the provider's API, including field descriptions and usage examples. ```APIDOC ## Types ### Description This section documents all type definitions used by the provider, including enumerations, input types, and response types. It provides field-level descriptions and usage examples. ### Enumerations Lists all available enumerations with their possible values. ### Input Types Details the structure and fields for all input types used in GraphQL operations and resource configurations. ### Response Types Describes the structure and fields for all response types returned by GraphQL operations. ``` -------------------------------- ### Resource Interface Implementation Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/architecture-and-internals.md Demonstrates the basic structure for implementing a resource, adhering to the Terraform Plugin Framework's resource interface. ```go type ProjectResource struct { client *graphql.Client } // Implements resource.Resource var _ resource.Resource = &ProjectResource{} // Implements resource.ResourceWithImportState var _ resource.ResourceWithImportState = &ProjectResource{} ``` -------------------------------- ### Generation Process: Schema to Go Types Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/architecture-and-internals.md Illustrates the process of generating Go types and operations from a GraphQL schema using genqlient. ```bash genqlient reads schema.graphql → generates Go types and operations ``` -------------------------------- ### Create Custom Domain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a custom domain for a service, returning DNS verification details. Requires domain, environment, project, and service IDs. ```go func createCustomDomain(ctx context.Context, client graphql.Client, input CustomDomainCreateInput) (*CreateCustomDomainResponse, error) ``` -------------------------------- ### Connect to Database Service Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/INDEX.md This snippet illustrates how to connect a service to a database. It provisions a PostgreSQL service using a source image, sets up a TCP proxy for database access, and configures a `DATABASE_URL` environment variable for the main API service to connect to the database. ```hcl resource "railway_service" "postgres" { name = "database" project_id = railway_project.app.id source_image = "postgres:15" } resource "railway_tcp_proxy" "db" { application_port = 5432 environment_id = railway_environment.prod.id service_id = railway_service.postgres.id } resource "railway_variable" "db_url" { name = "DATABASE_URL" value = "postgresql://user:pass@${railway_tcp_proxy.db.domain}:${railway_tcp_proxy.db.proxy_port}/mydb" environment_id = railway_environment.prod.id service_id = railway_service.api.id } ``` -------------------------------- ### Importing a Custom Domain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md Demonstrates the Terraform import command for an existing custom domain, requiring service ID, environment name, and domain. ```bash terraform import railway_custom_domain.api "service-uuid:production:api.example.com" ``` -------------------------------- ### CustomDomainCreateInput Go Struct Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input structure for creating a custom domain. Includes the domain name, target port, and associated service, environment, and project IDs. ```go type CustomDomainCreateInput struct { Domain string EnvironmentId string ProjectId string ServiceId string TargetPort *int } ``` -------------------------------- ### ServiceDomainCreateInput Go Struct Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input structure for creating a service domain. Requires the service ID and environment ID to associate a domain with a service. ```go type ServiceDomainCreateInput struct { ServiceId string EnvironmentId string } ``` -------------------------------- ### Resource Documentation Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/MANIFEST.txt Detailed documentation for all Railway resources managed by the Terraform provider, including their schemas, arguments, and example usage. ```APIDOC ## Resource Documentation This section provides comprehensive documentation for each resource managed by the Railway Terraform provider. ### `railway_project` - **Description**: Manages a Railway project. - **Schema and Arguments**: Detailed schema and available arguments. - **Lifecycle and Behavior**: Information on resource lifecycle and behavior. - **Example Usage**: Patterns for using the resource in Terraform configurations. - **Import and Validation**: Reference for importing existing projects and validation rules. ### `railway_environment` - **Description**: Manages a Railway environment within a project. - **Creation and Management**: Details on creating and managing environments. - **Import Syntax**: How to import existing environments. - **Error Handling**: Common errors and resolutions. - **Resource Dependencies**: Information on resource dependencies. ### `railway_service` - **Description**: Manages a Railway service. - **Source Configuration**: Supports configuration via Git repository, Docker image, or template. - **Multi-region Deployment**: Configuration for deploying services across multiple regions. - **Volume and Cron Configuration**: Settings for persistent volumes and cron jobs. - **Example Deployments**: Illustrative deployment examples. ### `railway_variable` (service-scoped) - **Description**: Manages service-scoped variables. ### `railway_shared_variable` (environment-scoped) - **Description**: Manages environment-scoped shared variables. ### `railway_variable_collection` - **Description**: Facilitates batch management of variables. - **Comparison Matrix**: Compares different variable types. - **Common Patterns and Error Handling**: Best practices and error resolution. ### `railway_custom_domain` - **Description**: Manages custom domains for services. - **DNS Configuration Guide**: Instructions for configuring DNS records. ### `railway_service_domain` - **Description**: Manages Railway-provided domains for services. - **Comparison Matrix**: Compares custom and service domains. - **Multi-service Setup Patterns**: Patterns for setting up domains across multiple services. ### `railway_tcp_proxy` - **Description**: Configures TCP proxy settings for services. - **Port Assignment and Proxy Domains**: Details on port assignments and proxy domains. - **Database and Cache Connectivity**: Configuration for connecting to databases and caches. - **Service Variable Integration**: Integration with service variables. - **Security and Performance Notes**: Security and performance considerations. ``` -------------------------------- ### Trace and Debug Logging in Go Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/architecture-and-internals.md Illustrates how to use the `terraform-plugin-log` package for tracing and debugging messages within the provider. These logs are controlled via environment variables and displayed during `terraform apply -d`. ```go tflog.Trace(ctx, "created a project") tflog.Debug(ctx, "fetching project details") ``` -------------------------------- ### TCP Proxy with Service Variables Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-tcp-proxy.md Illustrates how to configure a TCP proxy for a database service and then use its domain and proxy port to set environment variables for an application service. This allows the application to connect to the database via the proxy. ```hcl resource "railway_service" "app" { name = "application" project_id = railway_project.app.id source_repo = "myorg/app" source_repo_branch = "main" } resource "railway_service" "db" { name = "postgres" project_id = railway_project.app.id source_image = "postgres:15" } resource "railway_tcp_proxy" "db_connection" { application_port = 5432 environment_id = railway_environment.prod.id service_id = railway_service.db.id } resource "railway_variable_collection" "db_config" { environment_id = railway_environment.prod.id service_id = railway_service.app.id variables { name = "DATABASE_HOST" value = railway_tcp_proxy.db_connection.domain } variables { name = "DATABASE_PORT" value = tostring(railway_tcp_proxy.db_connection.proxy_port) } variables { name = "DATABASE_NAME" value = "production" } } ``` -------------------------------- ### Get TCP Proxy Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Retrieves TCP proxies for a service in an environment. Requires context, a GraphQL client, environment ID, and service ID. ```go func getTcpProxy(ctx context.Context, client graphql.Client, environmentId string, serviceId string) (*GetTcpProxyResponse, error) ``` -------------------------------- ### Set up TCP Proxy for Inter-Service Communication Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-tcp-proxy.md Creates a PostgreSQL service and a TCP proxy for it, then configures an API service to use the database via a generated variable. ```hcl resource "railway_service" "api" { name = "api" project_id = railway_project.app.id source_repo = "myorg/api" source_repo_branch = "main" } resource "railway_service" "db" { name = "postgres" project_id = railway_project.app.id source_image = "postgres:15" } resource "railway_tcp_proxy" "db_proxy" { application_port = 5432 environment_id = railway_environment.prod.id service_id = railway_service.db.id } # API service knows how to reach database resource "railway_variable" "api_db_url" { name = "DATABASE_URL" value = "postgresql://postgres:password@${railway_tcp_proxy.db_proxy.domain}:${railway_tcp_proxy.db_proxy.proxy_port}/myapp" environment_id = railway_environment.prod.id service_id = railway_service.api.id } ``` -------------------------------- ### Deploy a Service from GitHub Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/INDEX.md This snippet demonstrates how to deploy a service from a GitHub repository to a Railway project. It configures a project, an environment, the service itself with source repository details, and a custom domain for accessing the service. Finally, it outputs the service's URL. ```hcl resource "railway_project" "app" { name = "my-app" } resource "railway_environment" "prod" { name = "production" project_id = railway_project.app.id } resource "railway_service" "api" { name = "api-service" project_id = railway_project.app.id source_repo = "myorg/myrepo" source_repo_branch = "main" regions { region = "us-east-1" num_replicas = 1 } } resource "railway_service_domain" "api" { subdomain = "api" environment_id = railway_environment.prod.id service_id = railway_service.api.id } output "api_url" { value = "https://${railway_service_domain.api.domain}" } ``` -------------------------------- ### Configure Service with Private Registry Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-service.md Use this snippet to deploy a service from a private container registry. Ensure `source_image_registry_username` and `source_image_registry_password` are correctly set. ```hcl resource "railway_service" "private" { name = "private-service" project_id = railway_project.app.id source_image = "registry.example.com/myapp:latest" source_image_registry_username = "registry_user" source_image_registry_password = var.registry_password regions { region = "eu-west-1" num_replicas = 1 } } ``` -------------------------------- ### Import a Railway Service Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/docs/resources/service.md This command demonstrates how to import an existing Railway service into your Terraform state. Replace the example ID with the actual service ID. ```shell terraform import railway_service.example 89fa0236-2b1b-4a8c-b12d-ae3634b30d97 ``` -------------------------------- ### GraphQL Client Initialization Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/architecture-and-internals.md Initializes the genqlient GraphQL client with the Railway API endpoint and an authenticated HTTP client. ```go client := graphql.NewClient( "https://backboard.railway.app/graphql/v2?source=terraform_provider_railway", &httpClient, ) ``` -------------------------------- ### Multi-Service Domain Configuration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md This configuration demonstrates setting up both custom domains for production services and service domains for staging environments within the same project. It highlights managing different domain types for various needs. ```hcl resource "railway_environment" "prod" { name = "production" project_id = railway_project.app.id } resource "railway_service" "frontend" { name = "web" project_id = railway_project.app.id source_repo = "myorg/frontend" source_repo_branch = "main" } resource "railway_service" "backend" { name = "api" project_id = railway_project.app.id source_repo = "myorg/backend" source_repo_branch = "main" } resource "railway_custom_domain" "www" { domain = "example.com" environment_id = railway_environment.prod.id service_id = railway_service.frontend.id } resource "railway_custom_domain" "api" { domain = "api.example.com" environment_id = railway_environment.prod.id service_id = railway_service.backend.id } resource "railway_service_domain" "staging_frontend" { subdomain = "staging" environment_id = railway_environment.dev.id service_id = railway_service.frontend.id } ``` -------------------------------- ### ProjectCreateInput Structure Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input parameters for creating a new project in Railway. Use this to specify project name, description, visibility, and repository configuration. ```go type ProjectCreateInput struct { DefaultEnvironmentName string Description string IsMonorepo bool IsPublic bool Name string PrDeploys bool Repo *ProjectCreateRepo Runtime *PublicRuntime WorkspaceId *string } ``` -------------------------------- ### ServiceConnectInput Structure Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input parameters for connecting a service to a source repository or Docker image. Use this to specify the source details for a service. ```go type ServiceConnectInput struct { Branch *string Image *string Repo *string } ``` -------------------------------- ### List Custom Domains Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Lists all custom domains associated with a service in a specific environment and project. Returns an array of custom domains. ```go func listCustomDomains(ctx context.Context, client graphql.Client, environmentId string, serviceId string, projectId string) (*ListCustomDomainsResponse, error) ``` -------------------------------- ### Create TCP Proxy Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a TCP proxy for a service. Requires context, a GraphQL client, and a TCPProxyCreateInput struct containing application port, service ID, and environment ID. ```go func createTcpProxy(ctx context.Context, client graphql.Client, input TCPProxyCreateInput) (*CreateTcpProxyResponse, error) ``` ```go type TCPProxyCreateInput struct { ApplicationPort int ServiceId string EnvironmentId string } ``` -------------------------------- ### Basic Service Domain Configuration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-domains.md Use this snippet to create a single service domain for a specific environment and service. It defines the subdomain and links it to existing environment and service resources. ```hcl resource "railway_service_domain" "api" { subdomain = "my-api" environment_id = railway_environment.prod.id service_id = railway_service.backend.id } output "service_url" { value = railway_service_domain.api.domain } ``` -------------------------------- ### TCPProxyCreateInput Go Struct Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input structure for creating a TCP proxy. Requires the application port and the IDs for the associated service and environment. ```go type TCPProxyCreateInput struct { ApplicationPort int ServiceId string EnvironmentId string } ``` -------------------------------- ### Project Environments Connection Type Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Defines the structure for paginated environment lists using connection types, including edges and nodes. ```go type ProjectEnvironmentsConnection struct { Edges []ProjectEnvironmentsConnectionEdge } type ProjectEnvironmentsConnectionEdge struct { Node Environment } ``` -------------------------------- ### ServiceCreateInput Structure Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input parameters for creating a new service in Railway. Use this to configure service name, project, source, and environment variables. ```go type ServiceCreateInput struct { Branch *string EnvironmentId *string Icon *string Name string ProjectId string RegistryCredentials *RegistryCredentialsInput Source *ServiceSourceInput TemplateId *string TemplateServiceId *string Variables map[string]interface{} } ``` -------------------------------- ### List Service Domains Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Lists all service domains for a specific service within an environment. Requires context, a GraphQL client, environment ID, service ID, and project ID. ```go func listServiceDomains(ctx context.Context, client graphql.Client, environmentId string, serviceId string, projectId string) (*ListServiceDomainsResponse, error) ``` -------------------------------- ### Multiple Environments Configuration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-environment.md Demonstrates the creation of multiple distinct environments ('staging' and 'production') within the same Railway project. Each environment is defined using the 'railway_environment' resource, referencing the same project ID. ```hcl resource "railway_project" "app" { name = "my-app" } resource "railway_environment" "staging" { name = "staging" project_id = railway_project.app.id } resource "railway_environment" "production" { name = "production" project_id = railway_project.app.id } ``` -------------------------------- ### listServiceDomains Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Lists all service domains for a service in an environment. Requires environment ID, service ID, and project ID. ```APIDOC ## listServiceDomains ### Description Lists all service domains for a service in an environment. ### GraphQL Operation Name `listServiceDomains` ### Parameters - **environmentId** (ID!) - Required - The ID of the environment. - **serviceId** (ID!) - Required - The ID of the service. - **projectId** (ID!) - Required - The ID of the project. ``` -------------------------------- ### getEnvironments Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Lists all environments associated with a given project ID. The response includes pagination information. ```APIDOC ## getEnvironments ### Description Lists all environments in a project. ### GraphQL Operation `getEnvironments` ### Parameters #### Path Parameters - **projectId** (ID!) - The unique identifier of the project whose environments are to be listed. ``` -------------------------------- ### ServiceDomainUpdateInput Go Struct Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input structure for updating an existing service domain. Includes the service domain ID, new domain name, and associated service and environment IDs. ```go type ServiceDomainUpdateInput struct { ServiceDomainId string Domain string ServiceId string EnvironmentId string } ``` -------------------------------- ### EnvironmentCreateInput Structure Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Defines the input parameters for creating a new environment within a Railway project. Use this to specify environment name, project association, and deployment behavior. ```go type EnvironmentCreateInput struct { ApplyChangesInBackground bool Ephemeral bool Name string ProjectId string SkipInitialDeploys bool SourceEnvironmentId *string StageInitialChanges bool } ``` -------------------------------- ### railway_service Resource Configuration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-service.md This snippet shows how to configure a `railway_service` resource, specifying deployment details from a source repository. ```APIDOC ## Resource: railway_service ### Description Manages services within a Railway environment, representing deployable applications. ### Schema ```hcl resource "railway_service" "api" { name = "api-service" project_id = railway_project.example.id source_repo = "owner/repo" source_repo_branch = "main" regions { region = "us-east-1" num_replicas = 1 } } ``` ### Arguments #### Required - **name** (string) - Name of the service. Must be at least 1 character (UTF-8). - **project_id** (string) - Unique identifier of the project. Must be a valid UUID. Cannot be changed after creation (requires replacement). #### Optional - Source Configuration - **source_image** (string) - Docker image to deploy. Either a Dockerhub or GHCR image name. Conflicts with `source_repo`, `source_repo_branch`, `root_directory`, `config_path`. - **source_image_registry_username** (string) - Username for private Docker registry authentication. Requires `source_image_registry_password`. Conflicts with `source_repo`, `source_repo_branch`, `root_directory`, `config_path`. - **source_image_registry_password** (string, sensitive) - Password for private Docker registry authentication. Requires `source_image_registry_username`. Conflicts with `source_repo`, `source_repo_branch`, `root_directory`, `config_path`. - **source_repo** (string) - Git repository URL (owner/repo format). Requires `source_repo_branch`. Minimum 3 characters. Conflicts with `source_image`. - **source_repo_branch** (string) - Git branch to deploy from. Required if `source_repo` is specified. Minimum 1 character. Conflicts with `source_image`. - **root_directory** (string) - Root directory within the repository for the service. Minimum 1 character. Conflicts with `source_image`. - **config_path** (string) - Path to Railway config file within the repository. Minimum 1 character. Conflicts with `source_image`. #### Optional - Deployment Configuration - **cron_schedule** (string) - Cron schedule for the service. Only allowed when total replicas across all regions is 1. Minimum 9 characters. - **volume** (object) - Volume configuration (nested object). See nested schema. - **regions** (list(object)) - Regional deployment configuration. List of region objects. ### Nested `volume` Block - **name** (string) - Name of the volume. - **mount_path** (string) - Path where the volume is mounted. - **size** (number) - Size of the volume in GB. ### Nested `regions` Block - **region** (string) - AWS region identifier (e.g., `us-east-1`, `eu-west-1`). - **num_replicas** (int64) - Number of replicas to deploy in this region. Minimum 0. ### Attributes #### Computed (Read-Only) - **id** (string) - Unique identifier of the service (UUID format). - **volume.id** (string) - Unique identifier of the attached volume. ### Validation - **Name Length:** Must contain at least 1 UTF-8 character - **Project ID:** Must be a valid UUID - **Source Conflicts:** Cannot specify both image-based (`source_image`, registry credentials) and repo-based (`source_repo`, `source_repo_branch`) source configurations - **Registry Credentials:** Username and password must both be specified or neither - **Cron Schedule:** Only allowed when total replicas across all regions is 1 - **Repository URL:** If specified, must be at least 3 characters ``` -------------------------------- ### Provider Type Definition Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/architecture-and-internals.md Defines the main provider type and its configuration model. The configuration includes a token for authentication. ```go type RailwayProvider struct { version string } type RailwayProviderModel struct { Token types.String `tfsdk:"token"` } ``` -------------------------------- ### Terraform Import Syntax Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/INDEX.md This is the standard syntax for importing existing resources into Terraform state. It requires the resource type, resource name, and the import ID. ```bash terraform import . ``` -------------------------------- ### Define a TCP Proxy for a Production Database Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-tcp-proxy.md Configures a TCP proxy to expose a production PostgreSQL database. Outputs a connection string for local development access. ```hcl # Production database with TCP proxy resource "railway_tcp_proxy" "prod_db" { application_port = 5432 environment_id = railway_environment.prod.id service_id = railway_service.postgres.id } # Output connection string for local development output "database_connection_string" { value = "postgresql://user:password@${railway_tcp_proxy.prod_db.domain}:${railway_tcp_proxy.prod_db.proxy_port}/dbname" description = "Use this to connect to production database from local environment" sensitive = true } ``` -------------------------------- ### Resource Documentation Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/MANIFEST.txt Comprehensive documentation for all 9 resources managed by the provider, including schemas, arguments, attributes, and CRUD operations. ```APIDOC ## Resources ### Description This section provides detailed documentation for each of the 9 resources supported by the Terraform Provider Railway. It covers resource schemas, arguments, attributes, lifecycle behavior, and CRUD operations. ### Resource Schema Detailed schemas for each resource, including all fields, their types, and whether they are computed or user-supplied. Documentation also identifies immutable fields. ### CRUD Operations Documentation for Create, Read, Update, and Delete operations for each resource, including import support. ``` -------------------------------- ### createService Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a new service within a project. This operation requires a ServiceCreateInput object detailing the service's name, project ID, and source configuration. ```APIDOC ## createService ### Description Creates a new service within a project. ### GraphQL Operation `createService` ### Input Parameters #### ServiceCreateInput - **Branch** (*string) - The branch associated with the service. - **EnvironmentId** (*string) - The ID of the environment the service belongs to. - **Icon** (*string) - An icon identifier for the service. - **Name** (string) - The name of the service. - **ProjectId** (string) - The ID of the project the service belongs to. - **RegistryCredentials** (*RegistryCredentialsInput) - Registry credentials for the service. - **Source** (*ServiceSourceInput) - The source configuration for the service. - **TemplateId** (*string) - The ID of the template used for the service. - **TemplateServiceId** (*string) - The ID of the template service. - **Variables** (map[string]interface{}) - Key-value pairs for service variables. ``` -------------------------------- ### CustomDomainStatusDnsRecordsDNSRecords Struct Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Details individual DNS record information for custom domain verification. Used to set up DNS for a custom domain. ```go type CustomDomainStatusDnsRecordsDNSRecords struct { Hostlabel string RequiredValue string Zone string } ``` ```shell Zone: example.com Hostlabel: api RequiredValue: railway-proxy.example.com Create DNS record: api.example.com CNAME railway-proxy.example.com ``` -------------------------------- ### GraphQL Operations Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/MANIFEST.txt Documentation for all available GraphQL mutations and queries, including their parameters, return types, and error handling. ```APIDOC ## GraphQL Operations ### Description This section details all available GraphQL mutations and queries that can be invoked via the provider. It includes information on required parameters, expected return types, and common error scenarios. ### Queries Documentation for all documented GraphQL queries, including their signatures, parameter types, and return types. ### Mutations Documentation for all documented GraphQL mutations, including their signatures, parameter types, and return types. ``` -------------------------------- ### createServiceDomain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a Railway-provided service domain. Requires service ID and environment ID. ```APIDOC ## createServiceDomain ### Description Creates a Railway-provided service domain. ### GraphQL Operation Name `createServiceDomain` ### Input Type `ServiceDomainCreateInput` ### Input Parameters - **ServiceId** (string) - Required - The ID of the service. - **EnvironmentId** (string) - Required - The ID of the environment. ### Returns Service domain with assigned suffix and domain name. ``` -------------------------------- ### CustomDomainStatus Struct Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Represents status information for custom domain verification and DNS configuration. ```go type CustomDomainStatus struct { DnsRecords []CustomDomainStatusDnsRecordsDNSRecords VerificationDnsHost string VerificationToken string } ``` -------------------------------- ### Run Acceptance Tests for Terraform Provider Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/CONTRIBUTING.md Executes the full suite of acceptance tests for the Terraform provider. Be aware that these tests create real resources and may incur costs. ```shell make testacc ``` -------------------------------- ### Create a railway project Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/docs/resources/project.md Use this snippet to create a new project on Railway. It requires a name for the project. ```terraform resource "railway_project" "example" { name = "something" } ``` -------------------------------- ### createCustomDomain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a custom domain for a service, enabling access via a user-defined domain name. Includes DNS verification details in the response. ```APIDOC ## createCustomDomain ### Description Creates a custom domain for a service. Returns custom domain with DNS verification details. ### GraphQL Operation `createCustomDomain` ### Input Type `CustomDomainCreateInput` ### Input Parameters - **Domain** (string) - Required - The custom domain name. - **EnvironmentId** (string) - Required - The ID of the environment. - **ProjectId** (string) - Required - The ID of the project. - **ServiceId** (string) - Required - The ID of the service. - **TargetPort** (int) - Optional - The target port for the custom domain. ``` -------------------------------- ### Importing a Service Variable Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-variables.md Demonstrates how to import an existing service variable into Terraform management using its unique ID. ```bash terraform import railway_variable.db_url "variable-id-uuid" ``` -------------------------------- ### createEnvironment Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a new environment within a specified project. This operation takes an EnvironmentCreateInput object with details like environment name and project ID. ```APIDOC ## createEnvironment ### Description Creates a new environment within a project. ### GraphQL Operation `createEnvironment` ### Input Parameters #### EnvironmentCreateInput - **ApplyChangesInBackground** (bool) - Whether to apply changes in the background. - **Ephemeral** (bool) - Whether the environment is ephemeral. - **Name** (string) - The name of the environment. - **ProjectId** (string) - The ID of the project to create the environment in. - **SkipInitialDeploys** (bool) - Whether to skip initial deploys. - **SourceEnvironmentId** (*string) - The ID of the source environment. - **StageInitialChanges** (bool) - Whether to stage initial changes. ``` -------------------------------- ### Configure Cron Job Service Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-service.md Set up a scheduled cron job service. Cron jobs must have exactly one replica across all regions. ```hcl resource "railway_service" "job" { name = "daily-job" project_id = railway_project.app.id source_repo = "myorg/jobs" source_repo_branch = "main" cron_schedule = "0 2 * * *" # 2 AM UTC daily regions { region = "us-east-1" num_replicas = 1 } } ``` -------------------------------- ### Generate Code for Terraform Provider Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/CONTRIBUTING.md Generates or updates documentation and GraphQL client for the Terraform provider. This command is essential for maintaining up-to-date generated files. ```shell go generate ``` -------------------------------- ### PublicRuntime Enumeration Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/types-and-enums.md Specifies the public runtime version for projects. Specified during project creation to determine the runtime environment. ```go type PublicRuntime string const ( PublicRuntimeLegacy PublicRuntime = "LEGACY" PublicRuntimeUnspecified PublicRuntime = "UNSPECIFIED" PublicRuntimeV2 PublicRuntime = "V2" ) ``` -------------------------------- ### Create Service Domain Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a Railway-provided service domain. Requires context, a GraphQL client, and a ServiceDomainCreateInput struct containing the service ID and environment ID. ```go func createServiceDomain(ctx context.Context, client graphql.Client, input ServiceDomainCreateInput) (*CreateServiceDomainResponse, error) ``` ```go type ServiceDomainCreateInput struct { ServiceId string EnvironmentId string } ``` -------------------------------- ### createTcpProxy Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Creates a TCP proxy for a service. Requires ApplicationPort, ServiceId, and EnvironmentId. ```APIDOC ## createTcpProxy ### Description Creates a TCP proxy for a service. ### GraphQL Operation Name `createTcpProxy` ### Input Type `TCPProxyCreateInput` ### Input Parameters - **ApplicationPort** (int) - Required - The application port to proxy. - **ServiceId** (string) - Required - The ID of the service. - **EnvironmentId** (string) - Required - The ID of the environment. ### Returns TCP proxy with assigned proxy port and domain. ``` -------------------------------- ### listCustomDomains Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/graphql-operations.md Lists all custom domains configured for a specific service within a given environment and project. Returns an array of custom domain objects. ```APIDOC ## listCustomDomains ### Description Lists all custom domains for a service in an environment. Returns an array of custom domains. ### GraphQL Operation `listCustomDomains` ### Parameters - **environmentId** (ID!) - Required - The ID of the environment. - **serviceId** (ID!) - Required - The ID of the service. - **projectId** (ID!) - Required - The ID of the project. ``` -------------------------------- ### Import Project Source: https://github.com/terraform-community-providers/terraform-provider-railway/blob/master/_autodocs/resources-project.md Command to import an existing Railway project into Terraform state using its project ID. ```bash terraform import railway_project.example 550e8400-e29b-41d4-a716-446655440000 ```