Documentation
¶
Overview ¶
Package tfgen generates a fully-formed OpenTofu working directory for the Gothic AWS stack. The base .tf.json files are embedded in the CLI binary and are NEVER seeded onto the user's project disk. They use OpenTofu's own "${var.*}" interpolation syntax (NOT Go text/template "{{...}}" markers) so they remain valid JSON consumable directly by OpenTofu. Per-deployment values are supplied at runtime via a generated vars.tf.json, and environment-variable sources (raw / SSM / Secrets Manager) are resolved via a generated env_resolved.tf.json. This mirrors the embed pattern used by pkg/helpers/wasm/wasm_templates.go.
Index ¶
- Variables
- func GcpDomainLocal(v *config.EnvValue) (string, error)
- func GcpEnvLocals(env map[string]config.EnvValue) (map[string]string, error)
- func GcpResources(params TfGenParams) map[string]interface{}
- func QuoteBracketKey(key string) string
- func WriteGcpOutputs(workDir string) error
- func WriteGcpResources(workDir string, params TfGenParams) error
- type Generator
- type TfGenParams
Constants ¶
This section is empty.
Variables ¶
var TofuTemplateFS embed.FS
Functions ¶
func GcpDomainLocal ¶
GcpDomainLocal resolves the custom-domain EnvValue into local.custom_domain, with the same raw-only restriction as the env entries. An empty string keeps resources that reference the local resolvable when no domain is declared.
func GcpEnvLocals ¶
GcpEnvLocals resolves the stage's ENV map into the locals.env_vars values, failing loudly when a value uses a source GCP cannot resolve.
func GcpResources ¶
func GcpResources(params TfGenParams) map[string]interface{}
GcpResources returns the base resources.tf.json for GCP: the Cloud Run service, the GCS asset bucket, and — when the stage declares a CustomDomain — the Cloud Run domain mapping that serves it with a Google-managed TLS certificate (provisioned automatically once the domain is verified).
Everything the config object carries for GCP is materialized here:
- params.EnvVars → the container's environment (on top of GOTHIC_PROVIDER)
- params.CustomDomain → enable_domain_mapping + local.custom_domain
- params.Project/Region → provider wiring (main.tf.json)
Key differences from AWS:
- Cloud Run service instead of Lambda Function
- GAR instead of ECR
- GCS bucket instead of S3
- No CloudFront CDN (static assets served directly or via Cloud CDN)
- No VPC attachment needed (Cloud Run handles networking)
Memory, timeout, and concurrency use Cloud Run's service defaults; the container maps HTTP port 8080 (the Cloud Run $PORT contract).
func QuoteBracketKey ¶
QuoteBracketKey wraps a locals map key into the bracket interpolation local.env_vars["K"] — safe for keys that are not valid TF identifiers.
func WriteGcpOutputs ¶
WriteGcpOutputs writes gothic_outputs.tf.json for GCP: a `locals` block re-exporting the Gothic stack's key resource attributes under STABLE `gothic_*` names. This is the public contract user infra/ files build against (attaching a Cloud Armor policy, granting a service account access to the bucket) — it decouples them from Gothic's internal resource addresses, which may change.
func WriteGcpResources ¶
func WriteGcpResources(workDir string, params TfGenParams) error
WriteGcpResources writes resources.tf.json into workDir from GcpResources. The GCP resource set is generated rather than embedded because the container env list depends on the stage's config ENV entries.
Types ¶
type Generator ¶
type Generator struct{}
Generator materialises an OpenTofu working directory for the AWS Gothic stack.
func (*Generator) Prepare ¶
func (g *Generator) Prepare(workDir string, params TfGenParams) error
Prepare writes a complete OpenTofu working directory into workDir:
- the embedded base .tf.json files (provider/backend, variables, resources, outputs)
- a generated vars.tf.json supplying concrete defaults for every variable
- a generated env_resolved.tf.json resolving env-var sources (raw/SSM/Secrets Manager)
- a gothic_outputs.tf.json placeholder
- a generated gothic_cache_policy.tf.json (the CloudFront server cache policy)
It NEVER writes to the user's project directory; only workDir is touched.
type TfGenParams ¶
type TfGenParams struct {
// Provider selects which cloud's stack is generated. Its zero value is AWS
// (the Provider enum's first entry), so callers that leave it unset get the
// AWS stack unchanged.
Provider config.Provider
// GcpProject is the GCP project ID the GCP stack deploys into (the google
// provider's project argument). AWS stacks ignore it.
GcpProject string
ProjectName string
Stage string
Suffix string
Region string
Profile string
ServerMemory int
ServerTimeout int
ECRImageURI string
BucketName string
LambdaName string
StateBucket string
LockTable string
EnvVars map[string]config.EnvValue
// The custom-domain fields are source-aware EnvValues (raw / SSM / Secrets
// Manager), resolved into locals by writeEnvResolved exactly like EnvVars. A nil
// pointer means the stage did not declare that field.
WafArn *config.EnvValue
CustomDomain *config.EnvValue
HostedZoneId *config.EnvValue
CertificateArn *config.EnvValue
// CDN drives the generated aws_cloudfront_cache_policy.server (which query params,
// cookies, and headers the dynamic/Lambda behavior folds into the cache key and
// forwards to the origin). Its zero value = all query params, no cookies, no
// headers. See writeCachePolicy.
CDN config.CDNConfig
// InfraDir is the user's custom-infrastructure directory (cwd-relative, like
// the "public/" asset dir). Every *.tf / *.tf.json file directly inside it is
// merged flat into workDir so the user's resources land in the SAME module +
// state as the Gothic stack, and can reference the stable local.gothic_*
// contract. Empty or absent → no-op. Non-.tf files are ignored.
InfraDir string
}
TfGenParams carries every concrete per-deployment value the generator needs to materialise vars.tf.json and env_resolved.tf.json. The base .tf.json files reference these via "${var.*}" / "${local.env_vars}".