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 should get triggered based on declared file #343

Closed deepanjan90 closed 3 years ago

deepanjan90 commented 3 years ago

Describe the bug If two or more workflows are defined in different files that work on the same type of resource, Gyro confuses which workflow to use causing an error.

To Reproduce gyro up two separate configs with a common resource and a workflows that can target that. *Note: Name the workflow differently to know which one gets triggered.

campaigns/vpc.gyro

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

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

        @workflow::create aws::vpc "verify"
            cidr-block: "20.0.0.0/16"
            tags: {
                Name: "vpc-example-campaigns-verify"
            }
        @end

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

    stage update-verify-vpc
        confirm-diff: true

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

        transition finish
            to: finish
        end
    end

    stage finish
        confirm-diff: true
        @workflow::replace: $(aws::vpc vpc-campaigns) $(aws::vpc verify)
    end
@end

cmc/vpc.gyro

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

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

        @workflow::create aws::vpc "verify"
            cidr-block: "20.0.0.0/16"
            tags: {
                Name: "vpc-example-cmc-verify"
            }
        @end

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

    stage update-verify-vpc
        confirm-diff: true

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

        transition finish
            to: finish
        end
    end

    stage finish
        confirm-diff: true
        @workflow::replace: $(aws::vpc vpc-cmc) $(aws::vpc verify)
    end
@end

Gyro up both the files. Edit the cidr of one of the files and gyro up.

gyro up campaigns/vpc.gyro --verbose
⟳ Refreshed resources: 2

Looking for changes...

⇅ Replace aws::vpc vpc-campaigns (vpc-06615d56fa4b0e333) (because of cidr-block, using deploy-cmc)
· cidr-block:  '10.0.0.0/16' → '20.0.0.0/16'

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

Aborted!

Notice that the wrong workflow is triggered.

Expected behavior The workflow specific to the resource and the file it is defined in should get triggered.