Skip to content

Commit 074d470

Browse files
committed
configure gcp access for atlantis
1 parent cd24692 commit 074d470

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

.atlantis.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ version: 3
22
automerge: true
33
autodiscover:
44
mode: auto
5-
delete_source_branch_on_merge: true
65
parallel_plan: true
76
parallel_apply: true
87
abort_on_execution_order_fail: true

infra/gcp/terraform/README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ containing manifests that are deployed to the cluster
4747

4848
## Deploying
4949

50+
- Open a PR and Atlantis will apply and deploy your Terraform changes.
5051
- Ensure you are logged into your GCP account with `gcloud auth application-default login`
5152
- From within a module directory:
5253
- `terraform init` will initialize your local state (refresh modules)
@@ -55,9 +56,49 @@ containing manifests that are deployed to the cluster
5556

5657
## Deleting
5758

58-
- Get approval from a WG K8s Infra lead (ask in [#sig-k8s-infra] before doing this)
59+
- Get approval from a SIG K8s Infra lead (ask in [#sig-k8s-infra] before doing this)
5960
- Ensure you are logged into your GCP account with `gcloud auth application-default login`
6061
- From within a module directory:
6162
- `terraform destroy` will destroy and clean up all created resources
6263

6364
[#sig-k8s-infra]: https://kubernetes.slack.com/messages/sig-k8s-infra
65+
66+
67+
# Bootstrapping Terraform - One Time Setup
68+
69+
Terraform needs to be bootstrapped manually before it can be used. This process was done during Atlantis Setup. It is noted here for completeness and for potential troubleshooting.
70+
71+
This needs to be ran by a person.
72+
73+
```
74+
# Get the ORG_ID
75+
ORG_ID=$(gcloud organizations describe kubernetes.io --format json | jq .name -r | sed 's:.*/::')
76+
77+
# Create the k8s-infra-seed project
78+
79+
gcloud projects create k8s-infra-seed --organization $ORG_ID --name "K8s Infra Seed" --billing
80+
81+
# Create the terraform service account
82+
83+
gcloud iam service-accounts create atlantis —-display-name Atlantis --project k8s-infra-seed
84+
85+
# Allow the Atlantis Kubernetes Service Account in k8s-infra-prow project to assume this service account
86+
87+
gcloud iam service-accounts add-iam-policy-binding [email protected] \
88+
--member "serviceAccount:k8s-infra-prow.svc.id.goog[atlantis/atlantis]" --role='roles/iam.workloadIdentityUser'
89+
90+
# Create the State Bucket and version it
91+
gcloud storage buckets create gs://k8s-infra-tf-state --location=us --uniform-bucket-level-access
92+
gcloud storage buckets update gs://k8s-infra-tf-state --versioning
93+
94+
# Enable Google APIs
95+
gcloud services enable container.googleapis.com run.googleapis.com cloudbuild.googleapis.com --async
96+
97+
# Privilege the terraform service account
98+
gcloud organizations add-iam-policy-binding --organization $ORG_ID \
99+
--member "serviceAccount:[email protected]" --role='roles/resourcemanager.organizationAdmin'
100+
gcloud organizations add-iam-policy-binding --organization $ORG_ID \
101+
--member "serviceAccount:[email protected]" --role='roles/owner'
102+
gcloud organizations add-iam-policy-binding --organization $ORG_ID \
103+
--member "serviceAccount:[email protected]" --role='roles/billing.admin'
104+
```

kubernetes/gke-utility/atlantis/extras.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ spec:
1313
secretStoreRef:
1414
kind: ClusterSecretStore
1515
name: k8s-infra-prow
16+
---
17+
apiVersion: v1
18+
kind: ServiceAccount
19+
metadata:
20+
name: atlantis
21+
annotations:
22+
iam.gke.io/gcp-service-account: [email protected]

kubernetes/gke-utility/atlantis/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ patchesStrategicMerge:
2525
spec:
2626
template:
2727
spec:
28+
serviceAccountName: atlantis
2829
containers:
2930
- name: atlantis
3031
env:

0 commit comments

Comments
 (0)