Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/terraform-google-modules/terraform-google-gcloud

Executes Google Cloud CLI commands within Terraform
https://github.com/terraform-google-modules/terraform-google-gcloud

cft-terraform developer-tools

Last synced: 5 days ago
JSON representation

Executes Google Cloud CLI commands within Terraform

Awesome Lists containing this project

README

        

# terraform-google-gcloud

This module allows you to use gcloud, gsutil, any gcloud component, and jq in Terraform. Sometimes, there isn't Terraform GCP support for a particular feature, or you'd like to do something each time Terraform runs (ie: upload a file to a Kubernetes pod) that lacks Terraform support.

This module *does not* create any resources on GCP itself, rather exposes the GCP SDK to you for usage in null resources & external data resources.

## Usage

Basic usage of this module is as follows:

```hcl
module "gcloud" {
source = "terraform-google-modules/gcloud/google"
version = "~> 3.5"

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

create_cmd_entrypoint = "gcloud"
create_cmd_body = "version"
destroy_cmd_entrypoint = "gcloud"
destroy_cmd_body = "version"
}
```

Functional examples are included in the
[examples](https://github.com/terraform-google-modules/terraform-google-gcloud/tree/master/examples) directory.

The [jq](https://stedolan.github.io/jq/) binary is also included in this module so you can use it as well for either of your `create_cmd_entrypoint` or `destroy_cmd_entrypoint` values.

## Downloading
By default, this module assumes you already have gcloud installed in your $PATH.

If you need to run Terraform in environments without a gcloud binary available, you can override this behavior by setting the `skip_download` variable to `false`.

You can also override the behavior by setting the `GCLOUD_TF_DOWNLOAD` environment variable.
This environment variable will override all other settings.
Setting it to `never` will *never* gcloud download and setting it to `always` will always download gcloud.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| activate\_service\_account | Set to false to skip running `gcloud auth activate-service-account`. Optional. | `bool` | `true` | no |
| additional\_components | Additional gcloud CLI components to install. Defaults to none. Valid value are components listed in `gcloud components list` | `list(string)` | `[]` | no |
| create\_cmd\_body | On create, the command body you'd like to run with your entrypoint. | `string` | `"info"` | no |
| create\_cmd\_entrypoint | On create, the command entrypoint you'd like to use. Can also be set to a custom script. Module's bin directory will be prepended to path. | `string` | `"gcloud"` | no |
| create\_cmd\_triggers | List of any additional triggers to re-run the create command execution when either of values in the maps change. Some keys are reserved and will be overwritten if specified in this option. (eg. `md5`, `arguments`, `download_gcloud_command`, `download_jq_command`, etc. See details in [the source](https://github.com/terraform-google-modules/terraform-google-gcloud/blob/master/main.tf).) | `map(any)` | `{}` | no |
| destroy\_cmd\_body | On destroy, the command body you'd like to run with your entrypoint. | `string` | `"info"` | no |
| destroy\_cmd\_entrypoint | On destroy, the command entrypoint you'd like to use. Can also be set to a custom script. Module's bin directory will be prepended to path. | `string` | `"gcloud"` | no |
| enabled | Flag to optionally disable usage of this module. | `bool` | `true` | no |
| gcloud\_download\_url | Custom gcloud download url. Optional. | `string` | `""` | no |
| gcloud\_sdk\_version | The gcloud sdk version to download. | `string` | `"481.0.0"` | no |
| jq\_download\_url | Custom jq download url. Optional. | `string` | `""` | no |
| jq\_version | The jq version to download. | `string` | `"1.6"` | no |
| module\_depends\_on | List of modules or resources this module depends on. | `list(any)` | `[]` | no |
| platform | Platform CLI will run on. Defaults to linux. Valid values: linux, darwin | `string` | `"linux"` | no |
| service\_account\_key\_file | Path to service account key file to run `gcloud auth activate-service-account` with. Optional. | `string` | `""` | no |
| skip\_download | Whether to skip downloading gcloud (assumes gcloud is already available outside the module) | `bool` | `true` | no |
| upgrade | Whether to upgrade gcloud at runtime | `bool` | `true` | no |
| use\_tf\_google\_credentials\_env\_var | Use `GOOGLE_CREDENTIALS` environment variable to run `gcloud auth activate-service-account` with. Optional. | `bool` | `false` | no |

## Outputs

| Name | Description |
|------|-------------|
| bin\_dir | The full bin path of the modules executables |
| create\_cmd\_bin | The full bin path & command used on create |
| destroy\_cmd\_bin | The full bin path & command used on destroy |
| downloaded | Whether gcloud was downloaded or not |
| wait | An output to use when you want to depend on cmd finishing |

## Requirements

These sections describe requirements for using this module.

### Software

The following dependencies must be available:

- [Terraform][terraform] v0.12
- [Terraform Provider for GCP][terraform-provider-gcp] plugin v2.0
- [curl][curl]

### Service Account

A service account must be created, along with a key, to use this module.
The service account must have the proper IAM roles for whatever
commands you're running with this module.

### APIs

A project is not required to host resources of this module, since
this module does not create any resources.

However you will likely need a project for your service account
and any resources you'd like to interact with while using this module.

## Contributing

Refer to the [contribution guidelines](./CONTRIBUTING.md) for
information on contributing to this module.

[iam-module]: https://registry.terraform.io/modules/terraform-google-modules/iam/google
[project-factory-module]: https://registry.terraform.io/modules/terraform-google-modules/project-factory/google
[terraform-provider-gcp]: https://www.terraform.io/docs/providers/google/index.html
[terraform]: https://www.terraform.io/downloads.html
[curl]: https://curl.haxx.se