Skip to content

Commit ffe1014

Browse files
committed
feat: use default runner in meshstack_integration if runner_ref is omitted, add ref output, add import test step
1 parent 91ccfaf commit ffe1014

File tree

9 files changed

+168
-123
lines changed

9 files changed

+168
-123
lines changed

client/integration_config.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ var (
1919
)
2020

2121
type MeshIntegrationGithubConfig struct {
22-
Owner string `json:"owner" tfsdk:"owner"`
23-
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
24-
AppId string `json:"appId" tfsdk:"app_id"`
25-
AppPrivateKey types.Secret `json:"appPrivateKey" tfsdk:"app_private_key"`
26-
RunnerRef BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
22+
Owner string `json:"owner" tfsdk:"owner"`
23+
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
24+
AppId string `json:"appId" tfsdk:"app_id"`
25+
AppPrivateKey types.Secret `json:"appPrivateKey" tfsdk:"app_private_key"`
26+
RunnerRef *BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
2727
}
2828

2929
type MeshIntegrationGitlabConfig struct {
30-
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
31-
RunnerRef BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
30+
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
31+
RunnerRef *BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
3232
}
3333

3434
type MeshIntegrationAzureDevopsConfig struct {
35-
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
36-
Organization string `json:"organization" tfsdk:"organization"`
37-
PersonalAccessToken types.Secret `json:"personalAccessToken" tfsdk:"personal_access_token"`
38-
RunnerRef BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
35+
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
36+
Organization string `json:"organization" tfsdk:"organization"`
37+
PersonalAccessToken types.Secret `json:"personalAccessToken" tfsdk:"personal_access_token"`
38+
RunnerRef *BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
3939
}
4040

