{"id":18707001,"url":"https://github.com/terraform-google-modules/terraform-google-startup-scripts","last_synced_at":"2025-04-05T19:13:28.330Z","repository":{"id":39614581,"uuid":"161814152","full_name":"terraform-google-modules/terraform-google-startup-scripts","owner":"terraform-google-modules","description":"Provides a library of useful startup scripts to embed in VMs","archived":false,"fork":false,"pushed_at":"2025-01-16T13:53:59.000Z","size":204,"stargazers_count":74,"open_issues_count":2,"forks_count":35,"subscribers_count":35,"default_branch":"main","last_synced_at":"2025-03-29T18:08:25.786Z","etag":null,"topics":["cft-terraform","compute"],"latest_commit_sha":null,"homepage":"https://registry.terraform.io/modules/terraform-google-modules/startup-scripts/google","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/terraform-google-modules.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-14T16:44:12.000Z","updated_at":"2025-01-08T22:11:07.000Z","dependencies_parsed_at":"2023-10-05T04:30:20.773Z","dependency_job_id":"bc101f7a-6feb-491b-a1b7-e2d3aa690429","html_url":"https://github.com/terraform-google-modules/terraform-google-startup-scripts","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-google-modules%2Fterraform-google-startup-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-google-modules%2Fterraform-google-startup-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-google-modules%2Fterraform-google-startup-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terraform-google-modules%2Fterraform-google-startup-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terraform-google-modules","download_url":"https://codeload.github.com/terraform-google-modules/terraform-google-startup-scripts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386265,"owners_count":20930619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cft-terraform","compute"],"created_at":"2024-11-07T12:16:23.015Z","updated_at":"2025-04-05T19:13:28.307Z","avatar_url":"https://github.com/terraform-google-modules.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Startup Script Library\n\nThis terraform module provides a mechanism to store a library of bash functions\nintended for use in startup scripts.  The goal is to have a single place to add\nfunctionality useful by all instances.\n\nUse cases are:\n\n * Logging functions\n * Debugging functions\n * Functions to execute commands and provide a consistent output format for the\n   end user and/or machine parsing via logs.\n\n## Compatibility\n\nThis module is meant for use with Terraform 0.13+ and tested using Terraform 1.0+.\nIf you find incompatibilities using Terraform `\u003e=0.13`, please open an issue.\n\nIf you haven't [upgraded][terraform-0.13-upgrade] and need a Terraform\n0.12.x-compatible version of this module, the last released version\nintended for Terraform 0.12.x is [1.0.0].\n\n# Usage\n\nThe library is loaded as the startup script of an instance.  It initializes and\npasses control to the metadata key startup-script-custom. Control is passed\nusing bash's `source` mechanism so that all functions provided by the library are\navailable.\n\nAdd the following to your Terraform module.  Update the tag as necessary.\n\n```terraform\nmodule \"startup-script-lib\" {\n  source = \"git::https://github.com/terraform-google-modules/terraform-google-startup-scripts.git?ref=v0.1.0\"\n}\n```\n\nWhen managing a compute instance, your module is responsible for passing the\nlibrary of functions as a string values of the startup-script metadata key. Your\nmodule may also pass configuration via the startup-script-config metadata key.\nInject the library into the compute instance by reading the output content like\nso:\n\n```terraform\nresource \"google_compute_instance\" \"example\" {\n  # other attributes removed\n  metadata {\n    startup-script        = \"${module.startup-script-lib.content}\"\n    startup-script-custom = \"stdlib::info Hello World\"\n  }\n}\n```\n\n# Features\n\n## Configuration of startup-script\n\nThis module provides a mechanism to automatically load configuration values for\nuse by `startup-script-custom`.  Configuration values are automatically sourced\nfrom the metadata key `instance/attributes/startup-script-config`.  This module\nfollows the `/etc/sysconfig/defaults` model of loading configuration keys and\nvalues.\n\nSet the startup-script-config metadata key to a rendered template:\n\n```bash\n# IPIP peer address configuration.\nPEER_OUTER_IPADDR='${peer_outer_ipaddr}'\nPEER_INNER_IPADDR='${peer_inner_ipaddr}'\nMY_INNER_IPADDR='${my_inner_ipaddr}'\n# Subnets to route through the IPIP Tunnel to the peer\nIPIP_SUBNETS='${ipip_subnets}'\n```\n\nFill in this template in Terraform:\n\n```terraform\ndata \"template_file\" \"startup_script_config\" {\n  template = \"${file(\"${path.module}/templates/startup-script-config.tpl\")}\"\n  vars {\n    peer_outer_ipaddr = \"${var.peer_outer_ipaddr}\"\n    peer_inner_ipaddr = \"${var.peer_inner_ipaddr}\"\n    my_inner_ipaddr   = \"${var.my_inner_ipaddr}\"\n    ipip_subnets      = \"${var.ipip_subnets}\"\n  }\n}\n```\n\nThese configuration values will be automatically loaded into the environment\nwhen `startup-script-custom` script executes.\n\n# Behavior\n\n## Updating vs Deleting instances\n\nNote the use of of the `compute_instance` `metadata` attribute causes existing\ninstances to be updated in place when values change.  In contrast, the use of\nthe `metadata_startup_script` attribute causes Terraform to delete and re-create\nthe instance as per the [compute_instance\nmetadata_startup_script][metadata_startup_script] documentation.\n\n## Re-run startup scripts\n\nIt can be helpful to re-run custom startup scripts by logging into the instance\nand running.\n\n```bash\nsudo google_metadata_script_runner --script-type startup\n```\n\nTo enable full debugging, both in the script runner and the startup script\nlibrary, set `DEBUG` to a non-zero length string.\n\n```bash\nsudo DEBUG=1 google_metadata_script_runner --script-type startup --debug\n```\n\n## Configuration\n\nThe behavior of the startup scripts library is governed by environment\nvariables.  Feature flags are enabled by setting the environment variable to a\nnon-zero length value.  Logs are sent to syslog and standard error by default.\n\n| Variable              | Default          | Description                   |\n| --------              | -------          | -----------                   |\n| DEBUG                 | unset            | Log debug messages if set.    |\n| QUIET                 | unset            | Silence log messages if set.  |\n| COLOR                 | unset            | Colored logs if set.          |\n| DATE_FMT              |                  | Log `date +\u003cformat\u003e`.         |\n| SYSLOG_DEBUG_PRIORITY | syslog.debug     | `logger -p \u003cvalue\u003e`           |\n| SYSLOG_INFO_PRIORITY  | syslog.info      | `logger -p \u003cvalue\u003e`           |\n| SYSLOG_ERROR_PRIORITY | syslog.error     | `logger -p \u003cvalue\u003e`           |\n| VARDIR                | /var/lib/startup | Durable alternative to TMPDIR |\n\n\u003c!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --\u003e\n## Inputs\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| enable\\_get\\_from\\_bucket | If not false, include stdlib::get\\_from\\_bucket() prior to executing startup-script-custom.  Requires gsutil in the PATH.  See also enable\\_init\\_gsutil\\_crcmod\\_el feature flag. | `bool` | `false` | no |\n| enable\\_init\\_gsutil\\_crcmod\\_el | If not false, include stdlib::init\\_gsutil\\_crcmod\\_el() prior to executing startup-script-custom.  Call this function from startup-script-custom to initialize gsutil as per https://cloud.google.com/storage/docs/gsutil/addlhelp/CRC32CandInstallingcrcmod#centos-rhel-and-fedora Intended for CentOS, RHEL and Fedora systems. | `bool` | `false` | no |\n| enable\\_setup\\_init\\_script | If not false, include stdlib::setup\\_init\\_script() prior to executing startup-script-custom.   Call this function to load an init script from GCS into /etc/init.d and initialize it with chkconfig. This function depends on stdlib::get\\_from\\_bucket, so this function won't be enabled if enable\\_get\\_from\\_bucket is false. | `bool` | `false` | no |\n| enable\\_setup\\_sudoers | If true, include stdlib::setup\\_sudoers() prior to executing startup-script-custom. Call this function from startup-script-custom to setup unix usernames in sudoers Comma separated values must be posted to the project metadata key project/attributes/sudoers | `bool` | `false` | no |\n\n## Outputs\n\n| Name | Description |\n|------|-------------|\n| content | startup-script-stdlib.sh content as a string value. |\n\n\u003c!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --\u003e\n\n## Contributing\n\nRefer to the [contribution guidelines](./CONTRIBUTING.md) for\ninformation on contributing to this module.\n\n[metadata_startup_script]: https://www.terraform.io/docs/providers/google/r/compute_instance.html#metadata_startup_script\n[bats]: https://github.com/sstephenson/bats\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterraform-google-modules%2Fterraform-google-startup-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterraform-google-modules%2Fterraform-google-startup-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterraform-google-modules%2Fterraform-google-startup-scripts/lists"}