Skip to content

Commit 9ddb556

Browse files
authored
fix!: use an external git repository (#475)
- Don't enable the Cloud Source Repositories API. - Don't provision a Cloud Source Repository. - Get the Config Sync Git repository with an input variable. - Let users specify the credentials type to authenticate Config Sync with their repositories. Fix #449
1 parent 10ba392 commit 9ddb556

File tree

9 files changed

+32
-73
lines changed

9 files changed

+32
-73
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ super-linter.log
44

55
# GitHub Actions leftovers
66
github_conf
7+
8+
# Terraform
9+
terraform/.terraform

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ To deploy this blueprint you need:
3434
- The `serviceusage.googleapis.com` must be enabled on the project. For more
3535
information about enabling APIs, see
3636
[Enabling and disabling services](https://cloud.google.com/service-usage/docs/enable-disable)
37+
- A Git repository to store the environment configuration.
3738

3839
You create the infastructure using Terraform. The blueprint uses a local [Terraform backend](https://www.terraform.io/docs/language/settings/backends/configuration.html),
3940
but we recommend to configure a [remote backend](https://www.terraform.io/language/settings/backends/configuration#backend-types)
@@ -128,9 +129,14 @@ Users and teams managing tenant apps should not have permissions to change clust
128129

129130
```hcl
130131
project_id = # Google Cloud project ID where to provision resources with the blueprint.
131-
acm_repository_path = # Path on the host running Terraform to store the GKE descriptors to configure the cluster
132+
acm_repository_path = # Path on the host running Terraform to store environment configuration
133+
acm_repository_url = # URL of the repository to store environment configuration
134+
acm_secret_type = # Secret type to authenticate with the Config Sync Git repository
132135
```
133136

137+
For more information about setting `acm_secret_type`, see
138+
[Grant access to Git](https://cloud.google.com/kubernetes-engine/enterprise/config-sync/docs/how-to/installing-config-sync#git-creds-secret).
139+
134140
If you don't provide all the necessary inputs, Terraform will exit with an
135141
error, and will provide information about the missing inputs. For example,
136142
you can create a Terraform variables initialization file and set inputs there.
@@ -145,6 +151,9 @@ Users and teams managing tenant apps should not have permissions to change clust
145151

146152
The provisioning process may take about 15 minutes to complete.
147153

154+
1. [Grant the Config Sync agent access to the Git repository](https://cloud.google.com/kubernetes-engine/enterprise/config-sync/docs/how-to/installing-config-sync#git-creds-secret)
155+
where the environment configuration will be stored.
156+
148157
1. Wait for the GKE cluster to be reported as ready in the [GKE Kuberentes clusters dashboard](https://cloud.google.com/kubernetes-engine/docs/concepts/dashboards#kubernetes_clusters).
149158

150159
### Next steps

terraform/acm.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ resource "google_gke_hub_feature_membership" "acm_feature_member" {
3030
version = var.acm_version
3131
config_sync {
3232
git {
33-
gcp_service_account_email = local.source_repository_service_account_email
34-
sync_repo = google_sourcerepo_repository.configsync-repository.url
35-
sync_branch = var.acm_branch
36-
policy_dir = var.acm_dir
37-
secret_type = "gcpserviceaccount"
33+
sync_repo = var.acm_repository_url
34+
sync_branch = var.acm_branch
35+
policy_dir = var.acm_dir
36+
secret_type = var.acm_secret_type
3837
}
38+
prevent_drift = true
3939
source_format = "unstructured"
4040
}
4141

terraform/iam.tf

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,6 @@ module "project-iam-bindings" {
4747
]
4848
}
4949

50-
# There's no Terraform module for Cloud Source Repositories bindings, so we
51-
# configure it directly
52-
resource "google_sourcerepo_repository_iam_binding" "binding" {
53-
project = google_sourcerepo_repository.configsync-repository.project
54-
repository = google_sourcerepo_repository.configsync-repository.name
55-
56-
role = "roles/viewer"
57-
58-
members = [
59-
local.source_repository_service_account_iam_email,
60-
]
61-
}
62-
6350
module "fl-workload-identity" {
6451
for_each = local.tenants
6552
source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
@@ -85,28 +72,3 @@ module "fl-workload-identity" {
8572
module.service_accounts
8673
]
8774
}
88-
89-
module "cloud-source-repositories-workload-identity" {
90-
source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
91-
version = "27.0.0"
92-
project_id = data.google_project.project.project_id
93-
94-
annotate_k8s_sa = false
95-
k8s_sa_name = "root-reconciler"
96-
location = module.gke.location
97-
name = local.source_repository_service_account_id
98-
namespace = "config-management-system"
99-
use_existing_gcp_sa = true
100-
use_existing_k8s_sa = true
101-
102-
# The workload identity pool must exist before binding
103-
module_depends_on = [
104-
module.gke
105-
]
106-
107-
depends_on = [
108-
# Wait for the service accounts to be ready before trying to load data about them
109-
# Ref: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/1059
110-
module.service_accounts
111-
]
112-
}

terraform/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,8 @@ locals {
7777
list_sa_names = concat(
7878
[for tenant in local.tenants : tenant.tenant_nodepool_sa_name],
7979
[for tenant in local.tenants : tenant.tenant_apps_sa_name],
80-
[local.source_repository_service_account_name]
8180
)
8281

83-
source_repository_service_account_id = module.service_accounts.service_accounts_map[local.source_repository_service_account_name].account_id
84-
source_repository_service_account_name = "fl-source-repository"
85-
source_repository_service_account_email = module.service_accounts.service_accounts_map[local.source_repository_service_account_name].email
86-
source_repository_service_account_iam_email = "serviceAccount:${local.source_repository_service_account_email}"
87-
8882
acm_config_sync_tenant_configuration_package_source_directory_path = abspath("${path.module}/../tenant-config-pkg")
8983

9084
acm_config_sync_destination_directory_path = "${var.acm_repository_path}/${var.acm_dir}"

terraform/services.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ module "project-services" {
5050
"meshconfig.googleapis.com",
5151
"meshtelemetry.googleapis.com",
5252
"monitoring.googleapis.com",
53-
"sourcerepo.googleapis.com",
5453
"spanner.googleapis.com",
5554
"stackdriver.googleapis.com"
5655
]

terraform/source-repository.tf

Lines changed: 0 additions & 18 deletions
This file was deleted.

terraform/tenant-configuration.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ resource "null_resource" "init_acm_repository" {
1919
create_command = <<-EOT
2020
"${local.init_local_acm_repository_script_path}" \
2121
"${var.acm_repository_path}" \
22-
"${google_sourcerepo_repository.configsync-repository.url}" \
22+
"${var.acm_repository_url}" \
2323
"${var.acm_branch}"
2424
EOT
2525

terraform/variables.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,30 @@ variable "enable_confidential_nodes" {
114114
}
115115

116116
variable "acm_version" {
117-
description = "Anthos Config Management version"
117+
description = "Config Management version"
118118
default = ""
119119
type = string
120120
}
121121

122122
variable "acm_branch" {
123123
default = "main"
124-
description = "The Git branch Anthos Config Management will sync to"
124+
description = "The Git branch in the repository that Config Sync will sync with"
125125
type = string
126126
}
127127

128128
variable "acm_dir" {
129129
default = "configsync"
130-
description = "The directory in the repository that Anthos Config Management will sync to"
130+
description = "The directory in the repository that Config Sync will sync with"
131+
type = string
132+
}
133+
134+
variable "acm_repository_url" {
135+
description = "The URL of the repository that Config Sync will sync with"
136+
type = string
137+
}
138+
139+
variable "acm_secret_type" {
140+
description = "Secret type to authenticate with the Config Sync Git repository. Ref: https://cloud.google.com/kubernetes-engine/enterprise/config-sync/docs/how-to/installing-config-sync#git-creds-secret"
131141
type = string
132142
}
133143

0 commit comments

Comments
 (0)