4141
type MeshIntegrationConfig struct {

docs/resources/integration.md

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ resource "meshstack_integration" "example_github" {
2525
owner = "my-org"
2626
base_url = "https://github.com"
2727
app_id = "123456"
28-
app_private_key = { value = "-----BEGIN RSA PRIVATE KEY-----\nMOCK_KEY_CONTENT\n-----END RSA PRIVATE KEY-----" }
29-
runner_ref = {
30-
uuid = "dc8c57a1-823f-4e96-8582-0275fa27dc7b"
31-
}
28+
app_private_key = { secret_value = "-----BEGIN RSA PRIVATE KEY-----\nMOCK_KEY_CONTENT\n-----END RSA PRIVATE KEY-----" }
29+
runner_ref = { uuid = "dc8c57a1-823f-4e96-8582-0275fa27dc7b" } # Optional, by default, pre-defined shared runner is used
3230
}
3331
}
3432
}
@@ -48,10 +46,7 @@ resource "meshstack_integration" "example_azure_devops" {
4846
base_url = "https://dev.azure.com"
4947
organization = "my-organization"
5048
personal_access_token = {
51-
value = "mock-pat-token-12345"
52-
}
53-
runner_ref = {
54-
uuid = "05cfa85f-2818-4bdd-b193-620e0187d7de"
49+
secret_value = "mock-pat-token-12345"
5550
}
5651
}
5752
}
@@ -70,9 +65,6 @@ resource "meshstack_integration" "example_gitlab" {
7065
config = {
7166
gitlab = {
7267
base_url = "https://gitlab.com"
73-
runner_ref = {
74-
uuid = "f4f4402b-f54d-4ab9-93ae-c07e997041e9"
75-
}
7668
}
7769
}
7870
}
@@ -89,6 +81,7 @@ resource "meshstack_integration" "example_gitlab" {
8981

9082
### Read-Only
9183

84+
- `ref` (Attributes) Reference to integration, can be used in building block definitions. (see [below for nested schema](#nestedatt--ref))
9285
- `status` (Attributes) Status information of the integration. Computed by meshStack. (see [below for nested schema](#nestedatt--status))
9386

9487
<a id="nestedatt--metadata"></a>
@@ -127,38 +120,35 @@ Required:
127120

128121
- `base_url` (String) Base URL of the Azure DevOps instance (e.g., `https://dev.azure.com`).
129122
- `organization` (String) Azure DevOps organization name.
130-
- `runner_ref` (Attributes) Reference to the building block runner that executes Azure DevOps pipelines. (see [below for nested schema](#nestedatt--spec--config--azuredevops--runner_ref))
131123

132124
Optional:
133125

134126
- `personal_access_token` (Attributes) Personal Access Token (PAT) for authentication. (see [below for nested schema](#nestedatt--spec--config--azuredevops--personal_access_token))
127+
- `runner_ref` (Attributes) Reference to the building block runner that executes Azure DevOps pipelines. If omitted, the pre-defined shared runner is used. (see [below for nested schema](#nestedatt--spec--config--azuredevops--runner_ref))
135128

136-
<a id="nestedatt--spec--config--azuredevops--runner_ref"></a>
137-
### Nested Schema for `spec.config.azuredevops.runner_ref`
129+
<a id="nestedatt--spec--config--azuredevops--personal_access_token"></a>
130+
### Nested Schema for `spec.config.azuredevops.personal_access_token`
138131

139132
Required:
140133

141-
- `uuid` (String) UUID of the building block runner.
134+
- `secret_value` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Personal Access Token (PAT) for authentication.
142135

143-
Read-Only:
136+
Optional:
144137

145-
- `kind` (String) Kind of the runner reference.
138+
- `secret_version` (String) Version of the secret value. Change this to trigger rotation of the associated write-only attribute `secret_hash`. Can be omitted if resource is imported, in this case the `secret_value` attribute is used as an initial value for this attribute (computed output).
146139

140+
Read-Only:
147141

148-
<a id="nestedatt--spec--config--azuredevops--personal_access_token"></a>
149-
### Nested Schema for `spec.config.azuredevops.personal_access_token`
142+
- `secret_hash` (String) Hash value of the secret stored in the backend. If this hash has changed without changes in the version attribute, the secret was changed externally.
150143

151-
Required:
152144

153-
- `value` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Personal Access Token (PAT) for authentication.
145+
<a id="nestedatt--spec--config--azuredevops--runner_ref"></a>
146+
### Nested Schema for `spec.config.azuredevops.runner_ref`
154147

155148
Optional:
156149

157-
- `fingerprint` (String) Fingerprint of the secret value. Change this to trigger rotation of the associated write-only attribute `value`. Can be omitted if resource is imported, in this case the hash is used as an initial fingerprint (computed output).
158-
159-
Read-Only:
160-
161-
- `hash` (String) Hash value of the secret stored in the backend. If this hash has changed without changes in the version attribute, the secret was changed externally.
150+
- `kind` (String) meshObject type, always `meshBuildingBlockRunner`.
151+
- `uuid` (String) UUID of the meshBuildingBlockRunner.
162152

163153

164154

@@ -171,34 +161,34 @@ Required:
171161
- `app_private_key` (Attributes) Private key for the GitHub App. (see [below for nested schema](#nestedatt--spec--config--github--app_private_key))
172162
- `base_url` (String) Base URL of the GitHub instance (e.g., `https://github.com` for GitHub.com or your GitHub Enterprise URL).
173163
- `owner` (String) GitHub organization or user that owns the repositories.
174-
- `runner_ref` (Attributes) Reference to the building block runner that executes GitHub workflows. (see [below for nested schema](#nestedatt--spec--config--github--runner_ref))
164+
165+
Optional:
166+
167+
- `runner_ref` (Attributes) Reference to the building block runner that executes GitHub workflows.If omitted, the pre-defined shared runner is used. (see [below for nested schema](#nestedatt--spec--config--github--runner_ref))
175168

176169
<a id="nestedatt--spec--config--github--app_private_key"></a>
177170
### Nested Schema for `spec.config.github.app_private_key`
178171

179172
Required:
180173

181-
- `value` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Private key for the GitHub App.
174+
- `secret_value` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Private key for the GitHub App.
182175

183176
Optional:
184177

185-
- `fingerprint` (String) Fingerprint of the secret value. Change this to trigger rotation of the associated write-only attribute `value`. Can be omitted if resource is imported, in this case the hash is used as an initial fingerprint (computed output).
178+
- `secret_version` (String) Version of the secret value. Change this to trigger rotation of the associated write-only attribute `secret_hash`. Can be omitted if resource is imported, in this case the `secret_value` attribute is used as an initial value for this attribute (computed output).
186179

187180
Read-Only:
188181

189-
- `hash` (String) Hash value of the secret stored in the backend. If this hash has changed without changes in the version attribute, the secret was changed externally.
182+
- `secret_hash` (String) Hash value of the secret stored in the backend. If this hash has changed without changes in the version attribute, the secret was changed externally.
190183

191184

192185
<a id="nestedatt--spec--config--github--runner_ref"></a>
193186
### Nested Schema for `spec.config.github.runner_ref`
194187

195-
Required:
196-
197-
- `uuid` (String) UUID of the building block runner.
198-
199-
Read-Only:
188+
Optional:
200189

201-
- `kind` (String) Kind of the runner reference.
190+
- `kind` (String) meshObject type, always `meshBuildingBlockRunner`.
191+
- `uuid` (String) UUID of the meshBuildingBlockRunner.
202192

203193

204194

@@ -208,21 +198,30 @@ Read-Only:
208198
Required:
209199

210200
- `base_url` (String) Base URL of the GitLab instance (e.g., `https://gitlab.com` or your self-hosted GitLab URL).
211-
- `runner_ref` (Attributes) Reference to the building block runner that executes GitLab pipelines. (see [below for nested schema](#nestedatt--spec--config--gitlab--runner_ref))
201+
202+
Optional:
203+
204+
- `runner_ref` (Attributes) Reference to the building block runner that executes GitLab pipelines.If omitted, the pre-defined shared runner is used. (see [below for nested schema](#nestedatt--spec--config--gitlab--runner_ref))
212205

213206
<a id="nestedatt--spec--config--gitlab--runner_ref"></a>
214207
### Nested Schema for `spec.config.gitlab.runner_ref`
215208

216-
Required:
209+
Optional:
210+
211+
- `kind` (String) meshObject type, always `meshBuildingBlockRunner`.
212+
- `uuid` (String) UUID of the meshBuildingBlockRunner.
217213

218-
- `uuid` (String) UUID of the building block runner.
219214

220-
Read-Only:
221215

222-
- `kind` (String) Kind of the runner reference.
223216

224217

218+
<a id="nestedatt--ref"></a>
219+
### Nested Schema for `ref`
220+
221+
Read-Only:
225222

223+
- `kind` (String) meshObject type, always `meshIntegration`.
224+
- `uuid` (String) UUID of the meshIntegration.
226225

227226

228227
<a id="nestedatt--status"></a>

examples/resources/meshstack_integration/resource_01_github.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ resource "meshstack_integration" "example_github" {
1111
base_url = "https://github.com"
1212
app_id = "123456"
1313
app_private_key = { secret_value = "-----BEGIN RSA PRIVATE KEY-----\nMOCK_KEY_CONTENT\n-----END RSA PRIVATE KEY-----" }
14-
runner_ref = {
15-
uuid = "dc8c57a1-823f-4e96-8582-0275fa27dc7b"
16-
}
14+
runner_ref = { uuid = "dc8c57a1-823f-4e96-8582-0275fa27dc7b" } # Optional, by default, pre-defined shared runner is used
1715
}
1816
}
1917
}

examples/resources/meshstack_integration/resource_02_azure_devops.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ resource "meshstack_integration" "example_azure_devops" {
1212
personal_access_token = {
1313
secret_value = "mock-pat-token-12345"
1414
}
15-
runner_ref = {
16-
uuid = "05cfa85f-2818-4bdd-b193-620e0187d7de"
17-
}
1815
}
1916
}
2017
}

examples/resources/meshstack_integration/resource_03_gitlab.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ resource "meshstack_integration" "example_gitlab" {
88
config = {
99
gitlab = {
1010
base_url = "https://gitlab.com"
11-
runner_ref = {
12-
uuid = "f4f4402b-f54d-4ab9-93ae-c07e997041e9"
13-
}
1411
}
1512
}
1613
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package provider
2+
3+
import (
4+
"github.com/meshcloud/terraform-provider-meshstack/client"
5+
"github.com/meshcloud/terraform-provider-meshstack/client/types/enum"
6+
)
7+
8+
var (
9+
SharedBuildingBlockRunnerUuids = map[enum.Entry[client.MeshBuildingBlockImplementationType]]string{
10+
client.MeshBuildingBlockImplementationTypeManual: "46b7c17a-61f0-4062-9601-5785e60ce11f",
11+
client.MeshBuildingBlockImplementationTypeTerraform: "66ddc814-1e69-4dad-b5f1-3a5bce51c01f",
12+
client.MeshBuildingBlockImplementationTypeGithubWorkflows: "dc8c57a1-823f-4e96-8582-0275fa27dc7b",
13+
client.MeshBuildingBlockImplementationTypeGitlabPipeline: "f4f4402b-f54d-4ab9-93ae-c07e997041e9",
14+
client.MeshBuildingBlockImplementationTypeAzureDevOpsPipeline: "05cfa85f-2818-4bdd-b193-620e0187d7de",
15+
}
16+
)
17+
18+
func getSharedBuildingBlockRunnerRef(implementationType enum.Entry[client.MeshBuildingBlockImplementationType]) *client.BuildingBlockRunnerRef {
19+
return &client.BuildingBlockRunnerRef{
20+
Kind: "meshBuildingBlockRunner",
21+
Uuid: SharedBuildingBlockRunnerUuids[implementationType],
22+
}
23+
}

0 commit comments

Comments
 (0)