I have a workflow that runs terraform multiple times. The first invocation runs quickly, but every subsequent run after gets significantly slower
This is my top level Dagger definition
async def run_workflow(apply):
runner_image_tag = os.getenv('INFRA_RUNNER_IMAGE_TAG') #https://github.com/Wi3ard/docker-terraform-gcloud-aws/blob/master/Dockerfile
config = dagger.Config(log_output=sys.stderr, execute_timeout=60)
async with dagger.Connection(config) as client:
runner_image = await infra_runner.build_image_from_tag(runner_image_tag, client)
remote_state_image = await terraform.run_module("remote-state/gcp", runner_image, runner_image_tag, False, client)
project_image = await terraform.run_module("project/gcp", remote_state_image, runner_image_tag, apply, client)
network_image = await terraform.run_module("network/gcp", project_image, runner_image_tag, apply, client)
await terraform.run_module("serverless/gcp/cloudrun", network_image, runner_image_tag, apply, client)
print("All tasks have finished")
async def build_image_from_tag(tag: str, client):
base_image = (
client.container()
.from_(tag)
.exec(["mkdir", "-p", "/output"])
.exec(["mkdir", "-p", "/.terraform.d/plugin-cache"])
)
print(f"Building Docker Image for tag {tag}")
await base_image.exit_code()
return base_image
async def run_module(module: str, image, runner_tag: str, apply: bool, client):
terraform_action = (
client.container()
.from_(runner_tag)
.with_directory("/input", image.directory("/output")
.with_directory(plugin_cache_dir, image.directory(plugin_cache_dir)
.with_mounted_directory("/src",local_src)
# some code here that runs terraform init/plan/apply
)
await terraform_action.exit_code()
return terraform_action
if you're passing the directory forward like this, you need something like an