-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add workload identity, add service account flag (#10)
- Loading branch information
Showing
7 changed files
with
192 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
tflint: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
name: Checkout source code | ||
|
||
- uses: actions/cache@v2 | ||
name: Cache plugin dir | ||
with: | ||
path: ~/.tflint.d/plugins | ||
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }} | ||
|
||
- uses: terraform-linters/setup-tflint@v1 | ||
name: Setup TFLint | ||
with: | ||
tflint_version: v0.53.0 | ||
|
||
- name: Show version | ||
run: tflint --version | ||
|
||
- name: Init TFLint | ||
run: tflint --init | ||
|
||
- name: Run TFLint | ||
run: tflint -f compact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
moved { | ||
from = google_service_account.castai_service_account | ||
to = google_service_account.castai_service_account[0] | ||
} | ||
|
||
moved { | ||
from = google_service_account_key.castai_key | ||
to = google_service_account_key.castai_key[0] | ||
} | ||
|
||
locals { | ||
service_account_id = "castai-gke-tf-${substr(sha1(var.gke_cluster_name), 0, 8)}" | ||
service_account_email = "${local.service_account_id}@${var.project_id}.iam.gserviceaccount.com" | ||
} | ||
|
||
resource "google_service_account" "castai_service_account" { | ||
count = var.create_service_account ? 1 : 0 | ||
account_id = local.service_account_id | ||
display_name = "Service account to manage ${var.gke_cluster_name} cluster via CAST" | ||
project = var.project_id | ||
} | ||
|
||
resource "google_service_account_key" "castai_key" { | ||
count = var.create_service_account ? 1 : 0 | ||
service_account_id = google_service_account.castai_service_account[0].name | ||
public_key_type = "TYPE_X509_PEM_FILE" | ||
} | ||
|
||
resource "google_project_iam_member" "project" { | ||
for_each = ( | ||
var.create_service_account && length(var.service_accounts_unique_ids) == 0 ? | ||
{ for permission in local.default_permissions : permission => permission } : | ||
{} | ||
) | ||
|
||
project = var.project_id | ||
role = each.key | ||
member = "serviceAccount:${local.service_account_email}" | ||
} | ||
|
||
resource "google_project_iam_member" "scoped_project" { | ||
for_each = ( | ||
var.create_service_account && length(var.service_accounts_unique_ids) > 0 ? | ||
{ for permission in local.scoped_permissions : permission => permission } : | ||
{} | ||
) | ||
project = var.project_id | ||
role = each.key | ||
member = "serviceAccount:${local.service_account_email}" | ||
} | ||
|
||
resource "google_project_iam_member" "scoped_service_account_user" { | ||
count = var.create_service_account && length(var.service_accounts_unique_ids) > 0 ? 1 : 0 | ||
project = var.project_id | ||
|
||
role = "roles/iam.serviceAccountUser" | ||
member = "serviceAccount:${local.service_account_email}" | ||
|
||
condition { | ||
title = "iam_condition" | ||
description = "IAM condition with limited scope" | ||
expression = local.condition_expression | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
locals { | ||
workload_identity_namespace = var.workload_identity_namespace != "" ? var.workload_identity_namespace : "${var.project_id}.svc.id.goog" | ||
workload_identity_sa = "serviceAccount:${local.workload_identity_namespace}[${var.cloud_proxy_service_account_namespace}/${var.cloud_proxy_service_account_name}]" | ||
} | ||
|
||
resource "google_project_iam_member" "workload_identity_project" { | ||
for_each = ( | ||
var.setup_cloud_proxy_workload_identity && length(var.service_accounts_unique_ids) == 0 ? | ||
{ for permission in local.default_permissions : permission => permission } : | ||
{} | ||
) | ||
|
||
project = var.project_id | ||
role = each.key | ||
member = local.workload_identity_sa | ||
} | ||
|
||
resource "google_project_iam_member" "workload_identity_scoped_project" { | ||
for_each = ( | ||
var.setup_cloud_proxy_workload_identity && length(var.service_accounts_unique_ids) > 0 ? | ||
{ for permission in local.scoped_permissions : permission => permission } : | ||
{} | ||
) | ||
project = var.project_id | ||
role = each.key | ||
member = local.workload_identity_sa | ||
} | ||
|
||
resource "google_project_iam_member" "workload_identity_scoped_service_account_user" { | ||
count = var.setup_cloud_proxy_workload_identity && length(var.service_accounts_unique_ids) > 0 ? 1 : 0 | ||
project = var.project_id | ||
|
||
role = "roles/iam.serviceAccountUser" | ||
member = local.workload_identity_sa | ||
|
||
condition { | ||
title = "iam_condition" | ||
description = "IAM condition with limited scope" | ||
expression = local.condition_expression | ||
} | ||
} | ||
|