GitHub
11/30/2024, 12:35 AMmeltano.yml as static config and in various formats (e.g. URI vs. separate username, password, database). By introducing a first class 'resource' representation in Meltano that can i) be managed using the CLI/in meltano.yml and ii) be referenced by its alias/id within Meltano (environments, tap/target configs etc.) we provide a way for tools like Terraform to 'hand-off' resource details (including secrets) to Meltano, and for those details to change (if necessary) without breaking existing references within the Meltano Project (as resources are referenced by their alias/id rather than by hard-coded attributes, servicing use-cases like automated password rotation).
Proposal
• A yaml spec for 'resources' under a top-level 'inventory' key.
• CLI additions to manage resources (and secrets), accepting inputs in JSON (on the basis that Terraform can format its output in these formats).
Note: the reference syntax below (e.g. "{{ .inv... }}") is very much up for debate. We may need to follow the Jinja macro style if we use that engine for templating/referencing. The ones shown are Helm style, which I believe uses the templating language built in to Golang.
# Example definition
inventory:
- id: prod-meltano-database
type: database_postgres
properties:
host: "<hostname>"
port: "<port>"
username: "<user name>"
password: "<default password>" # ideally this would be a ref to a secret value added separately
database: "<optional: default database>"
schema: "<optional: default schema>"
uri: "<optional: sqlalchemy uri>" # this can maybe be inferred
- id: prod-s3-bucket
type: aws_s3_bucket
properties:
name: "<s3 bucket name>"
prefix: "<optional: default prefix>"
profile: "<optional: aws profile name>"
aws_access_key_id: "<optional: aws access key id>" # ideally this would be a ref to a secret value added separately
aws_secret_access_key: "<optional: aws secret access key>" # ideally this would be a ref to a secret value added separately
- id: prod-snowflake-load
type: snowflake_warehouse
properties:
account: "<snowflake account name>"
database: "<snowflake database name>"
region: "<warehouse region>"
warehouse: "<snowflake warehouse name>"
username: "<user name>"
password: "<password>" # ideally this would be a ref to a secret value added separately
role: "<snowflake role>"
session_parameters: "<session level parameters>"
# Example usage
environments:
- name: prod
config:
plugins:
loaders:
- name: target-snowflake
config:
db_name: "{{ .inv.prod-snowflake-load.database }}" # References resources defined above
account: "{{ .inv.prod-snowflake-load.account }}"
user: "{{ .inv.prod-snowflake-load.username }}"
role: "{{ .inv.prod-snowflake-load.username }}"
load_schema: "${TAP_NAMESPACE}_raw" # Dynamic from the name of the currently-executing tap
In Terraform, resources may be defined using the same schema as above as regular output blocks:
output "meltano" {
value = [
{
id = "prod-meltano-database"
type = "database_postgres"
properties = {
host = module.db.db_instance_endpoint
port = module.db.db_instance_port
user = module.db.db_instance_username
password = {
type = "secret"
value = module.db.db_instance_password
}
database = module.db.db_instance_name
}
}
]
}
The user experience might be:
# make changes to infrastructure
terraform apply
# output 'meltano' output name to file 'resources.json'
terraform output -json meltano > resources.json
# read 'resources.json'
meltano config inventory update -file resources.json
Or, eventually:
meltano invoke -update-resources terraform apply
meltano/meltanoGitHub
11/30/2024, 12:35 AM