Skip to content

Commit ea63937

Browse files
authored
feat: new process resource (#871)
feat: consume custom step template (#897) chore: migration guide for v1.0.0 (#902) chore: Explain implementation of version-controlled resources (#911) chore: Add examples for different configuration scenarios chore: Deprecate deployment_process and runbook_process resources in favor of new process resource (#6)
1 parent 4b585c6 commit ea63937

File tree

133 files changed

+11858
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+11858
-256
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ This repository contains the source code for the Terraform Provider for [Octopus
66

77
## 🪄 Installation and Configuration
88

9-
The Terraform Provider for Octopus Deploy is available via the Terraform Registry: [OctopusDeployLabs/octopusdeploy](https://registry.terraform.io/providers/OctopusDeployLabs/octopusdeploy). To install this provider, copy and paste this code into your Terraform configuration:
9+
The Terraform Provider for Octopus Deploy is available via the Terraform Registry: [OctopusDeployLabs/octopusdeploy](https://registry.terraform.io/providers/OctopusDeploy/octopusdeploy). To install this provider, copy and paste this code into your Terraform configuration:
1010

1111
```hcl
1212
terraform {
1313
required_providers {
1414
octopusdeploy = {
15-
source = "OctopusDeployLabs/octopusdeploy"
16-
version = "version-number" # example: 0.21.1
15+
source = "OctopusDeploy/octopusdeploy"
16+
version = "version-number" # example: 1.0.0
1717
}
1818
}
1919
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
page_title: "Create a new Version-Controlled Project"
3+
subcategory: "Examples"
4+
---
5+
6+
# Create a new Version-Controlled Project
7+
8+
This example show how to configure new version-controlled Project and let application team manage it with OCL
9+
10+
## Existing ecosystem
11+
These resources are the "pre-requisites" and assumed already exists
12+
```terraform
13+
resource "octopusdeploy_lifecycle" "example" {
14+
description = "This is the default lifecycle."
15+
name = "Test Lifecycle"
16+
}
17+
18+
resource "octopusdeploy_project_group" "example" {
19+
description = "The project group."
20+
name = "Version Controlled Project Group"
21+
}
22+
```
23+
24+
## Version-Controlled Project
25+
```terraform
26+
resource "octopusdeploy_git_credential" "app"{
27+
name = "Git credential"
28+
password = "Password"
29+
username = "Username"
30+
}
31+
32+
resource "octopusdeploy_project" "app" {
33+
name = "Version-Controlled Project "
34+
project_group_id = octopusdeploy_project_group.example.id
35+
lifecycle_id = octopusdeploy_lifecycle.example.id
36+
is_version_controlled = true
37+
git_library_persistence_settings {
38+
git_credential_id = octopusdeploy_git_credential.app.id
39+
url = "<git-url>"
40+
default_branch = "main"
41+
base_path = ".octopus"
42+
protected_branches = []
43+
}
44+
}
45+
```
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
---
2+
page_title: "Creating a Standardised Space and Project"
3+
subcategory: "Examples"
4+
---
5+
6+
# Creating a Standardised Space and Project
7+
8+
This example show how to create a standardised space and project that can be used to quickly setup applications used as
9+
microservices.
10+
11+
## Create Space, Project with Deployment Process
12+
Consuming terraform module with standard configuration for Space and Project
13+
14+
```terraform
15+
module "standard" {
16+
source = "../modules/standardised-space-and-project"
17+
18+
space = {
19+
name = "Testing"
20+
description = "Testing infrastructure"
21+
}
22+
23+
project = {
24+
name = "Test Project"
25+
description = "Testing resources"
26+
}
27+
}
28+
29+
resource "octopusdeploy_process" "test" {
30+
space_id = module.standard.space
31+
project_id = module.standard.project
32+
}
33+
34+
# Manual Intervention Step (Production only)
35+
resource "octopusdeploy_process_step" "approve" {
36+
space_id = module.standard.space
37+
process_id = octopusdeploy_process.test.id
38+
name = "Approve"
39+
type = "Octopus.Manual"
40+
is_required = true
41+
environments = [
42+
module.standard.environments.production
43+
]
44+
execution_properties = {
45+
"Octopus.Action.RunOnServer" = "True"
46+
"Octopus.Action.Manual.Instructions" = "Please review and approve the deployment to production."
47+
"Octopus.Action.Manual.ResponsibleTeamIds" = octopusdeploy_team.approvers.id
48+
}
49+
}
50+
51+
# Run Azure Script Step
52+
resource "octopusdeploy_process_step" "azure" {
53+
space_id = module.standard.space
54+
process_id = octopusdeploy_process.test.id
55+
name = "Run Azure Script"
56+
type = "Octopus.AzurePowerShell"
57+
is_required = true
58+
environments = [
59+
module.standard.environments.development,
60+
module.standard.environments.staging,
61+
module.standard.environments.production
62+
]
63+
execution_properties = {
64+
"Octopus.Action.RunOnServer" = "True"
65+
"Octopus.Action.Azure.AccountId" = octopusdeploy_azure_service_principal.azure_account.id
66+
"Octopus.Action.Script.ScriptSource" = "Inline"
67+
"Octopus.Action.Script.Syntax" = "PowerShell"
68+
"Octopus.Action.Script.ScriptBody" = <<-EOT
69+
# Your Azure PowerShell script here
70+
Write-Output "Running Azure Script"
71+
EOT
72+
"OctopusUseBundledTooling" = "False"
73+
}
74+
container = {
75+
feed_id = module.standard.docker_registry
76+
image = "your-private-registry/your-execution-container:latest"
77+
}
78+
}
79+
80+
# Deploy Kubernetes YAML Step
81+
resource "octopusdeploy_process_step" "kubernetes" {
82+
space_id = module.standard.space
83+
process_id = octopusdeploy_process.test.id
84+
name = "Deploy Kubernetes YAML"
85+
properties = {
86+
"Octopus.Action.TargetRoles" = "k8s_cluster"
87+
}
88+
type = "Octopus.KubernetesDeployRawYaml"
89+
is_required = true
90+
environments = [
91+
module.standard.environments.development,
92+
module.standard.environments.staging,
93+
module.standard.environments.production
94+
]
95+
worker_pool_id = octopusdeploy_static_worker_pool.default.id
96+
execution_properties = {
97+
"Octopus.Action.RunOnServer" = "true"
98+
"Octopus.Action.KubernetesContainers.CustomResourceYamlFileName" = "deployment.yaml"
99+
"Octopus.Action.KubernetesContainers.Namespace" = "#{Octopus.Environment.Name | ToLower}"
100+
"Octopus.Action.Script.ScriptSource" = "GitRepository"
101+
"Octopus.Action.Git.Url" = "https://github.com/your-org/your-repo.git"
102+
"Octopus.Action.Git.Branch" = "main"
103+
"OctopusUseBundledTooling" = "False"
104+
}
105+
container = {
106+
feed_id = module.standard.docker_registry
107+
image = "octopusdeploy/worker-tools:latest"
108+
}
109+
git_dependencies = {
110+
"": {
111+
git_credential_id = octopusdeploy_git_credential.git_credential.id
112+
git_credential_type = "Library"
113+
repository_uri = "https://github.com/your-org/your-repo.git"
114+
default_branch = "main"
115+
}
116+
}
117+
}
118+
119+
resource "octopusdeploy_process_steps_order" "test" {
120+
space_id = module.standard.space
121+
process_id = octopusdeploy_process.test.id
122+
steps = [
123+
octopusdeploy_process_step.approve.id,
124+
octopusdeploy_process_step.azure.id,
125+
octopusdeploy_process_step.kubernetes.id,
126+
]
127+
}
128+
129+
resource "octopusdeploy_team" "approvers" {
130+
space_id = module.standard.space
131+
name = "Deployment Approvers"
132+
description = "Team responsible for approving production deployments"
133+
}
134+
135+
resource "octopusdeploy_azure_service_principal" "azure_account" {
136+
space_id = module.standard.space
137+
name = "Example Azure Service Principal"
138+
description = "Azure service principal account for deployments"
139+
subscription_id = "00000000-0000-0000-0000-000000000001"
140+
tenant_id = "00000000-0000-0000-0000-000000000002"
141+
application_id = "00000000-0000-0000-0000-000000000003"
142+
password = "TopSecretPassword01!"
143+
environments = [
144+
module.standard.environments.development,
145+
module.standard.environments.staging,
146+
module.standard.environments.production,
147+
]
148+
}
149+
150+
resource "octopusdeploy_static_worker_pool" "default" {
151+
space_id = module.standard.space
152+
name = "Worker Pool 1"
153+
is_default = true
154+
}
155+
156+
resource "octopusdeploy_git_credential" "git_credential" {
157+
space_id = module.standard.space
158+
name = "TerraformGitCred"
159+
username = "TFP"
160+
password = "password01!"
161+
}
162+
163+
resource "octopusdeploy_kubernetes_cluster_deployment_target" "k8s_cluster_1" {
164+
space_id = module.standard.space
165+
name = "Example Kubernetes Cluster"
166+
cluster_url = "https://your-cluster-url.com"
167+
skip_tls_verification = false
168+
default_worker_pool_id = octopusdeploy_static_worker_pool.default.id
169+
namespace = "default"
170+
environments = [
171+
module.standard.environments.development,
172+
module.standard.environments.staging,
173+
module.standard.environments.production
174+
]
175+
roles = ["k8s-cluster"]
176+
azure_service_principal_authentication {
177+
account_id = octopusdeploy_azure_service_principal.azure_account.id
178+
cluster_name = "Cluster"
179+
cluster_resource_group = "cluster-rg"
180+
}
181+
}
182+
```
183+
184+
## Space and Project configuration module
185+
Module with standard configuration to be reused for multiple applications
186+
187+
### variables.tf
188+
```terraform
189+
variable "space" {
190+
description = "Space details"
191+
type = object({
192+
name = string
193+
description = optional(string, "")
194+
})
195+
}
196+
197+
variable "project" {
198+
description = "Application details"
199+
type = object({
200+
name = string
201+
description = optional(string, "")
202+
})
203+
}
204+
```
205+
206+
### main.tf
207+
```terraform
208+
data "octopusdeploy_teams" "everyone" {
209+
partial_name = "Everyone"
210+
skip = 0
211+
take = 1
212+
}
213+
214+
# Create a Space
215+
resource "octopusdeploy_space" "example" {
216+
name = var.space.name
217+
description = var.space.description
218+
space_managers_teams = [ data.octopusdeploy_teams.everyone.teams[0].id ]
219+
}
220+
221+
# Create 3 Environments
222+
resource "octopusdeploy_environment" "development" {
223+
name = "Development"
224+
description = "Development environment"
225+
space_id = octopusdeploy_space.example.id
226+
}
227+
228+
resource "octopusdeploy_environment" "staging" {
229+
name = "Staging"
230+
description = "Staging environment"
231+
space_id = octopusdeploy_space.example.id
232+
}
233+
234+
resource "octopusdeploy_environment" "production" {
235+
name = "Production"
236+
description = "Production environment"
237+
space_id = octopusdeploy_space.example.id
238+
}
239+
240+
# Create a Container Registry
241+
resource "octopusdeploy_docker_container_registry" "example" {
242+
name = "DockerHub"
243+
space_id = octopusdeploy_space.example.id
244+
feed_uri = "https://registry.hub.docker.com"
245+
}
246+
247+
# Additional required resources
248+
resource "octopusdeploy_lifecycle" "example" {
249+
name = "Example Lifecycle"
250+
space_id = octopusdeploy_space.example.id
251+
}
252+
253+
resource "octopusdeploy_project_group" "example" {
254+
name = "Example Project Group"
255+
space_id = octopusdeploy_space.example.id
256+
}
257+
258+
# Create a Project
259+
resource "octopusdeploy_project" "example" {
260+
name = var.project.name
261+
description = var.project.description
262+
space_id = octopusdeploy_space.example.id
263+
lifecycle_id = octopusdeploy_lifecycle.example.id
264+
project_group_id = octopusdeploy_project_group.example.id
265+
}
266+
```
267+
268+
### output.tf
269+
```terraform
270+
output "space" {
271+
value = octopusdeploy_space.example.id
272+
}
273+
274+
output "project" {
275+
value = octopusdeploy_project.example.id
276+
}
277+
278+
output "environments" {
279+
value = {
280+
development = octopusdeploy_environment.development.id
281+
staging = octopusdeploy_environment.staging.id
282+
production = octopusdeploy_environment.production.id
283+
}
284+
}
285+
286+
output "docker_registry" {
287+
value = octopusdeploy_docker_container_registry.example.id
288+
}
289+
```

0 commit comments

Comments
 (0)