google_apikeys_key

The Apikeys Key resource

Example Usage - android_key

A basic example of a android api keys key

resource "google_apikeys_key" "primary" {
  name         = "key"
  display_name = "sample-key"
  project      = google_project.basic.name

  restrictions {
    android_key_restrictions {
      allowed_applications {
        package_name     = "com.example.app123"
        sha1_fingerprint = "1699466a142d4682a5f91b50fdf400f2358e2b0b"
      }
    }

    api_targets {
      service = "translate.googleapis.com"
      methods = ["GET*"]
    }
  }
}

resource "google_project" "basic" {
  project_id = "app"
  name       = "app"
  org_id     = "123456789"
}

Example Usage - basic_key

A basic example of a api keys key

resource "google_apikeys_key" "primary" {
  name         = "key"
  display_name = "sample-key"
  project      = google_project.basic.name

  restrictions {
    api_targets {
      service = "translate.googleapis.com"
      methods = ["GET*"]
    }

    browser_key_restrictions {
      allowed_referrers = [".*"]
    }
  }
}

resource "google_project" "basic" {
  project_id = "app"
  name       = "app"
  org_id     = "123456789"
}

Example Usage - ios_key

A basic example of a ios api keys key

resource "google_apikeys_key" "primary" {
  name         = "key"
  display_name = "sample-key"
  project      = google_project.basic.name

  restrictions {
    api_targets {
      service = "translate.googleapis.com"
      methods = ["GET*"]
    }

    ios_key_restrictions {
      allowed_bundle_ids = ["com.google.app.macos"]
    }
  }
}

resource "google_project" "basic" {
  project_id = "app"
  name       = "app"
  org_id     = "123456789"
}

Example Usage - minimal_key

A minimal example of a api keys key

resource "google_apikeys_key" "primary" {
  name         = "key"
  display_name = "sample-key"
  project      = google_project.basic.name
}

resource "google_project" "basic" {
  project_id = "app"
  name       = "app"
  org_id     = "123456789"
}

Example Usage - server_key

A basic example of a server api keys key

resource "google_apikeys_key" "primary" {
  name         = "key"
  display_name = "sample-key"
  project      = google_project.basic.name

  restrictions {
    api_targets {
      service = "translate.googleapis.com"
      methods = ["GET*"]
    }

    server_key_restrictions {
      allowed_ips = ["127.0.0.1"]
    }
  }
}

resource "google_project" "basic" {
  project_id = "app"
  name       = "app"
  org_id     = "123456789"
}

Argument Reference

The following arguments are supported:

The allowed_applications block supports:


The restrictions block supports:

The android_key_restrictions block supports:

The api_targets block supports:

The browser_key_restrictions block supports:

The ios_key_restrictions block supports:

The server_key_restrictions block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Key can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Key using one of the formats above. For example:

import {
  id = "projects/{{project}}/locations/global/keys/{{name}}"
  to = google_apikeys_key.default
}

When using the terraform import command, Key can be imported using one of the formats above. For example:

$ terraform import google_apikeys_key.default projects/{{project}}/locations/global/keys/{{name}}
$ terraform import google_apikeys_key.default {{project}}/{{name}}
$ terraform import google_apikeys_key.default {{name}}