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

Add create and destroy scripts for the module to run #9

Merged

Conversation

taylorludwig
Copy link
Contributor

@taylorludwig
Copy link
Contributor Author

We might need to add variables for script_triggers and script_depends_on to replicate this functionality

https://github.com/terraform-google-modules/terraform-google-project-factory/blob/master/modules/core_project_factory/main.tf#L201-L208

@morgante
Copy link
Contributor

We might need to add variables for script_triggers and script_depends_on to replicate this functionality

Yes, let's add script_triggers and module_depends_on variables.

@taylorludwig
Copy link
Contributor Author

I added create_script_triggers and create_script_arguments

You can see the implementation of it used in the project factory PR here

https://github.com/terraform-google-modules/terraform-google-project-factory/pull/343/files#diff-d3740c193b3aa6f052c215e40f1a18ddR228-R232

I couldn't add a module_depends_on because the local_exec in this module already has some needed depends_on resources (eg gcloud needs to be installed before script execution). And we couldn't merge this module's depends_on with the module_depends_on variable because terraform would complain that it needed to be a static list.

However, I was able to replicate the dependency tree by passing extra keys to the triggers variable. This forces the same dependency implicitly so we get the same result. You can see in the project factory build the script execution happens at the right time.

@@ -26,4 +26,7 @@ module "cli" {

create_cmd_body = "services enable youtube.googleapis.com --project ${var.project_id}"
destroy_cmd_body = "services disable youtube.googleapis.com --project ${var.project_id}"

create_script = "${path.module}/scripts/script.sh"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make a script a separate example from a simple command (though I'm actually curious as to whether scripts could simply be passed as a command?)

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've added a script_example and test. Similar to the simple_example but using a script to enable and disable an api.

I could probably remove the new script vars in favor of utilizing the existing create|destroy_cmd_entrypoint variables.

Right now they default to gcloud - but passing in the script instead should work (assuming I also prepend the bin directory to the path). Arguments to the script could use the existing create|destroy_cmd_body vars.

Something like this uses all existing vars and will achieve the same effect without breaking original functionality.

module "cli" {
  source = "../.."

  platform              = "linux"
  additional_components = ["kubectl", "beta"]

  create_cmd_entrypoint = "${path.module}/scripts/script.sh"
  create_cmd_body       = "enable ${var.project_id}"

  destroy_cmd_entrypoint = "${path.module}/scripts/script.sh"
  destroy_cmd_body       = "disable ${var.project_id}"
}

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 went ahead and committed that. It does make the change quite a bit simpler. I'll update the project-factory PR for this approach too

@morgante morgante merged commit ab5b5f3 into terraform-google-modules:master Dec 22, 2019
@morgante
Copy link
Contributor

@taylorludwig Looks great thanks, released as v0.3.0 so please update pfactory to that.

morgante added a commit that referenced this pull request Jul 10, 2020
Add create and destroy scripts for the module to run

Former-commit-id: ab5b5f3
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.

2 participants