Skip to content

Commit 6b8be4d

Browse files
authored
Merge pull request harness#135 from schoudhury/main
fixed minor issues in the terraform tutorial
2 parents bb8f666 + 58b6296 commit 6b8be4d

File tree

1 file changed

+56
-37
lines changed

1 file changed

+56
-37
lines changed

tutorials/platform/onboard-terraform-provider.md

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Onboard with Terraform Provider
55

66
# Onboard with Terraform Provider
77

8-
The [Harness Terraform Provider](https://registry.terraform.io/providers/harness/harness/) enables automated lifecycle management of the Harness Platform using Terraform. Currently the following Harness entities can be managed via the provider.
8+
The [Harness Terraform Provider](https://registry.terraform.io/providers/harness/harness/) enables automated lifecycle management of the Harness Platform using Terraform. You can onboard onto Harness on day 1 and also make day 2 changes using tthis Provider. Currently the following Harness resources can be managed via the Provider.
99

1010
- Organizations
1111
- Projects
@@ -17,7 +17,7 @@ The [Harness Terraform Provider](https://registry.terraform.io/providers/harness
1717
- Permissions
1818
- Secrets
1919

20-
This tutorial shows you how to manage all the above entities except Permissions and Secrets.
20+
This tutorial shows you how to manage all the above resources except Permissions and Secrets.
2121

2222
## Prerequisite
2323

@@ -30,7 +30,7 @@ terraform -version
3030

3131
### Get Your Harness Account ID
3232

33-
You will also need to provde your Harness accountId as an input parameter to the terraform provider. This accountId is present in every Harness URL. For example, in the following URL
33+
You will also need to provde your Harness accountId as an input parameter to the Provider. This accountId is present in every Harness URL. For example, in the following URL
3434

3535
```
3636
https://app.harness.io/ng/#/account/6_vVHzo9Qeu9fXvj-AcQCb/settings/overview
@@ -50,9 +50,9 @@ You can create your own main.tf file. For this tutorial, we will use a sample ma
5050
curl -LO https://raw.githubusercontent.com/harness-apps/developer-hub-apps/main/terraform/main.tf
5151
```
5252

53-
### Specify the harness provider
53+
### Configure the Harness Provider
5454

55-
Open the `main.tf` file in a text editor and replace `PUT_YOUR_HARNESS_ACCOUNTID_HERE` and `PUT_YOUR_API_KEY_TOKEN_HERE` with your Harness accountId and PAT values respectively.
55+
Open the `main.tf` file in a text editor and replace `PUT_YOUR_HARNESS_ACCOUNTID_HERE` and `PUT_YOUR_API_KEY_TOKEN_HERE` with your Harness accountId and API key token values respectively.
5656

5757
```
5858
terraform {
@@ -76,7 +76,7 @@ provider "harness" {
7676

7777
Review the`main.tf` file for the operations that terraform is going to execute for us. As you can see, the sample first creates a new organization as well as a new project inside that organization. It then creates a helm chart service that will be deployed to Kubernetes infrastructure running in a pre-production environment. A new pipeline is then created to make this service deployment happen.
7878

79-
At every step, you can use existing organizations, projects, services, environments if you so desire. We will now review the terraform resource definition for each of these entities.
79+
At every step, you can use existing organizations, projects, services, environments if you so desire. We will now review the terraform resource definition for each of these resources.
8080

8181
#### Create a new organization
8282
```
@@ -94,6 +94,9 @@ resource "harness_platform_project" "project" {
9494
identifier = "projbytf"
9595
org_id = "orgbytf"
9696
description = "Created through Terraform"
97+
depends_on = [
98+
harness_platform_organization.org
99+
]
97100
}
98101
```
99102

@@ -105,9 +108,7 @@ resource "harness_platform_connector_helm" "helmconn" {
105108
name = "HelmConnByTF"
106109
identifier = "helmconnbytf"
107110
description = "Created through Terraform"
108-
yaml = <<-EOT
109-
...
110-
EOT
111+
url = "https://charts.bitnami.com/bitnami"
111112
}
112113
```
113114

@@ -116,28 +117,33 @@ resource "harness_platform_connector_helm" "helmconn" {
116117
This service will use the above Helm connector to deploy a Helm Chart.
117118
```
118119
resource "harness_platform_service" "service" {
119-
identifier = "identifier"
120-
name = "name"
121-
description = "test"
122-
org_id = "org_id"
123-
project_id = "project_id"
120+
name = "ServiceByTF"
121+
identifier = "servicebytf"
122+
description = "Created through Terraform"
123+
org_id = "orgbytf"
124+
project_id = "projbytf"
124125
yaml = <<-EOT
125-
...
126+
...
126127
EOT
128+
129+
depends_on = [
130+
harness_platform_project.project
131+
]
127132
}
128133
```
129134

130-
#### Create a kubernetes connector at account level
135+
#### Create a Kubernetes connector at account level
131136

132-
We will deploy the service defined earlier to the Kubernetes cluster associated with this connector.
137+
We will deploy the service defined earlier to the Kubernetes cluster associated with this connector. This connector will inherit the permissions of a delegate named `firstk8sdel` which you can install using the Kubernetes delegate instructions from [Install Delegate](/tutorials/platform/install-delegate)
133138
```
134139
resource "harness_platform_connector_kubernetes" "k8sconn" {
135-
name = "K8SConnByTF"
136-
identifier = "k8sconnbytf"
137-
description = "Created through Terraform"
138-
yaml = <<-EOT
139-
...
140-
EOT
140+
name = "K8SConnByTF"
141+
identifier = "k8sconnbytf"
142+
description = "Created through Terraform"
143+
144+
inherit_from_delegate {
145+
delegate_selectors = ["firstk8sdel"]
146+
}
141147
}
142148
```
143149

@@ -146,15 +152,19 @@ resource "harness_platform_connector_kubernetes" "k8sconn" {
146152
Create an environment inside the project that refers to the Kubernetes connector we defined in the previous step. Environments can be of `PreProduction` or `Production` types and we will use the former for this example.
147153
```
148154
resource "harness_platform_environment" "env" {
149-
identifier = "identifier"
150-
name = "name"
155+
name = "EnvByTF"
156+
identifier = "envbytf"
151157
org_id = "orgbytf"
152158
project_id = "projbytf"
153159
tags = []
154160
type = "PreProduction"
155161
yaml = <<-EOT
156-
...
162+
...
157163
EOT
164+
165+
depends_on = [
166+
harness_platform_project.project
167+
]
158168
}
159169
```
160170

@@ -163,8 +173,8 @@ resource "harness_platform_environment" "env" {
163173
Create a infrastructure definition in the environment we just created.
164174
```
165175
resource "harness_platform_infrastructure" "infra" {
166-
identifier = "preprodk8s"
167-
name = "preprod-k8s"
176+
name = "InfraByTF"
177+
identifier = "infrabytf"
168178
org_id = "orgbytf"
169179
project_id = "projbytf"
170180
env_id = "envbytf"
@@ -173,6 +183,10 @@ resource "harness_platform_infrastructure" "infra" {
173183
yaml = <<-EOT
174184
...
175185
EOT
186+
187+
depends_on = [
188+
harness_platform_environment.env
189+
]
176190
}
177191
```
178192

@@ -181,19 +195,24 @@ resource "harness_platform_infrastructure" "infra" {
181195
Every run of this pipeline will deploy a particular version of the service onto the Kubernetes cluster.
182196
```
183197
resource "harness_platform_pipeline" "pipeline" {
184-
identifier = "identifier"
185-
org_id = "orgIdentifier"
186-
project_id = "projectIdentifier"
187-
name = "name"
188-
yaml = <<-EOT
189-
...
198+
name = "PipelineByTF"
199+
identifier = "pipelinebytf"
200+
org_id = "orgbytf"
201+
project_id = "projbytf"
202+
203+
yaml = <<-EOT
204+
...
190205
EOT
206+
207+
depends_on = [
208+
harness_platform_infrastructure.infra
209+
]
191210
}
192211
```
193212

194213
## Run terraform init, plan and apply
195214

196-
Initialize terraform. This will download the harnes provider onto your machine.
215+
Initialize terraform. This will download the Harness Provider onto your machine.
197216
```
198217
terraform init
199218
```
@@ -203,7 +222,7 @@ Run the following step to see exactly the changes terraform is going to make on
203222
terraform plan
204223
```
205224

206-
Finally, run this step to make terraform onboard your entities onto the Harness Platform.
225+
Finally, run this step to make terraform onboard your resources onto the Harness Platform.
207226
```
208227
terraform apply
209228
```
@@ -233,7 +252,7 @@ Apply complete! Resources: 8 added, 0 changed, 0 destroyed.
233252

234253
## Verify and run pipeline on Harness UI
235254

236-
On Harness UI, you can go to Account Settings --> Organizations to see the new organization. Click View Projects to see the new project. Click the project and go into the "Continuous Delivery" module. When you click Pipelines now, you can see the new pipeline has been created. You can run this pipeline as long as you have previously installed a delegate with name `firstk8sdel` using the Kubernetes delegate instructions from the [Install Delegate](/tutorials/platform/install-delegate).
255+
On Harness UI, you can go to Account Settings --> Organizations to see the new organization. Click View Projects to see the new project. Click the project and go into the "Continuous Delivery" module. When you click Pipelines now, you can see the new pipeline has been created. You can run this pipeline as long as you have previously installed a delegate with name `firstk8sdel` using the Kubernetes delegate instructions from [Install Delegate](/tutorials/platform/install-delegate). As previously shown, you can change the delegate name to any other delegate you may have installed by editing the Kubernetes connector resource of the main.tf file.
237256

238257
## Run terraform destroy
239258

0 commit comments

Comments
 (0)