-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeshstack_integration.tf
More file actions
253 lines (218 loc) · 8.01 KB
/
Copy pathmeshstack_integration.tf
File metadata and controls
253 lines (218 loc) · 8.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
variable "stackit_project_id" {
type = string
description = "STACKIT project ID where the backplane service account will be created."
}
variable "stackit_organization_id" {
type = string
description = "STACKIT organization ID where the service account will be granted permissions."
}
variable "stackit_parent_container_id" {
type = string
description = "Default parent container ID (organization or folder) for project creation."
}
variable "stackit_service_account_name" {
type = string
default = null
description = "Name of the backplane service account. Defaults to 'mesh-project'. Override when deploying multiple backplane instances in the same STACKIT project."
}
variable "meshstack" {
type = object({
owning_workspace_identifier = string
tags = optional(object({
landingzone = map(list(string))
building_block = map(list(string))
}), { landingzone = {}, building_block = {} })
location_name = optional(string, "global")
platform_identifier = optional(string, "stackit")
})
description = <<-EOT
Shared meshStack context.
`owning_workspace_identifier`: Identifier of the meshStack workspace that owns the managed resources.
`tags`: Optional tags propagated to building block definition and landing zone metadata.
`location_name`: meshStack location name for the platform. Defaults to "global".
`platform_identifier`: Identifier for the platform in meshStack. Defaults to "stackit".
EOT
}
variable "hub" {
type = object({
git_ref = optional(string, "main")
bbd_draft = optional(bool, true)
})
const = true
default = {}
description = <<-EOT
`git_ref`: Hub release reference. Set to a tag (e.g. 'v1.2.3') or branch or commit sha of meshcloud/meshstack-hub repo.
`bbd_draft`: If true, allows changing the building block definition for upgrading dependent building blocks.
EOT
}
module "backplane" {
source = "github.com/meshcloud/meshstack-hub//modules/stackit/project/backplane?ref=${var.hub.git_ref}"
project_id = var.stackit_project_id
organization_id = var.stackit_organization_id
service_account_name = coalesce(var.stackit_service_account_name, "mesh-project")
}
output "building_block_definition" {
description = "BBD is consumed in building block compositions."
value = {
uuid = meshstack_building_block_definition.this.metadata.uuid
version_ref = var.hub.bbd_draft ? meshstack_building_block_definition.this.version_latest : meshstack_building_block_definition.this.version_latest_release
}
}
resource "meshstack_platform" "stackit" {
metadata = {
name = var.meshstack.platform_identifier
owned_by_workspace = var.meshstack.owning_workspace_identifier
}
spec = {
display_name = "STACKIT Project"
description = "Create a STACKIT project with role-based access control."
endpoint = "https://portal.stackit.cloud"
location_ref = {
name = var.meshstack.location_name
}
availability = {
restriction = "PRIVATE"
publication_state = "UNPUBLISHED"
restricted_to_workspaces = [var.meshstack.owning_workspace_identifier]
}
config = {
custom = {
platform_type_ref = { name = "STACKIT" }
}
}
}
}
resource "meshstack_landingzone" "stackit_default" {
metadata = {
name = "${var.meshstack.platform_identifier}-default"
owned_by_workspace = var.meshstack.owning_workspace_identifier
tags = var.meshstack.tags.landingzone
}
spec = {
display_name = "STACKIT Default"
description = "Default landing zone for STACKIT projects."
automate_deletion_approval = true
automate_deletion_replication = true
platform_ref = {
uuid = meshstack_platform.stackit.metadata.uuid
}
platform_properties = {
custom = {}
}
mandatory_building_block_refs = [
{ uuid = meshstack_building_block_definition.this.metadata.uuid }
]
}
}
resource "meshstack_building_block_definition" "this" {
metadata = {
owned_by_workspace = var.meshstack.owning_workspace_identifier
tags = var.meshstack.tags.building_block
}
spec = {
display_name = "STACKIT Project"
symbol = "https://raw.githubusercontent.com/meshcloud/meshstack-hub/${var.hub.git_ref}/modules/stackit/project/buildingblock/logo.png"
description = "Creates a new STACKIT project and manages user access permissions with role-based access control."
support_url = "https://portal.stackit.cloud"
target_type = "TENANT_LEVEL"
run_transparency = true
supported_platforms = [{ name = "STACKIT" }]
}
version_spec = {
draft = var.hub.bbd_draft
deletion_mode = "DELETE"
implementation = {
terraform = {
terraform_version = "1.11.0"
repository_url = "https://github.com/meshcloud/meshstack-hub.git"
repository_path = "modules/stackit/project/buildingblock"
ref_name = var.hub.git_ref
async = false
use_mesh_http_backend_fallback = true
}
}
inputs = {
parent_container_id = {
display_name = "Parent Container ID"
description = "Default parent container ID (organization or folder) where the project will be created."
type = "STRING"
assignment_type = "STATIC"
argument = jsonencode(var.stackit_parent_container_id)
}
service_account_email = {
display_name = "Service Account Email"
description = "Email of the STACKIT service account that owns created projects."
type = "STRING"
assignment_type = "STATIC"
argument = jsonencode(module.backplane.service_account_email)
}
service_account_key_json = {
display_name = "Service Account Key JSON"
description = "Service account key JSON for authenticating the STACKIT provider."
type = "FILE"
assignment_type = "STATIC"
sensitive = {
argument = {
secret_value = "data:application/json;base64,${base64encode(module.backplane.service_account_key_json)}"
secret_version = nonsensitive(sha256(module.backplane.service_account_key_json))
}
}
}
STACKIT_SERVICE_ACCOUNT_KEY_PATH = {
display_name = "STACKIT Credentials Path"
description = "Path to the STACKIT service account credentials file."
type = "STRING"
assignment_type = "STATIC"
is_environment = true
argument = jsonencode("./service_account_key_json")
}
project_name = {
display_name = "Project Name"
description = "Name of the STACKIT project."
type = "STRING"
assignment_type = "PROJECT_IDENTIFIER"
}
users = {
display_name = "Users"
description = "Project users with role assignments from meshStack."
type = "CODE"
assignment_type = "USER_PERMISSIONS"
}
}
outputs = {
project_url = {
display_name = "Open Project"
type = "STRING"
assignment_type = "RESOURCE_URL"
}
project_id = {
display_name = "Project ID"
type = "STRING"
assignment_type = "PLATFORM_TENANT_ID"
}
container_id = {
display_name = "Container ID"
type = "STRING"
assignment_type = "NONE"
}
project_name = {
display_name = "Project Name"
type = "STRING"
assignment_type = "SUMMARY"
}
}
}
}
terraform {
required_version = ">= 1.12.0"
required_providers {
meshstack = {
source = "meshcloud/meshstack"
version = "~> 0.21.0"
}
stackit = {
source = "stackitcloud/stackit"
version = ">= 0.88.0"
}
}
}