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

Platform default: autodetect #30

Closed
wants to merge 109 commits into from
Closed

Platform default: autodetect #30

wants to merge 109 commits into from

Conversation

bdelv
Copy link

@bdelv bdelv commented Feb 14, 2020

  • Added a platform detection mechanism (linux or darwin)
  • Changed the default from linux to "" (autodetect)
  • if the detection already happened, a config file is saved in the cache folder and the next tf plans/apply don't need more action
  • Removed the explicit platform from the examples

ran the tests under Linux and MacOS
updated the docs, and ran the lints

Fixes #26

Miles Matthias and others added 30 commits October 22, 2019 10:52
@morgante morgante self-requested a review February 14, 2020 15:44
Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, very helpful!

description = "Platform CLI will run on. Defaults to linux. Valid values: linux, darwin"
default = "linux"
description = "Platform CLI will run on. Defaults to \"\" (autodetect). Valid values: linux, darwin, \"\""
default = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a default of null (and also explicitly set the type to string)?

@@ -67,10 +111,15 @@ resource "null_resource" "copy" {

provisioner "local-exec" {
when = create
command = local.copy_command
command = "cp -R ${path.module}/cache/${var.platform == "" ? (local.dynamic_platform_file ? data.local_file.platform_detected[0].content : file(local.platform_file)) : var.platform}/. ${local.cache_path}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep this as a local at the top (for consistency) and possibly split it into two expressions?

]
}

data "local_file" "platform_detected" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a brief explanation (in a comment) of how this flow is meant to work?

My understanding:

  1. On first run, fileexists will be false so the flow is null_resource.platform_detect then call this data source.
  2. On subsequent runs, fileexists will be true so the flow is to directly skip to copy and use file( to pick up the flow.

This works, but I wonder if it could be simpler. In particular, I'm not sure there's much value in caching the platform detection since gcloud scripts should generally only need to be invoked ~once in a particular module. So maybe we could always redetect when we need to run the command?

Copy link
Author

Choose a reason for hiding this comment

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

Your understanding is correct.
The reason I ended up doing it like that is because

  • I need a bash script to detect the OS
  • The only way I found to get back the value is through a file
  • local_file is "dynamically resolved" and can be sequenced with a depends_on, but was causing the plan to always contain an action (dynamic reading of the file each time).
  • fileexists is evaluated at the "planing" time so it's not useable during the first run (the file is not created at plan time), but is useable afterward without generating a plan action.

I'll give it another try to use local_file, without generating an action for each run.
I probably missed something in the triggers

@morgante
Copy link
Contributor

@bdelv Would you be able to rebase and address review comments?

@github-actions
Copy link
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Jan 26, 2021
@github-actions github-actions bot closed this Feb 3, 2021
@morgante morgante added enhancement New feature or request P2 high priority issues triaged Scoped and ready for work and removed Stale labels Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2 high priority issues triaged Scoped and ready for work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

platform default to linux
7 participants