Skip to content

Commit 91ccfaf

Browse files
committed
refactor: equip meshstack_integration with proper secret handling
1 parent 42f6302 commit 91ccfaf

File tree

12 files changed

+158
-179
lines changed

12 files changed

+158
-179
lines changed

client/integration.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@ import (
44
"context"
55

66
"github.com/meshcloud/terraform-provider-meshstack/client/internal"
7-
"github.com/meshcloud/terraform-provider-meshstack/client/types"
87
)
98

109
type MeshIntegration struct {
11-
ApiVersion string `json:"apiVersion"`
12-
Kind string `json:"kind"`
13-
Metadata MeshIntegrationMetadata `json:"metadata"`
14-
Spec MeshIntegrationSpec `json:"spec"`
15-
Status *MeshIntegrationStatus `json:"status"`
10+
ApiVersion string `json:"apiVersion" tfsdk:"-"`
11+
Kind string `json:"kind" tfsdk:"-"`
12+
Metadata MeshIntegrationMetadata `json:"metadata" tfsdk:"metadata"`
13+
Spec MeshIntegrationSpec `json:"spec" tfsdk:"spec"`
14+
Status *MeshIntegrationStatus `json:"status" tfsdk:"status"`
1615
}
1716

18-
type MeshIntegrationMetadataAdapter[String any] struct {
19-
Uuid String `json:"uuid,omitempty" tfsdk:"uuid"`
20-
OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"`
17+
type MeshIntegrationMetadata struct {
18+
Uuid *string `json:"uuid,omitempty" tfsdk:"uuid"`
19+
OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"`
2120
}
2221

23-
type MeshIntegrationMetadata = MeshIntegrationMetadataAdapter[*types.String]
24-
2522
type MeshIntegrationSpec struct {
2623
DisplayName string `json:"displayName" tfsdk:"display_name"`
2724
Config MeshIntegrationConfig `json:"config" tfsdk:"config"`

client/integration_config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"reflect"
77

8+
"github.com/meshcloud/terraform-provider-meshstack/client/types"
89
"github.com/meshcloud/terraform-provider-meshstack/client/types/enum"
910
)
1011

@@ -21,7 +22,7 @@ type MeshIntegrationGithubConfig struct {
2122
Owner string `json:"owner" tfsdk:"owner"`
2223
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
2324
AppId string `json:"appId" tfsdk:"app_id"`
24-
AppPrivateKey string `json:"appPrivateKey" tfsdk:"app_private_key"`
25+
AppPrivateKey types.Secret `json:"appPrivateKey" tfsdk:"app_private_key"`
2526
RunnerRef BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
2627
}
2728

@@ -33,7 +34,7 @@ type MeshIntegrationGitlabConfig struct {
3334
type MeshIntegrationAzureDevopsConfig struct {
3435
BaseUrl string `json:"baseUrl" tfsdk:"base_url"`
3536
Organization string `json:"organization" tfsdk:"organization"`
36-
PersonalAccessToken string `json:"personalAccessToken" tfsdk:"personal_access_token"`
37+
PersonalAccessToken types.Secret `json:"personalAccessToken" tfsdk:"personal_access_token"`
3738
RunnerRef BuildingBlockRunnerRef `json:"runnerRef" tfsdk:"runner_ref"`
3839
}
3940

docs/data-sources/integrations.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,24 @@ Optional:
113113
<a id="nestedatt--integrations--spec--config--azuredevops"></a>
114114
### Nested Schema for `integrations.spec.config.azuredevops`
115115

116+
Required:
117+
118+
- `personal_access_token` (Attributes) (see [below for nested schema](#nestedatt--integrations--spec--config--azuredevops--personal_access_token))
119+
116120
Read-Only:
117121

118122
- `base_url` (String)
119123
- `organization` (String)
120-
- `personal_access_token` (String)
121124
- `runner_ref` (Attributes) (see [below for nested schema](#nestedatt--integrations--spec--config--azuredevops--runner_ref))
122125

126+
<a id="nestedatt--integrations--spec--config--azuredevops--personal_access_token"></a>
127+
### Nested Schema for `integrations.spec.config.azuredevops.personal_access_token`
128+
129+
Read-Only:
130+
131+
- `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.
132+
133+
123134
<a id="nestedatt--integrations--spec--config--azuredevops--runner_ref"></a>
124135
### Nested Schema for `integrations.spec.config.azuredevops.runner_ref`
125136

@@ -133,14 +144,25 @@ Read-Only:
133144
<a id="nestedatt--integrations--spec--config--github"></a>
134145
### Nested Schema for `integrations.spec.config.github`
135146

147+
Required:
148+
149+
- `app_private_key` (Attributes) (see [below for nested schema](#nestedatt--integrations--spec--config--github--app_private_key))
150+
136151
Read-Only:
137152

138153
- `app_id` (String)
139-
- `app_private_key` (String)
140154
- `base_url` (String)
141155
- `owner` (String)
142156
- `runner_ref` (Attributes) (see [below for nested schema](#nestedatt--integrations--spec--config--github--runner_ref))
143157

158+
<a id="nestedatt--integrations--spec--config--github--app_private_key"></a>
159+
### Nested Schema for `integrations.spec.config.github.app_private_key`
160+
161+
Read-Only:
162+
163+
- `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.
164+
165+
144166
<a id="nestedatt--integrations--spec--config--github--runner_ref"></a>
145167
### Nested Schema for `integrations.spec.config.github.runner_ref`
146168

docs/resources/integration.md

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,14 @@ resource "meshstack_integration" "example_github" {
2525
owner = "my-org"
2626
base_url = "https://github.com"
2727
app_id = "123456"
28-
app_private_key = "-----BEGIN RSA PRIVATE KEY-----\nMOCK_KEY_CONTENT\n-----END RSA PRIVATE KEY-----"
28+
app_private_key = { value = "-----BEGIN RSA PRIVATE KEY-----\nMOCK_KEY_CONTENT\n-----END RSA PRIVATE KEY-----" }
2929
runner_ref = {
3030
uuid = "dc8c57a1-823f-4e96-8582-0275fa27dc7b"
3131
}
3232
}
3333
}
3434
}
3535
}
36-
37-
# Access workload identity federation for GCP
38-
output "github_wif_gcp_audience" {
39-
value = meshstack_integration.example_github.status.workload_identity_federation.gcp.audience
40-
}
4136
```
4237

4338
```terraform
@@ -50,9 +45,11 @@ resource "meshstack_integration" "example_azure_devops" {
5045
display_name = "Azure DevOps Integration"
5146
config = {
5247
azuredevops = {
53-
base_url = "https://dev.azure.com"
54-
organization = "my-organization"
55-
personal_access_token = "mock-pat-token-12345"
48+
base_url = "https://dev.azure.com"
49+
organization = "my-organization"
50+
personal_access_token = {
51+
value = "mock-pat-token-12345"
52+
}
5653
runner_ref = {
5754
uuid = "05cfa85f-2818-4bdd-b193-620e0187d7de"
5855
}
@@ -130,9 +127,12 @@ Required:
130127

131128
- `base_url` (String) Base URL of the Azure DevOps instance (e.g., `https://dev.azure.com`).
132129
- `organization` (String) Azure DevOps organization name.
133-
- `personal_access_token` (String) Personal Access Token (PAT) for authentication. This is a sensitive value.
134130
- `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))
135131

132+
Optional:
133+
134+
- `personal_access_token` (Attributes) Personal Access Token (PAT) for authentication. (see [below for nested schema](#nestedatt--spec--config--azuredevops--personal_access_token))
135+
136136
<a id="nestedatt--spec--config--azuredevops--runner_ref"></a>
137137
### Nested Schema for `spec.config.azuredevops.runner_ref`
138138

@@ -145,18 +145,50 @@ Read-Only:
145145
- `kind` (String) Kind of the runner reference.
146146

147147

148+
<a id="nestedatt--spec--config--azuredevops--personal_access_token"></a>
149+
### Nested Schema for `spec.config.azuredevops.personal_access_token`
150+
151+
Required:
152+
153+
- `value` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Personal Access Token (PAT) for authentication.
154+
155+
Optional:
156+
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.
162+
163+
148164

149165
<a id="nestedatt--spec--config--github"></a>
150166
### Nested Schema for `spec.config.github`
151167

152168
Required:
153169

154170
- `app_id` (String) GitHub App ID for authentication.
155-
- `app_private_key` (String) Private key for the GitHub App. This is a sensitive value.
171+
- `app_private_key` (Attributes) Private key for the GitHub App. (see [below for nested schema](#nestedatt--spec--config--github--app_private_key))
156172
- `base_url` (String) Base URL of the GitHub instance (e.g., `https://github.com` for GitHub.com or your GitHub Enterprise URL).
157173
- `owner` (String) GitHub organization or user that owns the repositories.
158174
- `runner_ref` (Attributes) Reference to the building block runner that executes GitHub workflows. (see [below for nested schema](#nestedatt--spec--config--github--runner_ref))
159175

176+
<a id="nestedatt--spec--config--github--app_private_key"></a>
177+
### Nested Schema for `spec.config.github.app_private_key`
178+
179+
Required:
180+
181+
- `value` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Private key for the GitHub App.
182+
183+
Optional:
184+
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).
186+
187+
Read-Only:
188+
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.
190+
191+
160192
<a id="nestedatt--spec--config--github--runner_ref"></a>
161193
### Nested Schema for `spec.config.github.runner_ref`
162194

examples/resources/meshstack_integration/resource_01_github.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ resource "meshstack_integration" "example_github" {
1010
owner = "my-org"
1111
base_url = "https://github.com"
1212
app_id = "123456"
13-
app_private_key = "-----BEGIN RSA PRIVATE KEY-----\nMOCK_KEY_CONTENT\n-----END RSA PRIVATE KEY-----"
13+
app_private_key = { secret_value = "-----BEGIN RSA PRIVATE KEY-----\nMOCK_KEY_CONTENT\n-----END RSA PRIVATE KEY-----" }
1414
runner_ref = {
1515
uuid = "dc8c57a1-823f-4e96-8582-0275fa27dc7b"
1616
}
1717
}
1818
}
1919
}
2020
}
21-
22-
# Access workload identity federation for GCP
23-
output "github_wif_gcp_audience" {
24-
value = meshstack_integration.example_github.status.workload_identity_federation.gcp.audience
25-
}

examples/resources/meshstack_integration/resource_02_azure_devops.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ resource "meshstack_integration" "example_azure_devops" {
77
display_name = "Azure DevOps Integration"
88
config = {
99
azuredevops = {
10-
base_url = "https://dev.azure.com"
11-
organization = "my-organization"
12-
personal_access_token = "mock-pat-token-12345"
10+
base_url = "https://dev.azure.com"
11+
organization = "my-organization"
12+
personal_access_token = {
13+
secret_value = "mock-pat-token-12345"
14+
}
1315
runner_ref = {
1416
uuid = "05cfa85f-2818-4bdd-b193-620e0187d7de"
1517
}

internal/clientmock/mock_integration.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,9 @@ func (m MeshIntegrationClient) Create(_ context.Context, integration client.Mesh
2626
Spec: integration.Spec,
2727
Status: &client.MeshIntegrationStatus{
2828
IsBuiltIn: false,
29-
WorkloadIdentityFederation: &client.MeshWorkloadIdentityFederation{
30-
Issuer: "https://meshstack.example.com",
31-
Subject: "integration:" + integrationUuid,
32-
Gcp: &client.MeshWifProvider{
33-
Audience: "gcp-audience",
34-
},
35-
Aws: &client.MeshAwsWifProvider{
36-
Audience: "aws-audience",
37-
Thumbprint: "abc123",
38-
},
39-
Azure: &client.MeshWifProvider{
40-
Audience: "azure-audience",
41-
},
42-
},
4329
},
4430
}
31+
backendSecretBehavior(true, created, nil)
4532
m.Store[integrationUuid] = created
4633
return created, nil
4734
}

internal/provider/integration_model.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)