Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Provisioner example with ability to trigger dynamic provider change #513

Merged
merged 5 commits into from
May 5, 2020

Conversation

praneetloke
Copy link
Contributor

This PR updates the provisioner example with a new property in the ConnectionArgs interface that allows a user to provide a value, which can trigger a replacement should the value change. An ideal source of values is a hash calculated from the file itself. As the file changes, the dynamic provider will re-run the related steps, i.e. copy/execute. Without this change, updating the user-defined conf or script that the provisioner copies will never be re-executed after the first time.

@praneetloke praneetloke self-assigned this Jan 14, 2020
host: server.publicIp,
username: "ec2-user",
privateKey,
privateKeyPassphrase,
privateKeyPassphrase,
changeToken: getFileHash("myapp.conf"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some indentation appears to be off here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my editor was set to use Tabs for this repo for some reason. I have fixed it now.

* A string value to control the replacement of the provisioner during each update.
* Provide a stable value if you do not need the provisioner to run each time you run an update.
*/
changeToken: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this doesn't quite belong on the ConnectionArgs - and might make more sense as a property on CopyFile args and RemoteExec args? In terraform, this is often called keepers - perhaps use that terminology (I've never found any terminology I particularly like for this).

Note that for the specific case of changing when the file contents change - it might be nice to actually have a first class hash property. Doing just that might be sufficient here?

Though looking at your original example - perhaps the reason you did it the way you did was to trigger both of these to re-run - which would not be possible with my suggestion above due to the lack of pulumi/pulumi#838.

Feel free to keep this as is - but perhaps consider keepers as the name?

As for doc comment here - the inconsistency is a little jarring - perhaps add comments on all properties? And either adopt the same // style, or update all existing doc comments to /** */ style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this doesn't quite belong on the ConnectionArgs - and might make more sense as a property on CopyFile args and RemoteExec args?

Yeah I agree -- it was a little hacky to put it with the ConnectionArgs, to be honest. I moved it to be a property of those component resources, as well as the provisioner dynamic resource's "state" input as well.

Though looking at your original example - perhaps the reason you did it the way you did was to trigger both of these to re-run

Yes, that's correct. The user can control which one they would like to re-run every time the file(s) content changes.

Feel free to keep this as is - but perhaps consider keepers as the name?

I don't like the name keepers, so I left the name changeToken, but can change it if you insist on using keepers.

* Calculates a hash for all of the files under the scripts directory.
*/
export function getFileHash(filename: string): string {
const data = fs.readFileSync(path.join(__dirname, filename), {encoding: "utf8"});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW - I think the current interpretation of src: is relative to cwd, not to the __dirname.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand this comment?

@praneetloke
Copy link
Contributor Author

@lukehoban it seems I neglected this PR for quite a while. Could you please take another look when you get a chance? I updated it based on your feedback.

@stack72 stack72 requested a review from lukehoban April 29, 2020 15:49
@stack72
Copy link
Contributor

stack72 commented May 4, 2020

@praneetloke is this something you can add to the python provisioners as well? :)

@praneetloke
Copy link
Contributor Author

I will go ahead and merge this. The failure is unrelated to the changes in this sample. It was a GCP test failure. All other tests passed.

For posterity, here's the test that failed:

--- FAIL: TestAccGcpJsWebserver (83.35s)
##[error]    program.go:769: [/home/runner/.pulumi/bin/pulumi up --non-interactive --yes --skip-preview --event-log /tmp/p-it-fv-az115-gcp-js-web-fd99589c-events.json --tracing https://tracing.pulumi-engineering.com/collector/api/v1/spans] failed: exit status 255; retrying...
##[error]    program.go:769: [/home/runner/.pulumi/bin/pulumi up --non-interactive --yes --skip-preview --event-log /tmp/p-it-fv-az115-gcp-js-web-fd99589c-events.json --tracing https://tracing.pulumi-engineering.com/collector/api/v1/spans] failed: exit status 255; retrying...
    program.go:604: 
        	Error Trace:	program.go:604
        	            				examples_test.go:1175
        	Error:      	Received unexpected error:
        	            	[/home/runner/.pulumi/bin/pulumi up --non-interactive --yes --skip-preview --event-log /tmp/p-it-fv-az115-gcp-js-web-fd99589c-events.json --tracing https://tracing.pulumi-engineering.com/collector/api/v1/spans] did not succeed after 3 tries

@praneetloke praneetloke merged commit 94ba6da into master May 5, 2020
@pulumi-bot pulumi-bot deleted the praneetloke/update-provisioner branch May 5, 2020 22:23
@praneetloke
Copy link
Contributor Author

is this something you can add to the python provisioners as well?

I'll try to add something there as well, but likely won't get to it soon. Is that ok?

dixler pushed a commit that referenced this pull request Jan 21, 2022
…hange (#513)

* Add a user-settable changeToken property to ConnectionArgs that can be used to detect changes to scripts.

* Add the changeToken property to the input args of the provisioner and the componentresources.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants