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

Workflow action fails if it references a resource having a variable which needs resolving #342

Closed deepanjan90 closed 3 years ago

deepanjan90 commented 3 years ago

Describe the bug Gyro errors on executing workflow if the workflow action has a reference resource with a variable that needs resolving.

To Reproduce gyro up

ver: "verify"
aws::vpc vpc
    cidr-block: "10.0.0.0/16" #20.0.0.0/16 <-- update to this to trigger workflow
    tags: {
        Name: "vpc-example"
    }
end

@workflow::define aws::vpc deploy
    stage create-verify-vpc
        confirm-diff: true

        @workflow::create aws::vpc "$(ver)"
            cidr-block: "20.0.0.0/16"
            tags: {
                Name: "vpc-example-$(ver)"
            }
        @end

        transition update-verify-vpc
            to: update-verify-vpc
        end
    end

    stage update-verify-vpc
        confirm-diff: true

        @workflow::update $(aws::vpc $(ver))
            tags: {
                Name: "vpc-example-$(ver)-update"
            }
        @end

        transition finish
            to: finish
        end
    end

    stage finish
        confirm-diff: true

        @workflow::replace: $(aws::vpc vpc) $(aws::vpc $(ver))
    end
@end

Update the cidr to trigger the workflow

$ ../../gyro/cli/dist/gyro up ec2/vpc.gyro --verbose
⟳ Refreshed resources: 1

Looking for changes...

⇅ Replace aws::vpc vpc (vpc-01b713b66be751977) (because of cidr-block, using deploy)
· cidr-block:  '10.0.0.0/16' → '20.0.0.0/16'

Are you sure you want to change resources? (y/N) y

⇅ Replacing aws::vpc vpc (vpc-01b713b66be751977)
· cidr-block:  '10.0.0.0/16' → '20.0.0.0/16'

~ Executing deploy workflow
· Executing verify stage

    + Create aws::vpc verify
    · cidr-block: '20.0.0.0/16'
    · tags: { Name: 'vpc-example-verify' }

    Continue with verify stage? (Y/n) y

    + Creating aws::vpc verify
    · cidr-block: '20.0.0.0/16'
    · tags: { Name: 'vpc-example-verify' }
    OK

· Executing verify-finish stage

Error: Can't resolve ver!

In ec2/vpc.gyro on line 30 from column 39 to 44:
29:     stage verify-finish
30:         @workflow::update $(aws::vpc "$(ver)")
31:             tags: {

Expected behavior Gyro should be able to resolve the variable and able to execute the workflow.