-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add condition block to all iam_member type resources (#7)
- Loading branch information
Showing
27 changed files
with
1,454 additions
and
45 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
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,3 @@ | ||
[submodule "examples/modules/terraform-gcp-gcs"] | ||
path = examples/modules/terraform-gcp-gcs | ||
url = https://github.com/honestbank/terraform-gcp-gcs |
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,21 @@ | ||
# Contributing to this repo | ||
|
||
## Testing this repo | ||
In order to test this repo, use Terratest github secrets to be able to run the tests. | ||
* secrets.TERRATEST_GOOGLE_PROJECT | ||
* secrets.TERRATEST_GOOGLE_CREDENTIALS | ||
* secrets.TERRATEST_GCP_SA_EMAIL | ||
|
||
These will ensure the right projects are used with the right credentials. | ||
Additionally for this repo you must enable permissions if they are not already enabled: | ||
* enable permission `iam.serviceAccounts.create` | ||
* enable permission `resourcemanager.folders.getIamPolicy` | ||
|
||
|
||
## A note on service account conditions | ||
Google does not allow you to create conditions on primitive roles. These roles are: | ||
* `roles/viewer` | ||
* `roles/admin` | ||
* `roles/owner` | ||
|
||
Instead, roles should be scoped down such as `roles/storage.objectViewer` or custom roles. see [here](https://cloud.google.com/storage/docs/access-control/iam-permissions) |
26 changes: 26 additions & 0 deletions
26
examples/google_service_account_cross_project_test/bucket.tf
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,26 @@ | ||
locals { | ||
bucket_name = var.run_id | ||
} | ||
|
||
module "test_bucket" { | ||
source = "../modules/terraform-gcp-gcs/modules/gcp_gcs_bucket" | ||
|
||
location = "${var.google_region}2" | ||
name = local.bucket_name | ||
|
||
force_destroy = true | ||
} | ||
|
||
resource "google_storage_bucket_object" "readable_file" { | ||
bucket = module.test_bucket.name | ||
name = "readable.txt" | ||
content = "hello world" | ||
content_type = "text/plain; charset=utf-8" | ||
} | ||
|
||
resource "google_storage_bucket_object" "unreadable_file" { | ||
bucket = module.test_bucket.name | ||
name = "unreadable.txt" | ||
content = "goodbye world" | ||
content_type = "text/plain; charset=utf-8" | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/google_service_account_cross_project_test/inputs.tf
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,28 @@ | ||
variable "google_credentials" { | ||
type = string | ||
description = "GCP Service Account JSON keyfile contents." | ||
} | ||
|
||
variable "google_project" { | ||
type = string | ||
description = "The GCP project to use when initializing the google Terraform provider." | ||
} | ||
|
||
variable "google_region" { | ||
type = string | ||
description = "The GCP region to use when initializing the google Terraform provider." | ||
} | ||
variable "run_id" { | ||
type = string | ||
description = "The unique ID of the run." | ||
} | ||
|
||
variable "cross_project_iam_role_memberships" { | ||
default = {} | ||
description = "A map of GCP project IDs and an associated list of IAM roles to add a membership to." | ||
type = map(list(string)) | ||
validation { | ||
condition = length(var.cross_project_iam_role_memberships) < 2 | ||
error_message = "To maintain a cleaner security model, only one project is currently supported for cross-project role memberships." | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/google_service_account_cross_project_test/outputs.tf
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,3 @@ | ||
output "bucket_name" { | ||
value = module.test_bucket.name | ||
} |
5 changes: 5 additions & 0 deletions
5
examples/google_service_account_cross_project_test/providers.tf
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,5 @@ | ||
provider "google" { | ||
region = var.google_region | ||
project = var.google_project | ||
credentials = var.google_credentials | ||
} |
24 changes: 24 additions & 0 deletions
24
examples/google_service_account_cross_project_test/service_account.tf
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,24 @@ | ||
module "bucket_service_account" { | ||
source = "../../modules/google_service_account" | ||
|
||
account_id = "terratest-${var.run_id}" | ||
display_name = "terratest-${var.run_id}" | ||
description = "An instance of the google_service_account Terraform component module." | ||
|
||
cross_project_iam_role_memberships = var.cross_project_iam_role_memberships | ||
|
||
iam_role_membership_type = "CROSS_PROJECT" | ||
|
||
cross_project_conditions = [ | ||
{ | ||
title = "User can read readable file" | ||
description = "User can read readable file" | ||
expression = <<EOF | ||
resource.service == 'storage.googleapis.com' && | ||
resource.name == 'projects/_/buckets/${local.bucket_name}/readable.txt' | ||
EOF | ||
} | ||
] | ||
|
||
project = var.google_project | ||
} |
26 changes: 26 additions & 0 deletions
26
examples/google_service_account_test_with_condition/bucket.tf
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,26 @@ | ||
locals { | ||
bucket_name = var.run_id | ||
} | ||
|
||
module "test_bucket" { | ||
source = "../modules/terraform-gcp-gcs/modules/gcp_gcs_bucket" | ||
|
||
location = "${var.google_region}2" | ||
name = local.bucket_name | ||
|
||
force_destroy = true | ||
} | ||
|
||
resource "google_storage_bucket_object" "readable_file" { | ||
bucket = module.test_bucket.name | ||
name = "readable.txt" | ||
content = "hello world" | ||
content_type = "text/plain; charset=utf-8" | ||
} | ||
|
||
resource "google_storage_bucket_object" "unreadable_file" { | ||
bucket = module.test_bucket.name | ||
name = "unreadable.txt" | ||
content = "goodbye world" | ||
content_type = "text/plain; charset=utf-8" | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/google_service_account_test_with_condition/inputs.tf
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,18 @@ | ||
variable "google_credentials" { | ||
type = string | ||
description = "GCP Service Account JSON keyfile contents." | ||
} | ||
|
||
variable "google_project" { | ||
type = string | ||
description = "The GCP project to use when initializing the google Terraform provider." | ||
} | ||
|
||
variable "google_region" { | ||
type = string | ||
description = "The GCP region to use when initializing the google Terraform provider." | ||
} | ||
variable "run_id" { | ||
type = string | ||
description = "The unique ID of the run." | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/google_service_account_test_with_condition/outputs.tf
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,3 @@ | ||
output "bucket_name" { | ||
value = module.test_bucket.name | ||
} |
5 changes: 5 additions & 0 deletions
5
examples/google_service_account_test_with_condition/providers.tf
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,5 @@ | ||
provider "google" { | ||
region = var.google_region | ||
project = var.google_project | ||
credentials = var.google_credentials | ||
} |
23 changes: 23 additions & 0 deletions
23
examples/google_service_account_test_with_condition/service_account.tf
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,23 @@ | ||
module "bucket_service_account" { | ||
source = "../../modules/google_service_account" | ||
|
||
account_id = "terratest-${var.run_id}" | ||
display_name = "terratest-${var.run_id}" | ||
description = "An instance of the google_service_account Terraform component module." | ||
|
||
in_project_roles = ["roles/viewer"] | ||
iam_role_membership_type = "IN_PROJECT" | ||
|
||
in_project_conditions = [ | ||
{ | ||
title = "User can read readable file" | ||
description = "User can read readable file" | ||
expression = <<EOF | ||
resource.service == 'storage.googleapis.com' && | ||
resource.name == 'projects/_/buckets/${local.bucket_name}/readable.txt' | ||
EOF | ||
} | ||
] | ||
|
||
project = var.google_project | ||
} |
Submodule terraform-gcp-gcs
added at
7fd4ce
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
google_project = "test-terraform-project-01" | ||
google_region = "asia-southeast2" | ||
service_account_host_project = "test-terraform-project-01" | ||
service_account_host_project = "compute-df9f" # This is a project in our GCP to run terratest in. |
Oops, something went wrong.