Generate Environment Files for an Existing Environment
Use the v2-generate-env-files-for-existing-environment job to create V2 environment files for a Self-Managed Commerce environment that is already running in the cluster.
The primary use case is migrating an environment that was previously created and managed with V1 legacy jobs so that it can be managed with v2-configure-commerce-environment going forward.
How It Works
The job inspects the existing environment by reading Terraform state from S3 and querying live Kubernetes resources in the namespace.
It then produces a ready-to-review artifact directory named:
generated-env-<kubernetesNickname>/
That directory contains one or more component YAML files:
commerce-values.yamlactivemq-values.yamlmysql-container.yaml,aurora-mysql-80.yaml,postgres-rds.yaml, orexisting-database.yaml
The generated files reflect the running configuration at the time the job ran.
Before You Run the Job
Complete these two steps before you run the job.
1. Choose a database approach
Decide how V2 will handle the database. This determines the value to use for the databaseAdoptionApproach parameter when you run the v2-generate-env-files-for-existing-environment job.
Choose fully-manage when
- The database server was created by a CloudOps for Kubernetes Jenkins job, and
- You are confident that all configuration changes made to the database server were applied using that CloudOps for Kubernetes Jenkins job, and
- You want to continue managing the database server configuration using the new V2 environment configuration files.
The fully-manage option is safe for Commerce environments using a mysql-container database created by the create-or-delete-mysql-container job.
fully-manage only when there is no config driftThe fully-manage approach reads the database configuration directly from the existing Terraform state file. If the database server's configuration has been changed outside of Terraform since it was originally provisioned, the generated database file will not reflect those changes, and running v2-configure-commerce-environment may attempt to revert them.
If you are unsure, use manage-only-database-secret or do-not-manage instead.
Choose manage-only-database-secret when
- The database server was not configured using a CloudOps for Kubernetes Jenkins job, or it was but changes may have been made outside the job since.
- You will continue to manage the database server configuration outside the CloudOps for Kubernetes Jenkins database jobs.
- You want the JDBC parameters safely stored in an AWS Secrets Manager secret.
Choose do-not-manage when
- You prefer to edit, back up, and manage the database secret manually, and you are confident doing so.
2. Update the environment with the legacy jobs
When you run the v2-generate-env-files-for-existing-environment job with validateGeneratedFiles enabled, it will validate the generated environment configuration files against the existing environment. It performs that validation by running terraform plan using the specified cloudOpsForKubernetesBranch branch and the generated environment configuration files. If that branch has Terraform module changes that were never applied to the environment, the validation reports them as planned changes. The job cannot tell those changes apart from a real mismatch between the generated files and the environment. If failOnValidationDrift is also enabled, the job reports any difference as an error.
To eliminate any false positives or unexpected planned changes, update the environment using the legacy jobs and the same cloudOpsForKubernetesBranch branch before running v2-generate-env-files-for-existing-environment. That ensures all Terraform updates are applied before generating and validating the new V2 environment configuration files.
Run each of these jobs against the environment and let it finish applying, so that all Terraform changes are applied:
create-or-delete-activemq-containerfor ActiveMQ.deploy-or-delete-commerce-stackfor the Commerce stack.- The job that matches your database implementation, only if you chose
fully-manage:create-and-manage-database-serverfor Amazon Aurora MySQL or Amazon RDS for PostgreSQL.create-or-delete-mysql-containerfor a containerized MySQL database.
If you will select either manage-only-database-secret or do-not-manage for databaseAdoptionApproach, do not run a database job.
Job Parameters
kubernetesNickname
The Kubernetes namespace name of the existing Self-Managed Commerce environment.
The job validates that the namespace exists in the cluster before proceeding.
databaseAdoptionApproach
Controls how the database is represented in the generated files.
For guidance on which approach to choose, see Choose a database approach.
| Approach | What it generates |
|---|---|
fully-manage | A database provider file such as aurora-mysql-80.yaml, postgres-rds.yaml, or mysql-container.yaml, populated from Terraform state |
manage-only-database-secret | An existing-database.yaml file with the Amazon Resource Name (ARN) of a newly created Secrets Manager secret |
do-not-manage | No database file. v2-configure-commerce-environment does not touch the database or its Kubernetes secret |
What manage-only-database-secret does
When you select manage-only-database-secret, the job reads the existing Kubernetes database secret in the namespace and creates or updates an AWS Secrets Manager secret named ep-c4k/rdbms/<kubernetesNickname>. The generated existing-database.yaml file references the ARN of that Secrets Manager secret.
This lets v2-configure-commerce-environment manage and update the Kubernetes database secret going forward, without attempting to manage the database server infrastructure itself.
validateGeneratedFiles
When enabled, the job runs Terraform plans against the generated files using the live environment state.
This is a read-only sanity check. It does not apply changes.
Terraform module changes on the selected branch that were never applied to the environment also appear as planned changes. To avoid these false positives, complete the steps in Before You Run the Job first.
If one or more Terraform modules show planned changes, review the plan output carefully before committing the files or running v2-configure-commerce-environment.
failOnValidationDrift
When enabled together with validateGeneratedFiles, the job fails if any Terraform module shows planned changes or if plan output is missing.
This is mainly useful for internal validation automation.
Output
The job produces these build artifacts:
generated-env-<kubernetesNickname>/*.yaml- Generated component files, ready to review and commit.generate_env_spec.log- The full Ansible output log for troubleshooting.
Where the job can determine a value from the running environment, it fills it in. Where a value cannot be determined automatically, a generated file may contain a # TODO: comment indicating that manual input is required before the file is committed.
All values in the generated YAML files reflect the state of the running environment at the time the job ran. Review every field before committing, paying particular attention to any # TODO: comments.
Sensitive values such as SSH and GNU Privacy Guard keys are intentionally not included in the generated files. If the environment uses a secure config repository, retrieve those values from the commerce-stack-secret Kubernetes secret and add them manually only if your team intentionally stores those values in Git.
After the Job Runs
Option: Start with one component at a time (optional)
When you first start using the new configuration approach, you may prefer to start small. Instead of committing and applying all generated files at once, you can start incrementally by adding one component at a time.
Start with ActiveMQ.
- Download the
activemq-values.yamlfile from the build artifacts. - Commit only
environments/<kubernetesNickname>/activemq-values.yaml. - Run
v2-configure-commerce-environmentwithplanOnlyset totrue. WhenplanOnlyis set, the job will make no changes. LeavedataPopCommandset tonone. - Review the Terraform plan printed in the console output. It should say that no changes will be made. If any changes would be made, investigate what they are and why they would happen.
- When you are satisfied that no unexpected changes would be made, run
v2-configure-commerce-environmentagain withplanOnlyset tofalse. LeavedataPopCommandset tonone.
Repeat the above for your database environments/<kubernetesNickname>/*.yaml file, unless you chose the do-not-manage option.
Repeat the above steps for the environments/<kubernetesNickname>/commerce-values.yaml file.
Option: Commit all files
-
Download all of the generated YAML files from the build artifacts.
-
Review every file. Refer to
environments/reference/for the full field reference. -
Commit the reviewed files to your CloudOps for Kubernetes repository under folder
environments/<kubernetesNickname>/. -
Run
v2-configure-commerce-environmentin plan mode, with:envFileSource:fromGitkubernetesNickname: the same value you used when checking the files into Git.planOnlyset totrue
Validate the first runOn the first run of
v2-configure-commerce-environmentagainst a migrated environment, review the archived Terraform log artifacts carefully. If the generated files accurately reflect the running environment, the database, ActiveMQ, and Commerce stack applies should report no changes. -
When ready, run
v2-configure-commerce-environmentin apply mode, with:envFileSource:fromGitkubernetesNickname: the same value you used when checking the files into Git.planOnlyset tofalse