Generated Values
GeneratedValue is a value generated once and kept in state: a database password, an API token,
a random suffix, a CA and the TLS certificates it signs. It is what hashicorp/random's
random_password and hashicorp/tls's certificates are often used for, without those providers:
hybrid execution runs it in-process, so there is no provider binary to install, cache or bundle,
and the stack needs no provider declaration for it.
from nf.core import App, GeneratedValue, Output, Stack
app = App(nf_id="installer")
stack = Stack(nf_scope=app, nf_id="database")
admin_password = GeneratedValue(
nf_scope=stack,
nf_id="admin_password",
generator="password",
params={"length": 32, "min_special": 2, "override_special": "-_!"},
keepers={"rotation": "2026-11"},
)
Output(nf_scope=stack, nf_id="admin_password", value=admin_password.result, sensitive=True)
Other resources take the value as they take any attribute: password=admin_password.result.
How It Behaves
It is the nf_generated_value resource of Netherframe's built-in provider,
netherframe.arsenal.sh/builtin/nf. Types starting nf_ imply that provider, as terraform_*
types imply Terraform's, so it never takes a resource from a stack's declared providers, nor they
from it.
| Event | What happens |
|---|---|
| First apply | The generator runs; result (sensitive) and id are recorded in state |
| Later plans | No change: refreshing it returns what state keeps, so it never drifts |
generator, params or keepers change |
The value is replaced with a new one (a TLS generator's early_renewal_hours alone is updated in place) |
A params or keepers value not known until apply |
The value is replaced, as Terraform replaces random_password |
| Its renewal falls due (a TLS certificate) | The plan replaces it, ready_for_renewal forcing the replacement |
nf state taint (or taint_resource) |
The next apply replaces the value |
| Destroy, or removing it from the app | The entry is removed from state |
Plans show the value as unknown until it is generated, and an output of it (result, values
or value(name)) needs sensitive=True to stay out of plan summaries. Like every attribute a provider marks sensitive,
the value is stored in state, saved plan files and checkpoints in plain text: protect them as you
protect any state.
Recovery strategies treat it like any resource: CHECKPOINT keeps a value generated by a failed
apply in state, so the next apply does not generate another; ROLLBACK deletes it with the other
resources the failed apply created.
Generators
| Generator | Parameters |
|---|---|
password |
length (16), upper, lower, numeric, special (all true), override_special, min_upper, min_lower, min_numeric, min_special (all 0), as random_password |
hex |
length (32): lower-case hexadecimal digits |
uuid |
None: a random version 4 UUID |
tls_ca |
A self-signed CA; see TLS Certificates |
tls_cert |
A key and certificate signed by a CA; see TLS Certificates |
Generators are named, never passed as callables, so plans and state name them as data, as runtime
checks are. A package adds generators under the nf.generators entry-point group; the entry
point's name is the generator's, and it loads a function taking the parameters as keyword
arguments and returning a string, or a mapping of strings for several named values (the first is
result):
[project.entry-points."nf.generators"]
pin = "my_package.generators:pin"
import secrets
def pin(digits: int = 6) -> str:
return "".join(secrets.choice("0123456789") for _ in range(digits))
register_generator(name, function) in netherframe.core.providers.generators registers one
from code. Parameters are checked against the function's signature when the plan validates the
resource, and the function runs once, when the resource is created. Registering (or loading from
the entry point) a GeneratorDefinition instead of a function adds a check of the parameters'
values at validation, a renew_after time from which plans replace the value, the parameters it
takes write-only, those whose change keeps the value and update_values, which brings the named
values up to date after such a change, as the TLS generators have.
TLS Certificates
tls_ca makes a CA (a new key and a self-signed certificate that is a CA's), and tls_cert a new
key and a certificate that CA signs, for the names a TLS server or client presents: Kafka's
external listeners, a log gateway. They are hashicorp/tls's tls_private_key,
tls_self_signed_cert and tls_locally_signed_cert, kept in state by the same resource.
from nf.core import App, GeneratedValue, Output, Stack
app = App(nf_id="installer")
stack = Stack(nf_scope=app, nf_id="pki")
ca = GeneratedValue(
nf_scope=stack,
nf_id="ca",
generator="tls_ca",
params={"common_name": "Example Kafka CA", "organization": "Example", "validity_period_hours": 87600, "early_renewal_hours": 720},
)
broker = GeneratedValue(
nf_scope=stack,
nf_id="broker",
generator="tls_cert",
params={
"ca_cert_pem": ca.value("cert_pem"),
"common_name": "kafka",
"dns_names": ["kafka-0.example.internal", "kafka.example.internal"],
"ip_addresses": ["10.0.0.7"],
"validity_period_hours": 8760,
"early_renewal_hours": 720,
"allowed_uses": ["digital_signature", "key_encipherment", "server_auth", "client_auth"],
},
write_only_params={"ca_private_key_pem": ca.value("private_key_pem")},
)
Output(nf_scope=stack, nf_id="ca_cert", value=ca.value("cert_pem"), sensitive=True)
Output(nf_scope=stack, nf_id="broker_cert", value=broker.value("cert_pem"), sensitive=True)
Output(nf_scope=stack, nf_id="broker_key", value=broker.value("private_key_pem"), sensitive=True)
Both return several named values, which values (a map) holds and value(name) (or
values["name"]) refers to; result is the first, cert_pem. A generator returning one string
(password) keeps its result as before and a null values.
| Value | What it is |
|---|---|
cert_pem |
The certificate (PEM) |
private_key_pem |
Its key, PKCS#8 PEM (-----BEGIN PRIVATE KEY-----), which OpenSSL and Kafka's ssl.keystore.type=PEM read |
public_key_pem |
Its public key (PEM) |
ca_cert_pem |
tls_cert only: the certificate of the CA that signed it, for a chain or a trust store |
not_before, not_after |
Its validity (RFC 3339, UTC) |
serial_number |
Its serial number (decimal) |
| Parameter | Generators | Meaning |
|---|---|---|
validity_period_hours |
both (required) | Requested lifetime from creation; tls_cert expires no later than its CA |
early_renewal_hours |
both (0) | How long before not_after a plan replaces it; changing it alone replaces nothing |
common_name, organization, organizational_unit, country, province, locality |
both (common_name required for tls_ca) |
The subject |
key_algorithm |
both (ECDSA) |
ECDSA, RSA or ED25519 |
ecdsa_curve |
both (P256) |
P256, P384 or P521; it also picks the signature hash (SHA-256, -384, -512) |
rsa_bits |
both (2048) | At least 2048 |
allowed_uses |
both | hashicorp/tls's names: key usages (digital_signature, key_encipherment, cert_signing, crl_signing, ...) and extended ones (server_auth, client_auth, code_signing, ...). tls_ca: cert_signing, crl_signing, digital_signature; tls_cert: digital_signature, key_encipherment, server_auth |
max_path_length |
tls_ca |
The CA's path length constraint (none by default) |
ca_cert_pem |
tls_cert (required) |
The CA's certificate: ca.value("cert_pem") |
ca_private_key_pem |
tls_cert (required, in write_only_params) |
The CA's key: ca.value("private_key_pem") |
dns_names, ip_addresses, uris |
tls_cert |
Its subject alternative names |
pkcs12 and the other pkcs12_* |
both | PKCS#12 bundles for Java; see PKCS#12 Keystores and Truststores |
The CA certificate is always a CA's (basic constraints, critical) and a certificate never is; both get subject and authority key identifiers. Parameters are checked when the plan validates the resource, those not known yet (the CA's, before it exists) once they are.
The CA's Key Stays Out of the Certificate's State
write_only_params is a write-only argument, as Terraform's *_wo arguments are: apply hands it
to the generator, from the CA's state entry through the reference, and neither the certificate's
state entry nor a plan keeps it. tls_cert takes ca_private_key_pem only there (a plan given
it in params fails), so the CA's key is stored once, in the CA's entry. A saved plan for a
certificate not created yet holds no key, so apply it with the app loaded, as any plan setting a
write-only argument.
The certificate's params hold the CA certificate (public) instead, so the CA and its
certificates are linked as any resources referring to each other are:
- the reference orders the CA's creation before the certificate's, in one apply
- while the CA is not created (or is being replaced) the certificate's
ca_cert_pemis unknown, which validation skips and which replaces an existing certificate - so replacing the CA, for a
keeperschange, a taint or its renewal, replaces every certificate it signed, in the same apply; changing a certificate's names replaces that certificate alone
Renewal
A plan replaces a certificate from early_renewal_hours before its not_after (from not_after
itself with none), as hashicorp/tls's ready_for_renewal does: the plan names
ready_for_renewal as the path forcing the replacement. The time is that of the plan, so a stack
nobody plans keeps an expired certificate: plan it on a schedule shorter than
early_renewal_hours. A CA renewed this way replaces its certificates with it.
tls_cert caps the certificate's expiration at the CA's expiration, including when the CA has
less than an hour left. Its PEM, not_after value and optional PKCS#12 keystore all use that
actual expiration, and renewal is scheduled from it. Issuance fails if the CA is expired or
not yet valid, or if the shortened lifetime is already inside early_renewal_hours: renew the
CA first or reduce the leaf's renewal window. Set the CA's own renewal window early enough
to replace it before its certificates need renewal.
Existing certificates stored in state are kept until replaced or renewed; this change does not
rewrite them. To correct a previously generated certificate that outlives its CA immediately,
force replacement by changing its keepers or tainting it, then apply.
As with every generated value, both keys are kept in state (the CA's in the CA's entry, each certificate's in its own), in checkpoints, and in the prior state a saved plan carries, in plain text: protect them as you protect any state.
PKCS#12 Keystores and Truststores
Java services (Kafka, Elasticsearch, Tomcat) usually read a key and its chain from a PKCS#12
keystore and the CAs they trust from a PKCS#12 truststore. With pkcs12 set, tls_cert also
returns its keystore and tls_ca a truststore, each base64-encoded (standard alphabet, no line
breaks) so it fits a JSON document or a Secrets Manager string:
| Value | Generator | What it is |
|---|---|---|
keystore_p12_base64 |
tls_cert |
Its key and certificate as one private key entry, with the CA's certificate as its chain (length 2) |
keystore_password |
tls_cert |
The keystore's password, when it was generated (not when given) |
truststore_p12_base64 |
tls_ca |
The CA's certificate as a trusted certificate entry (trustedCertEntry) |
truststore_password |
tls_ca |
The truststore's password, when it was generated (not when given) |
| Parameter | Default | Meaning |
|---|---|---|
pkcs12 |
False |
Return the bundle |
pkcs12_password |
generated | The bundle's password, in write_only_params only (a plan given it in params fails) |
pkcs12_alias |
common_name (certificate for a tls_cert without one) |
The entry's alias |
pkcs12_legacy_encryption |
False |
Encrypt with 3DES and SHA-1 instead of AES-256 and PBKDF2, for JVMs older than 8u301 and 11.0.12, which cannot read the default |
pkcs12_password_version |
none | Any string or number: changing it makes the bundle again with the pkcs12_password now configured |
Without pkcs12_password a password is generated (32 URL-safe characters) and returned as
keystore_password or truststore_password, kept in state like the bundle. A password you pass
is write-only, as the CA's key is: the bundle encrypted with it is kept, the password is not, so
there is no *_password value and the service reads the password from wherever you keep it.
State keeps no write-only value to compare, so changing pkcs12_password alone changes nothing:
change pkcs12_password_version with it.
The bundles are made with the certificate, so whatever makes a new certificate (renewal, a change
of names or other parameters, keepers, a taint, a new CA) makes new bundles in the same apply.
Changing only the pkcs12* parameters keeps the key and certificate: the apply makes the bundle
again from those in state (the plan shows it as an update, the bundle known after apply), keeping
a generated password, and turning pkcs12 off removes the bundle and its password. The
truststore needs only the CA's certificate and the keystore only the CA's certificate besides the
leaf's own key, so the CA's key still never reaches a certificate's state.
A Kafka broker with mutual TLS, its stores written from the outputs to files the broker reads:
from nf.core import App, GeneratedValue, Output, Stack
app = App(nf_id="installer")
stack = Stack(nf_scope=app, nf_id="pki")
ca = GeneratedValue(
nf_scope=stack,
nf_id="ca",
generator="tls_ca",
params={"common_name": "Example Kafka CA", "validity_period_hours": 87600, "early_renewal_hours": 720, "pkcs12": True},
)
broker = GeneratedValue(
nf_scope=stack,
nf_id="broker",
generator="tls_cert",
params={
"ca_cert_pem": ca.value("cert_pem"),
"common_name": "kafka-0",
"dns_names": ["kafka-0.example.internal"],
"validity_period_hours": 8760,
"early_renewal_hours": 720,
"allowed_uses": ["digital_signature", "key_encipherment", "server_auth", "client_auth"],
"pkcs12": True,
},
write_only_params={"ca_private_key_pem": ca.value("private_key_pem")},
)
Output(nf_scope=stack, nf_id="broker_keystore", value=broker.value("keystore_p12_base64"), sensitive=True)
Output(nf_scope=stack, nf_id="broker_keystore_password", value=broker.value("keystore_password"), sensitive=True)
Output(nf_scope=stack, nf_id="truststore", value=ca.value("truststore_p12_base64"), sensitive=True)
Output(nf_scope=stack, nf_id="truststore_password", value=ca.value("truststore_password"), sensitive=True)
# server.properties: the files are the outputs, base64-decoded
listeners=SSL://kafka-0.example.internal:9093
security.inter.broker.protocol=SSL
ssl.client.auth=required
ssl.endpoint.identification.algorithm=https
ssl.keystore.type=PKCS12
ssl.keystore.location=/etc/kafka/secrets/kafka-0.keystore.p12
ssl.keystore.password=<broker_keystore_password>
ssl.key.password=<broker_keystore_password>
ssl.truststore.type=PKCS12
ssl.truststore.location=/etc/kafka/secrets/truststore.p12
ssl.truststore.password=<truststore_password>
The key's password is the keystore's: a PKCS#12 bundle encrypts both with one. Kafka 2.7 and
later also read PEM directly (ssl.keystore.type=PEM with ssl.keystore.certificate.chain and
ssl.keystore.key, ssl.truststore.type=PEM with ssl.truststore.certificates), from
cert_pem, ca_cert_pem and private_key_pem, which needs no bundle or password at all.
Limits
- Hybrid execution only: Terraform synthesis rejects a stack with a
GeneratedValue, since Terraform has nonetherframe.arsenal.sh/builtin/nfprovider. Userandom_passwordthere. - It cannot be imported: the value exists only in state.
- The TLS generators make no certificate signing requests, CRLs or intermediate CAs, and take no
existing key: a CA made elsewhere signs through
ca_cert_pemandca_private_key_pemall the same, its key coming from wherever the stack reads it.