perfectsense / gyro

Gyro is a command-line tool for creating, updating, and maintaining cloud infrastructure. Gyro makes infrastructure-as-code possible.
https://gyro.dev
Apache License 2.0
134 stars 7 forks source link

Allow @for to work inside @workflow::define stages #349

Closed beetlebugorg closed 3 years ago

beetlebugorg commented 3 years ago

Workflow stages don't work with @for.

Example workflow stage (single stage for brevity):

db-restore-id: restore
cluster-name: test
@workflow::define aws::db-cluster replace-db-cluster

    stage create-db-cluster
        confirm-diff: true

        # Create new Database Cluster
        @workflow::create aws::db-cluster "$(cluster-name)-primary $(db-restore-id)"
            @extends: $(aws::db-cluster "$(cluster-name)-primary aurora") -exclude ['arn', 'identifier']

            identifier: "$(cluster-name)-primary-$(db-restore-id)"
        @end

        # Create new Database Instances
        @for create-zone -in $bsp-cloud-zones
            @workflow::create aws::db-instance "$(cluster-name)-primary $(create-zone) $(db-restore-id)"
                @extends: $(aws::db-instance "$(cluster-name)-primary $(create-zone)")

                identifier: "$(cluster-name)-primary-$(create-zone)-$(db-restore-id)"
                db-cluster: "$(cluster-name)-primary-$(db-restore-id)"
            @end
        @end
    end

    .
    .

@end

Expected output:

⇅ Replacing aws::db-cluster test-primary aurora (test-primary-restore)
~ Executing replace-db-cluster workflow
· Executing create-db-cluster stage
    + Create aws::db-cluster test-primary restore (test-primary-restore)
    + Create aws::db-instance test-primary us-east-1a restore (test-primary-us-east-1a-restore)
    + Create aws::db-instance test-primary us-east-1b restore (test-primary-us-east-1b-restore)
    + Create aws::db-instance test-primary us-east-1c restore (test-primary-us-east-1c-restore)

    Continue with create-db-cluster stage? (Y/n) n

Actual output:

⇅ Replacing aws::db-cluster test-primary aurora (test-primary-restore)
~ Executing replace-db-cluster workflow
· Executing create-db-cluster stage
    + Create aws::db-cluster test-primary restore (test-primary-restore)

    Continue with create-db-cluster stage? (Y/n) n