Skip to content

feat(application integration): Add example for creating auth configs #658

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

Merged
merged 12 commits into from
May 15, 2024
216 changes: 216 additions & 0 deletions application_integration/create_auth_config/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

provider "google" {}

data "google_project" "default" {}

# [START application_integration_create_auth_config_auth_token]
resource "google_integrations_client" "client" {
location = "us-central1"
}

resource "google_integrations_auth_config" "auth_config_auth_token" {
location = "us-central1"
display_name = "tf-auth-token"
description = "Test auth config created via terraform"
decrypted_credential {
credential_type = "AUTH_TOKEN"
auth_token {
type = "Basic"
token = "some-random-token"
}
}
depends_on = [google_integrations_client.client]
}
# [END application_integration_create_auth_config_auth_token]

# [START application_integration_create_auth_config_certificate]
resource "google_integrations_auth_config" "auth_config_certificate" {
location = "us-central1"
display_name = "tf-certificate"
description = "Test auth config created via terraform"
decrypted_credential {
credential_type = "CLIENT_CERTIFICATE_ONLY"
}
client_certificate {
ssl_certificate = <<EOT
-----BEGIN CERTIFICATE-----
MIICTTCCAbagAwIBAgIJAPT0tSKNxan/MA0GCSqGSIb3DQEBCwUAMCoxFzAVBgNV
BAoTDkdvb2dsZSBURVNUSU5HMQ8wDQYDVQQDEwZ0ZXN0Q0EwHhcNMTUwMTAxMDAw
MDAwWhcNMjUwMTAxMDAwMDAwWjAuMRcwFQYDVQQKEw5Hb29nbGUgVEVTVElORzET
MBEGA1U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vyXsR6GjmlZJvULEopJNUNCOOpITNQikXK63sIFry7/59eGv5
UwKadZbfwbVF5ipu59UxfVE3lipf/mYePDqMkHVWv/8p+OnnJt9uKnyW8VSOu5uk
82QF30zbIWDTUjrcugVAs+E=
-----END PRIVATE KEY-----
EOT
}
depends_on = [google_integrations_client.client]
}
# [END application_integration_create_auth_config_certificate]

# [START application_integration_create_auth_config_jwt]
resource "google_integrations_auth_config" "auth_config_jwt" {
location = "us-central1"
display_name = "tf-jwt"
description = "Test auth config created via terraform"
decrypted_credential {
credential_type = "JWT"
jwt {
jwt_header = "{\"alg\": \"HS256\", \"typ\": \"JWT\"}"
jwt_payload = "{\"sub\": \"1234567890\", \"name\": \"John Doe\", \"iat\": 1516239022}"
secret = "secret"
}
}
depends_on = [google_integrations_client.client]
}
# [END application_integration_create_auth_config_jwt]

# [START application_integration_create_auth_config_oauth2_authorization_code]
resource "google_integrations_auth_config" "auth_config_oauth2_authorization_code" {
location = "us-central1"
display_name = "tf-oauth2-authorization-code"
description = "Test auth config created via terraform"
decrypted_credential {
credential_type = "OAUTH2_AUTHORIZATION_CODE"
oauth2_authorization_code {
client_id = "Kf7utRvgr95oGO5YMmhFOLo8"
client_secret = "D-XXFDDMLrg2deDgczzHTBwC3p16wRK1rdKuuoFdWqO0wliJ"
scope = "photo offline_access"
auth_endpoint = "https://authorization-server.com/authorize"
token_endpoint = "https://authorization-server.com/token"
}
}
depends_on = [google_integrations_client.client]
}
# [END application_integration_create_auth_config_oauth2_authorization_code]

# [START application_integration_create_auth_config_oauth2_client_credentials]
resource "google_integrations_auth_config" "auth_config_oauth2_client_credentials" {
location = "us-central1"
display_name = "tf-oauth2-client-credentials"
description = "Test auth config created via terraform"
decrypted_credential {
credential_type = "OAUTH2_CLIENT_CREDENTIALS"
oauth2_client_credentials {
client_id = "demo-backend-client"
client_secret = "MJlO3binatD9jk1"
scope = "read"
token_endpoint = "https://login-demo.curity.io/oauth/v2/oauth-token"
request_type = "ENCODED_HEADER"
token_params {
entries {
key {
literal_value {
string_value = "string-key"
}
}
value {
literal_value {
string_value = "string-value"
}
}
}
}
}
}
depends_on = [google_integrations_client.client]
}
# [END application_integration_create_auth_config_oauth2_client_credentials]

# [START application_integration_create_auth_config_service_account]
resource "random_id" "default" {
byte_length = 8
}

resource "google_service_account" "default" {
account_id = "sa-${random_id.default.hex}"
display_name = "Service Account"
}

resource "google_integrations_auth_config" "auth_config_service_account" {
location = "us-central1"
display_name = "tf-service-account"
description = "Test auth config created via terraform"
decrypted_credential {
credential_type = "SERVICE_ACCOUNT"
service_account_credentials {
service_account = google_service_account.default.email
scope = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/adexchange.buyer https://www.googleapis.com/auth/admob.readonly"
}
}
depends_on = [google_integrations_client.client]
}
# [END application_integration_create_auth_config_service_account]

# [START application_integration_create_auth_config_oidc_token]
resource "google_project_iam_member" "default" {
project = data.google_project.default.project_id
role = "roles/iam.serviceAccountTokenCreator"
member = "serviceAccount:${google_service_account.default.email}"
}

resource "google_integrations_auth_config" "auth_config_oidc_token" {
location = "us-central1"
display_name = "tf-oidc-token"
description = "Test auth config created via terraform"
decrypted_credential {
credential_type = "OIDC_TOKEN"
oidc_token {
service_account_email = google_service_account.default.email
audience = "https://us-central1-project.cloudfunctions.net/functionA 1234987819200.apps.googleusercontent.com"
}
}
depends_on = [google_integrations_client.client, google_project_iam_member.default]
}
# [END application_integration_create_auth_config_oidc_token]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ data "google_project" "default" {
}

# [START application_integration_edit_region]

resource "random_id" "default" {
byte_length = 8
}
Expand Down