Terraform CDK code for Flight Controller's GCP infrastructure
GCP's infrastructure deployment is divided in two parts viz. base_gcp_infra
and main_gcp_infra
. Reason being we need to setup Artifact registry first before uploading the container image and creating a Cloud Run service using the same image.
Here are the components built in stage base_gcp_infra
:
- Enable relevant API's
- Service Accounts
- Artifact Registry
Subsequently, following components are built in stage main_gcp_infra
:
- Bigquery datasets and tables
- PubSub topic
- EventArc trigger
- Cloud Run service (for event receiver)
- Cloud Run service (for Grafana)
- Load balancing components (NEG, URLMap, Frontend, backend, Global address)
- Authenticate to Google Cloud and set the correct project using
gcloud config set project $MY_PROJECT_ID
- Synth, plan and deploy both infra & Grafana Dashboard.
make gcp-synth
make gcp-plan-all
make gcp-deploy-all
make gcp-build-dependencies
install gcp build dependenciesmake gcp-build-image
build the docker image for cloud runmake gcp-synth
cdktf synth the all the stacksmake gcp-plan-base
cdktf plan the base stackmake gcp-plan-core
cdktf plan the core stackmake gcp-plan-grafana
cdktf plan the grafana stackmake gcp-plan-all
cdktf plan all stacksmake gcp-deploy-base
cdktf deploy the base stackmake gcp-deploy-core
cdktf deploy the core_stackmake gcp-deploy-grafana
cdktf deploy the grafana stackmake gcp-deploy-all
cdktf deploy all stacksmake gcp-destroy-base
cdktf destroy the base stackmake gcp-destroy-core
cdktf destroy core stackmake gcp-destroy-grafana
cdktf destroy grafana stackmake gcp-destroy-all
cdktf destroy all stacksmake gcp-test
gcp specific testsmake gcp-e2e
gcp specific end to end tests
WHilst writing this, running Grafana with Identiy-Aware Proxy is work in progress due to Cognizant integration. Therefore, accessing Grafana from the Cloud Run is not possible.
As a workaround, it is recommended to run the Grafana container locally using the below image on PORT: 3000
:
mirror.gcr.io/grafana/grafana:latest
- Open the side menu by clicking the Grafana icon in the top header.
- In the side menu under
Configuration
you should find a link namedPlugins
. - Type
BigQuery
in the search bar - Select Google BigQuery by "doitintl" from the list.
- Finally, click on
Install
There are two ways to authenticate the BigQuery plugin - either by uploading a Google JWT file, or by automatically retrieving credentials from Google's metadata server. The latter is only available when running Grafana on a GCE virtual machine.
Create a GCP Service Account for a Project
-
Navigate to the
APIs & Services Credentials
page. -
On the Create service account key page, choose key type
JSON
. Then in the Service Account dropdown, choose theNew service account
option: -
Some new fields will appear. Fill in a name for the service account in the
Service account name
field and then choose theBigQuery Data Viewer
andBigQuery Job User
roles from the Role dropdown: -
Click the
Create
button. A JSON key file will be created and downloaded to your computer. Store this file in a secure place as it allows access to your BigQuery data. -
Upload it to Grafana on the datasource Configuration page. You can either upload the file or paste in the contents of the file.
-
The file contents will be encrypted and saved in the Grafana database. Don't forget to save after uploading the file!
A dashboard in Grafana is represented by a JSON object, which stores metadata of its dashboard.
You can create a dashboard by simply uploading the dashboard.json
file located within the infrastructure/gcp
folder:
- Open the side menu by clicking the Grafana icon in the top header.
- In the side menu under
Dashboards
you should find a link namedImport
. - Upload the
dashboard.json
file - Finally, click on
Load
This will create the Dashboard. In case, you decide to add new panels manually, remember to update the dahboard.json
file and commit it along with the source code. This way, everyone can have the same view of dashboard.