Create gcloud infrastructure
Clone the infctl
repo if you have not yet done so. We will work on the assumption that we are working in a home directory called projects
.
cd ~/projects
if [ ! -d "infctl-cli" ]; then git clone https://codeberg.org/headshed/infctl-cli cd infctl-clielse cd infctl-clifi
we need to configure some environment variables to let our build know some things about our project.
cp .env.gcloud-example .env
edit our newly created .env
file and give it values that are appropriate to our gcloud account, for example:
PROJECT_NAME="my-very-own-dev-lab"EMAIL="your.email@mailsomewhere.com"APP_DOMAIN_NAME="atestdr.yourdomain.com"
where each of these variables represent:
- your project name, often called the project id in gcloud
- your email that you wish to be identified with for DNS and TLS encryption
- the domain name you want to use for this project when it is on line
Activate these in the current shell with:
source .env
Before we go any further, we need to confirm we have our gcloud environment ready and configured:
gcloud compute instances list --project="$PROJECT_NAME" \&& gcloud compute disks list --project="$PROJECT_NAME" \&& gcloud compute firewall-rules list --project="$PROJECT_NAME" \&& gcloud storage buckets list --project="$PROJECT_NAME"
We should see pretty much an empty list but for default rules assigned for us by Google to our project to accept SSH, RDP and ICMP traffic - 4 lines in all.
To build the infrastructure :
LOGFORMAT=none infctl -f gcloud/tf/scripts/build-gcloud-k3s-pipeline.json
You should see a successful build ending with something like:
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:k3s_vm_public_ip = "xxx.xxx.xxx.xxx"project_number = "..233434.."✅ Step completed: run tofu✅ 🚀 Pipeline completed successfully
Take a note of public IP address assigned to your VM as in xxx.xxx.xxx.xxx
in the above example.
You need to create an A record
in your DNS console to point to this address, using the environment name you set for your app earlier
echo $APP_DOMAIN_NAME<whatever you set your application full domain name to>
Setting an A Record in your chosen or Cloudflare DNS
Section titled “Setting an A Record in your chosen or Cloudflare DNS”If you are using Cloudflare DNS, you can follow the below or use as a guide for your chosen DNS console…
- Log in to your Cloudflare dashboard.
- Select your domain.
- Go to the DNS tab.
- Click Add record.
- Choose A as the record type.
- Enter your subdomain (e.g.,
atestdr
) in the Name field. - Enter your VM’s public IP address in the IPv4 address field.
- Set the record to be DNS only and a low TTL, for example 5 min.
- Click Save.
Your domain should now point to your VM’s public IP.