Skip to content
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

feat(module): Add ML Infra Projects Module and 4-projects refactor #40

Merged
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
427fb23
first commit
caetano-colin May 9, 2024
7b6da01
restore files
caetano-colin May 9, 2024
f81d4cf
add new files
caetano-colin May 9, 2024
0cd451f
add copies
caetano-colin May 9, 2024
29e6e70
remove old files
caetano-colin May 9, 2024
5c13ce8
add sa
caetano-colin May 9, 2024
03cc68e
add newline to EOF
caetano-colin May 10, 2024
b5b1cf1
add outputs.tf
caetano-colin May 10, 2024
a3bab22
remove remote.tff from inside module
caetano-colin May 13, 2024
ca7c7d2
chore(format): terraform fmt on dns module
caetano-colin May 13, 2024
8676a28
add env kms project id as variable
caetano-colin May 14, 2024
ba35d53
Merge branch 'main' of github.com:caetano-colin/terraform-google-ente…
caetano-colin May 14, 2024
0d4f692
generate docs
caetano-colin May 14, 2024
be0ba50
Merge branch 'format/fmt-dns-module' into refactor/ml-infra-projects
caetano-colin May 14, 2024
38069e2
Revert "Merge branch 'format/fmt-dns-module' into refactor/ml-infra-p…
caetano-colin May 14, 2024
b6c863c
update to 2024
caetano-colin May 14, 2024
56eceb0
add title and description to ml single project
caetano-colin May 15, 2024
2902891
add project_name as variable on ml_single_project
caetano-colin May 15, 2024
3742d5b
add missing locals.tf
caetano-colin May 15, 2024
5e42646
feat: parametrize prevent_destroy for project key
caetano-colin May 15, 2024
7ffece7
Update 4-projects/modules/ml_single_project/outputs.tf
caetano-colin May 15, 2024
82f73eb
Update 4-projects/modules/ml_single_project/outputs.tf
caetano-colin May 15, 2024
8e861fd
Update 4-projects/modules/ml_infra_projects/variables.tf
caetano-colin May 15, 2024
87cbc5f
chore: enabled_apis to locals
caetano-colin May 15, 2024
4bb5f13
Merge branch 'refactor/ml-infra-projects' of github.com:caetano-colin…
caetano-colin May 15, 2024
6f81967
add space
caetano-colin May 15, 2024
caafacb
Update 4-projects/modules/ml_single_project/outputs.tf
caetano-colin May 15, 2024
e6d031b
Update 4-projects/modules/ml_single_project/variables.tf
caetano-colin May 15, 2024
8d263ae
Update 4-projects/modules/ml_single_project/variables.tf
caetano-colin May 15, 2024
e6735c1
Update 4-projects/modules/ml_single_project/variables.tf
caetano-colin May 15, 2024
30e67f7
update description
caetano-colin May 15, 2024
98b598f
Merge branch 'refactor/ml-infra-projects' of github.com:caetano-colin…
caetano-colin May 15, 2024
32ba9ac
chore: add trailing dots to where missing
caetano-colin May 15, 2024
83346f5
remove default value
caetano-colin May 15, 2024
bea34fa
restore dns file
caetano-colin May 15, 2024
a15a1c8
Merge branch 'main' of github.com:caetano-colin/terraform-google-ente…
caetano-colin May 15, 2024
a963b03
externalize project suffixes
caetano-colin May 15, 2024
e30ae29
externalize application name
caetano-colin May 15, 2024
5ba54de
add files again
caetano-colin May 22, 2024
2955195
remove files again
caetano-colin May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 4-projects/business_unit_3/shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| keyring\_name | Name to be used for KMS Keyring | `string` | `"sample-keyring"` | no |
| location\_gcs | Case-Sensitive Location for GCS Bucket | `string` | `"US"` | no |
| location\_kms | Case-Sensitive Location for KMS Keyring | `string` | `"us"` | no |
| prevent\_destroy | Prevent Project Key destruction. | `bool` | `true` | no |
| project\_budget | Budget configuration.<br> budget\_amount: The amount to use as the budget.<br> alert\_spent\_percents: A list of percentages of the budget to alert on when threshold is exceeded.<br> alert\_pubsub\_topic: The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}`.<br> alert\_spend\_basis: The type of basis used to determine if spend has passed the threshold. Possible choices are `CURRENT_SPEND` or `FORECASTED_SPEND` (default). | <pre>object({<br> budget_amount = optional(number, 1000)<br> alert_spent_percents = optional(list(number), [1.2])<br> alert_pubsub_topic = optional(string, null)<br> alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> })</pre> | `{}` | no |
| remote\_state\_bucket | Backend bucket to load Terraform Remote State Data from previous steps. | `string` | n/a | yes |
| tfc\_org\_name | Name of the TFC organization | `string` | `""` | no |
Expand Down
36 changes: 36 additions & 0 deletions 4-projects/business_unit_3/shared/ml_infra_projects.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.
*/

module "ml_infra_project" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to ml_infra_projects

source = "../../modules/ml_infra_projects"

org_id = local.org_id
folder_id = local.common_folder_name
billing_account = local.billing_account
environment = "common"
key_rings = local.shared_kms_key_ring
business_code = "bu3"
billing_code = "1234"
primary_contact = "[email protected]"
secondary_contact = "[email protected]"
cloud_source_artifacts_repo_name = var.cloud_source_artifacts_repo_name
cloud_source_service_catalog_repo_name = var.cloud_source_service_catalog_repo_name
remote_state_bucket = var.remote_state_bucket
artifacts_infra_pipeline_sa = module.infra_pipelines[0].terraform_service_accounts["bu3-artifact-publish"]
service_catalog_infra_pipeline_sa = module.infra_pipelines[0].terraform_service_accounts["bu3-service-catalog"]
environment_kms_project_id = ""
caetano-colin marked this conversation as resolved.
Show resolved Hide resolved
prevent_destroy = var.prevent_destroy
}
12 changes: 6 additions & 6 deletions 4-projects/business_unit_3/shared/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,30 @@ output "enable_cloudbuild_deploy" {

output "service_catalog_project_id" {
description = "Service Catalog Project ID."
value = try(module.app_service_catalog_project[0].project_id, "")
value = module.ml_infra_project.service_catalog_project_id
}

output "common_artifacts_project_id" {
description = "App Infra Artifacts Project ID"
value = try(module.app_infra_artifacts_project[0].project_id, "")
value = module.ml_infra_project.common_artifacts_project_id
}

output "service_catalog_repo_name" {
description = "The name of the Service Catalog repository"
value = google_sourcerepo_repository.service_catalog.name
value = module.ml_infra_project.service_catalog_repo_name
}

output "service_catalog_repo_id" {
description = "ID of the Service Catalog repository"
value = google_sourcerepo_repository.service_catalog.id
value = module.ml_infra_project.service_catalog_repo_id
}

output "artifacts_repo_name" {
description = "The name of the Artifacts repository"
value = google_sourcerepo_repository.artifact_repo.name
value = module.ml_infra_project.artifacts_repo_name
}

output "artifacts_repo_id" {
description = "ID of the Artifacts repository"
value = google_sourcerepo_repository.artifact_repo.id
value = module.ml_infra_project.artifacts_repo_id
}
6 changes: 6 additions & 0 deletions 4-projects/business_unit_3/shared/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ variable "cloud_source_artifacts_repo_name" {
description = "Name to give the could source repository for Artifacts"
type = string
}

variable "prevent_destroy" {
description = "Prevent Project Key destruction."
type = bool
default = true
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2021 Google LLC
* 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.
Expand All @@ -15,6 +15,7 @@
*/

locals {
artifacts_project_suffix = "artifacts"
caetano-colin marked this conversation as resolved.
Show resolved Hide resolved
artifact_tf_sa_roles = [
"roles/artifactregistry.admin",
"roles/cloudbuild.builds.editor",
Expand All @@ -27,16 +28,15 @@ locals {

}
module "app_infra_artifacts_project" {
source = "../../modules/single_project"
# count = local.enable_cloudbuild_deploy ? 1 : 0
source = "../ml_single_project"

org_id = local.org_id
billing_account = local.billing_account
folder_id = local.common_folder_name
environment = "common"
org_id = var.org_id
billing_account = var.billing_account
folder_id = var.folder_id
environment = var.environment
project_budget = var.project_budget
project_prefix = local.project_prefix
key_rings = local.shared_kms_key_ring
project_prefix = var.project_prefix
key_rings = var.key_rings
remote_state_bucket = var.remote_state_bucket
activate_apis = [
"artifactregistry.googleapis.com",
Expand All @@ -49,48 +49,40 @@ module "app_infra_artifacts_project" {
"sourcerepo.googleapis.com",
]
# Metadata
project_suffix = "artifacts"
application_name = "app-infra-artifacts"
billing_code = "1234"
primary_contact = "[email protected]"
secondary_contact = "[email protected]"
business_code = "bu3"
project_suffix = local.artifacts_project_suffix
application_name = "app-infra-artifacts"
caetano-colin marked this conversation as resolved.
Show resolved Hide resolved
billing_code = var.billing_code
primary_contact = var.primary_contact
secondary_contact = var.secondary_contact
business_code = var.business_code
environment_kms_project_id = var.environment_kms_project_id
project_name = "${var.project_prefix}-${local.env_code}-${var.business_code}${local.artifacts_project_suffix}"
prevent_destroy = var.prevent_destroy
}

# resource "google_kms_crypto_key" "ml_key" {
# for_each = toset(local.shared_kms_key_ring)
# name = module.app_infra_artifacts_project[0].project_name
# key_ring = each.key
# rotation_period = var.key_rotation_period
# lifecycle {
# prevent_destroy = false
# }
# }

resource "google_kms_crypto_key_iam_member" "ml_key" {
for_each = module.app_infra_cloudbuild_project[0].kms_keys
for_each = module.app_infra_artifacts_project.kms_keys
crypto_key_id = each.value.id
role = "roles/cloudkms.admin"
member = "serviceAccount:${module.infra_pipelines[0].terraform_service_accounts["bu3-artifact-publish"]}"
member = "serviceAccount:${var.artifacts_infra_pipeline_sa}"
}

resource "google_project_iam_member" "artifact_tf_sa_roles" {
for_each = toset(local.artifact_tf_sa_roles)
project = module.app_infra_artifacts_project[0].project_id
project = module.app_infra_artifacts_project.project_id
role = each.key
member = "serviceAccount:${module.infra_pipelines[0].terraform_service_accounts["bu3-artifact-publish"]}"
member = "serviceAccount:${var.artifacts_infra_pipeline_sa}"
}

// Add Service Agent for Cloud Build
resource "google_project_iam_member" "artifact_cloudbuild_agent" {
project = module.app_infra_artifacts_project[0].project_id
project = module.app_infra_artifacts_project.project_id
role = "roles/secretmanager.secretAccessor"
member = "serviceAccount:${module.app_infra_artifacts_project[0].project_number}@cloudbuild.gserviceaccount.com"
member = "serviceAccount:${module.app_infra_artifacts_project.project_number}@cloudbuild.gserviceaccount.com"
}

// Add Repository for Artifact repo

resource "google_sourcerepo_repository" "artifact_repo" {
project = module.app_infra_artifacts_project[0].project_id
project = module.app_infra_artifacts_project.project_id
name = var.cloud_source_artifacts_repo_name
}
19 changes: 19 additions & 0 deletions 4-projects/modules/ml_infra_projects/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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.
*/

locals {
env_code = element(split("", var.environment), 0)
}
45 changes: 45 additions & 0 deletions 4-projects/modules/ml_infra_projects/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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.
*/

output "service_catalog_project_id" {
description = "Service Catalog Project ID."
value = try(module.app_service_catalog_project.project_id, "")
}

output "common_artifacts_project_id" {
description = "App Infra Artifacts Project ID."
value = try(module.app_infra_artifacts_project.project_id, "")
}

output "service_catalog_repo_name" {
description = "The name of the Service Catalog repository."
value = google_sourcerepo_repository.service_catalog.name
}

output "service_catalog_repo_id" {
description = "ID of the Service Catalog repository."
value = google_sourcerepo_repository.service_catalog.id
}

output "artifacts_repo_name" {
description = "The name of the Artifacts repository."
value = google_sourcerepo_repository.artifact_repo.name
}

output "artifacts_repo_id" {
description = "ID of the Artifacts repository."
value = google_sourcerepo_repository.artifact_repo.id
}
Loading