Skip to main content
Version: v3.3 print this page

Driver File

The driver file is the entry point for executing the Amorphic CICD Utils module. This file is executed inside the pipeline. Below is the minimal structure required for the driver file:

import os
from amorphiccicdutils import ResourceManager

AMORPHIC_AUTH_TOKEN = os.getenv('AMORPHIC_AUTHORIZATION_TOKEN')
AMORPHIC_BASE_URL = os.getenv('AMORPHIC_BASE_URL')
AMORPHIC_ROLE_ID = os.getenv('AMORPHIC_ROLE_ID')
AMORPHIC_LOG_FILE = os.getenv('LOG_FILE')
AMORPHIC_LOG_LEVEL = os.getenv('LOG_LEVEL')

rm = ResourceManager(
"./resources",
amorphic_auth_token=AMORPHIC_AUTH_TOKEN,
amorphic_base_url=AMORPHIC_BASE_URL,
amorphic_role_id=AMORPHIC_ROLE_ID,
validate_resource_properties=True,
)

rm.plan()
rm.execute()

The driver file must be named driver_file.py and this name must not be changed.

The file can be customized to accommodate advanced use cases. For example, if users need to retrieve values from the Amorphic Parameter Store, the driver file can be extended as follows:

import os
import requests
from amorphiccicdutils import ResourceManager

AMORPHIC_AUTH_TOKEN = os.getenv('AMORPHIC_AUTHORIZATION_TOKEN')
AMORPHIC_BASE_URL = os.getenv('AMORPHIC_BASE_URL')
AMORPHIC_ROLE_ID = os.getenv('AMORPHIC_ROLE_ID')
AMORPHIC_LOG_FILE = os.getenv('LOG_FILE')
AMORPHIC_LOG_LEVEL = os.getenv('LOG_LEVEL')


def get_parameter_from_amorphic(parameter_name):
"""
Retrieve a parameter from the Amorphic Parameter Store.
"""
response = requests.get(
f"{AMORPHIC_BASE_URL}/parameters/{parameter_name}",
headers={
"Content-Type": "application/json",
"Authorization": AMORPHIC_AUTH_TOKEN,
"role_id": AMORPHIC_ROLE_ID
},
timeout=10,
)
return response.json()["ParameterValue"]


# Example: retrieving connection credentials from Amorphic Parameter Store
os.environ["CONN_USERNAME"] = get_parameter_from_amorphic("CONN_USERNAME")
os.environ["CONN_PASSWORD"] = get_parameter_from_amorphic("CONN_PASSWORD")

rm = ResourceManager(
"./resources",
amorphic_auth_token=AMORPHIC_AUTH_TOKEN,
amorphic_base_url=AMORPHIC_BASE_URL,
amorphic_role_id=AMORPHIC_ROLE_ID,
validate_resource_properties=True,
)

rm.plan()
rm.execute()

Configuration Options

The first argument to the ResourceManager class specifies the root directory containing all resource definition JSON files. If you are following the recommended project structure, this value should be set to ./resources. If your resources are organized under a different folder, update this path accordingly.

Authentication requires three attributes:

amorphic_auth_token: Authentication token provided as an environment variable.

amorphic_base_url: Base API endpoint for Amorphic, provided as an environment variable.

amorphic_role_id: Role identifier for authorization, provided as an environment variable.

If you are running within the Amorphic Infrastructure, these values are automatically available as environment variables and can be used directly.

Additional options include:

validate_resource_properties: Boolean flag (default: True). Enables schema validation for resource property definitions. Set to False to skip validation.

Logging configuration:

Set LOG_LEVEL environment variable (values 1–3 for increasing verbosity).

Set LOG_FILE to "true" to generate a log file named amorphic_cicd.log after execution.

Execution Phases

The CICD Utils module executes in two phases.

Planning Phase

  • Parses the resource definitions.
  • Validates schema requirements.
  • Creates an execution plan that determines the correct order of resource creation.

Execution Phase

  • Executes the plan generated in the planning phase.
  • Creates resources in Amorphic.

Running only the planning phase does not create resources. The execution phase must always follow the planning phase.