Add Default Resources to a Project
Add a default connector and infrastructure definition to a project.
Add a new Kubernetes connector using a delegate
Open the
custom-template-libraryin VSCode andReopen in ContainerCreate a new branch called
feature/infrastructure-connectorsCreate a new file called
harness_connectors.tfin the root of theharness-projectdirectory
resource "harness_platform_connector_kubernetes" "k8s_dev_infra" {
identifier = "k8s_dev_infra"
name = "K8s Dev Infra"
org_id = data.harness_platform_organization.selected.id
project_id = data.harness_platform_project.selected.id
description = "Kubernetes Connector"
tags = local.common_tags_tuple
inherit_from_delegate {
delegate_selectors = [var.k8s_dev_infra_delegate]
}
}Open the file
harness-project/variables.tfto add the following variable.
Open the file
harness-project/terraform.tfvars.exampleto add the following helper example
In terminal, change directory to the new folder
cd harness-project, open the fileterraform.tfvars.exampleand save as a new file (CTL+SHIFT+S on windows or CMD+SHIFT+S on Mac). The file should be namedterraform.tfvarsFor local testing, you will need a terraform provider configuration. Run the command
mise provider
The
providers.tffile includes the two variablesharness_platform_urlandharness_platform_account. Theharness-projectmandates those in thevariables.tf. Remove or Comment out the entries from theproviders.tfModify the
terraform.tfvarsto set the variables:
harness_platform_account
Should be your Harness account number
harness_platform_key
Personal Access Token with permissions to the provided account
organization_id
For the purposes of this test, use the workshop organization Lab
project_name
Provide a new name for a test project - Lab Exercise
In terminal, run the command
mise deploy:dryrun. You should see a Plan for 24 resources to be added. This will run the commandstofu init; tofu fmt; tofu planusing Mise
Run a
mise deployto execute the full deployment of the codebase against your account. This will run the commandstofu init; tofu fmt; tofu plan; tofu applyusing Mise
Navigate to your new project in your Harness Account to verify the results.
Commit your code locally and push the branch
Add a new default infrastructure definition
Create a new file called
harness_infradefs.tfin the root of theharness-projectdirectory
Open the file
harness-project/variables.tfto add the following variable.
Open the file
harness-project/terraform.tfvars.exampleto add the following helper example
Open the file
harness-project/terraform.tfvarsto add the following value for testing
In terminal, run the command
mise deploy:dryrun. You should see a Plan for 1 resource to be added. This will run the commandstofu init; tofu fmt; tofu planusing Mise
Run a
mise deployto execute the full deployment of the codebase against your account. This will run the commandstofu init; tofu fmt; tofu plan; tofu applyusing Mise
Navigate to your new project to verify the results. This adds a new infrastructure definition in the
Devenvironment.Clean up your new project by deleting the resources
mise teardown. This will destroy the resources, remove the state files and providers, and then remove theproviders.tffile.Commit your code locally and push the branch
Roll out changes to your projects
Navigate to the
Solutions FactoryprojectOpen the IACM Workspaces and select the
Lab_Custom-ProjectworkspaceSwitch the Configuration tab for the workspace and change the branch to use your new branch
feature/infrastructure-connectorsClick
Drift Check. The results will show that two new items will be added.Navigate back to the workspace and run
Provision. Wait for the execution to complete to verify that everything has worked.Navigate to the
Harness Platform Managementorganization, go to the Code Repository module, and clickcustom-template-libraryCreate and merge a new Pull-Request and delete the branch
Navigate to IACM Workspace, select the workspace
Lab_Custom-Projectand in the Configuration tab change the branch to use your new branchmainRun the pipeline
Bulk Workspace Managementby navigating to the pipelines in theSolutions Factoryproject and filtering your pipelines by typingiacmin the pipeline search barWORKSPACE_SOURCE =
customWORKSPACE_TYPE =
harness-projectWORKSPACE_STATUS =
anyWORKSPACE_CHANGE_SOURCE =
noWORKSPACE_ACTION =
apply
After the
Bulk Workspace Managementcompletes, it will have started new executions of theProvision Workspacepipeline for each matching IACM Workspace. Approve the changes to the existing workspaces and verify the changes have been applied.Each project will have the new connector and infrastructure definition
The
Custom Projectshould have no changes applied
In your local VSCode repository, check out branch main to pull your changes and delete your local branch feature/infrastructure-connectors
Last updated
Was this helpful?