Skip to content

Commit

Permalink
Update documentation for ephemeral resources: remove broken examples,…
Browse files Browse the repository at this point in the history
… add notes, misc fixes (#12448)
  • Loading branch information
SarahFrench authored Dec 2, 2024
1 parent 383689a commit efbaa73
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ In the example below, `google_project` will run as `service_B`.
provider "google" {
}
data "google_client_config" "default" {
provider = google
}
ephemeral "google_service_account_access_token" "default" {
provider = google
target_service_account = "[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ For more information see
[OpenID Connect](https://openid.net/specs/openid-connect-core-1_0.html#IDToken).

## Example Usage - ServiceAccount JSON credential file.

-> **Note:** If you run this example configuration you will be able to see ephemeral.google_service_account_id_token.oidc in terraform plan and apply terminal output but you will not see it in state, as ephemeral resources are excluded from state. In future, when write-only attributes are added to resources in the Google provider, ephemeral resources such as google_service_account_id_token could be used to set field values when creating managed resources.

`google_service_account_id_token` will use the configured [provider credentials](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#credentials-1)

```hcl
Expand All @@ -21,7 +24,10 @@ For more information see
```

## Example Usage - Service Account Impersonation.
`google_service_account_access_token` will use background impersonated credentials provided by [google_service_account_access_token](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/service_account_access_token).

-> **Note:** If you run this example configuration you will be able to see ephemeral.google_service_account_id_token.oidc in terraform plan and apply terminal output but you will not see it in state, as ephemeral resources are excluded from state. In future, when write-only attributes are added to resources in the Google provider, ephemeral resources such as google_service_account_id_token could be used to set field values when creating managed resources.

Ephemeral resource `google_service_account_id_token` will use background impersonated credentials provided by [google_service_account_access_token](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/service_account_access_token).

Note: to use the following, you must grant `target_service_account` the
`roles/iam.serviceAccountTokenCreator` role on itself.
Expand Down Expand Up @@ -50,29 +56,6 @@ For more information see
```

## Example Usage - Invoking Cloud Run Endpoint

The following configuration will invoke [Cloud Run](https://cloud.google.com/run/docs/authenticating/service-to-service) endpoint where the service account for Terraform has been granted `roles/run.invoker` role previously.

```hcl
ephemeral "google_service_account_id_token" "oidc" {
target_audience = "https://your.cloud.run.app/"
}
data "http" "cloudrun" {
url = "https://your.cloud.run.app/"
request_headers = {
Authorization = "Bearer ${ephemeral.google_service_account_id_token.oidc.id_token}"
}
}
output "cloud_run_response" {
value = data.http.cloudrun.body
}
```

## Argument Reference

The following arguments are supported:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This ephemeral resource provides a [self-signed JWT](https://cloud.google.com/ia

## Example Usage

-> **Note:** If you run this example configuration you will be able to see ephemeral.google_service_account_jwt.foo in terraform plan and apply terminal output but you will not see it in state, as ephemeral resources are excluded from state. In future, when write-only attributes are added to resources in the Google provider, ephemeral resources such as google_service_account_jwt could be used to set field values when creating managed resources.

Note: in order to use the following, the caller must have _at least_ `roles/iam.serviceAccountTokenCreator` on the `target_service_account`.

```hcl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Get an ephemeral service account public key. For more information, see [the offi

## Example Usage

-> **Note:** If you run this example configuration you will be able to see ephemeral.google_service_account_key.mykey in terraform plan and apply terminal output but you will not see it in state, as ephemeral resources are excluded from state. In future, when write-only attributes are added to resources in the Google provider, ephemeral resources such as google_service_account_key could be used to set field values when creating managed resources.


```hcl
resource "google_service_account" "myaccount" {
account_id = "dev-foo-account"
Expand Down

0 comments on commit efbaa73

Please sign in to comment.