Skip to content

Commit 1841be2

Browse files
authored
Merge pull request #10 from combor/ona_runner_scm_integration
bump `gitpod-sdk-go` to `v0.13.0`
2 parents df5c60d + ae7c0f7 commit 1841be2

12 files changed

Lines changed: 390 additions & 103 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
timeout-minutes: 5
4040
steps:
4141
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42-
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
42+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
4343
with:
4444
go-version-file: 'go.mod'
4545
cache: true
@@ -57,7 +57,7 @@ jobs:
5757
timeout-minutes: 5
5858
steps:
5959
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
60-
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
60+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
6161
with:
6262
go-version-file: 'go.mod'
6363
cache: true
@@ -82,7 +82,7 @@ jobs:
8282
GITPOD_API_KEY: ${{ secrets.GITPOD_API_KEY }}
8383
steps:
8484
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
85-
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
85+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
8686
with:
8787
go-version-file: 'go.mod'
8888
cache: true
@@ -143,7 +143,7 @@ jobs:
143143
with:
144144
# Allow goreleaser to access older tag information.
145145
fetch-depth: 0
146-
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
146+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
147147
with:
148148
go-version-file: 'go.mod'
149149
cache: true

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ act push -j integration \
5959
-s RUNNER_MANAGER_ID=01984227-2946-7e40-a982-2f427741f5da
6060
```
6161

62-
This runs the local `integration` matrix for Terraform `1.7.*` and `1.14.*` against the real Gitpod API. It first applies and destroys `examples/cleanup`, then applies and destroys the main `examples/` configuration, which currently exercises `ona_runner`, `ona_runner_scm_integration`, `ona_project`, and `ona_secret`.
62+
This runs the local `integration` matrix for Terraform `1.7.*` and `1.14.*` against the real Gitpod API. It first applies and destroys `examples/cleanup`, then applies and destroys the main `examples/` configuration, which currently exercises `ona_runner`, `ona_project`, and `ona_secret`. (`ona_runner_scm_integration` is not included because SCM integrations cannot be added to Gitpod-managed runners.)
6363

6464
Requires `GITPOD_API_KEY` to be set. The integration job also requires `RUNNER_MANAGER_ID`.

examples/main.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ data "ona_project" "example" {
7878
id = ona_project.example.id
7979
}
8080

81-
resource "ona_runner_scm_integration" "example" {
82-
runner_id = ona_runner.example.id
83-
scm_id = "github"
84-
host = "github.com"
85-
pat = true
86-
}
87-
8881
resource "ona_secret" "example" {
8982
name = "TF_CI_SECRET"
9083
value = var.secret_value

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/combor/terraform-provider-ona
22

3-
go 1.26.1
3+
go 1.26.2
44

55
require (
6-
github.com/gitpod-io/gitpod-sdk-go v0.12.0
6+
github.com/gitpod-io/gitpod-sdk-go v0.13.0
77
github.com/hashicorp/terraform-plugin-framework v1.19.0
88
github.com/hashicorp/terraform-plugin-go v0.31.0
99
github.com/hashicorp/terraform-plugin-log v0.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FM
2626
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
2727
github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
2828
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
29-
github.com/gitpod-io/gitpod-sdk-go v0.12.0 h1:t07zjnbJvuyTnSLtpVo/ddd0gIbHfvonKZGxKbJwrk0=
30-
github.com/gitpod-io/gitpod-sdk-go v0.12.0/go.mod h1:4mCKUT0lDkx/sJBRamDZNvE4BDNghPs4p4mte2+Dz0A=
29+
github.com/gitpod-io/gitpod-sdk-go v0.13.0 h1:yu9onZoBJUiI7ar+fSM09iF9eBhZajVtsyxZMON9uM8=
30+
github.com/gitpod-io/gitpod-sdk-go v0.13.0/go.mod h1:4mCKUT0lDkx/sJBRamDZNvE4BDNghPs4p4mte2+Dz0A=
3131
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
3232
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
3333
github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM=

internal/provider/authenticated_identity_data_source.go

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

77
gitpod "github.com/gitpod-io/gitpod-sdk-go"
8-
"github.com/gitpod-io/gitpod-sdk-go/shared"
98
"github.com/hashicorp/terraform-plugin-framework/datasource"
109
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
1110
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -41,6 +40,10 @@ func (d *authenticatedIdentityDataSource) Schema(_ context.Context, _ datasource
4140
Computed: true,
4241
MarkdownDescription: "Organization ID associated with the authenticated identity.",
4342
},
43+
"organization_tier": schema.StringAttribute{
44+
Computed: true,
45+
MarkdownDescription: "Organization tier (e.g. plan level) of the authenticated identity.",
46+
},
4447
},
4548
}
4649
}
@@ -67,20 +70,22 @@ func (d *authenticatedIdentityDataSource) Read(ctx context.Context, _ datasource
6770
return
6871
}
6972

70-
state := mapAuthenticatedIdentityToDataSourceModel(getResp.OrganizationID, getResp.Subject)
73+
state := mapAuthenticatedIdentityToDataSourceModel(getResp)
7174
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
7275
}
7376

74-
func mapAuthenticatedIdentityToDataSourceModel(organizationID string, subject shared.Subject) authenticatedIdentityDataSourceModel {
77+
func mapAuthenticatedIdentityToDataSourceModel(resp *gitpod.IdentityGetAuthenticatedIdentityResponse) authenticatedIdentityDataSourceModel {
7578
return authenticatedIdentityDataSourceModel{
76-
ID: stringValueOrNull(subject.ID),
77-
Principal: stringValueOrNull(string(subject.Principal)),
78-
OrganizationID: stringValueOrNull(organizationID),
79+
ID: stringValueOrNull(resp.Subject.ID),
80+
Principal: stringValueOrNull(string(resp.Subject.Principal)),
81+
OrganizationID: stringValueOrNull(resp.OrganizationID),
82+
OrganizationTier: stringValueOrNull(resp.OrganizationTier),
7983
}
8084
}
8185

8286
type authenticatedIdentityDataSourceModel struct {
83-
ID types.String `tfsdk:"id"`
84-
Principal types.String `tfsdk:"principal"`
85-
OrganizationID types.String `tfsdk:"organization_id"`
87+
ID types.String `tfsdk:"id"`
88+
Principal types.String `tfsdk:"principal"`
89+
OrganizationID types.String `tfsdk:"organization_id"`
90+
OrganizationTier types.String `tfsdk:"organization_tier"`
8691
}

internal/provider/authenticated_identity_data_source_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ package provider
33
import (
44
"testing"
55

6+
gitpod "github.com/gitpod-io/gitpod-sdk-go"
67
"github.com/gitpod-io/gitpod-sdk-go/shared"
78
"github.com/stretchr/testify/assert"
89
)
910

1011
func TestMapAuthenticatedIdentityToDataSourceModel(t *testing.T) {
11-
got := mapAuthenticatedIdentityToDataSourceModel("org-123", shared.Subject{
12-
ID: "subject-123",
13-
Principal: shared.PrincipalUser,
12+
got := mapAuthenticatedIdentityToDataSourceModel(&gitpod.IdentityGetAuthenticatedIdentityResponse{
13+
OrganizationID: "org-123",
14+
OrganizationTier: "pro",
15+
Subject: shared.Subject{
16+
ID: "subject-123",
17+
Principal: shared.PrincipalUser,
18+
},
1419
})
1520

1621
assert.Equal(t, "subject-123", got.ID.ValueString())
1722
assert.Equal(t, string(shared.PrincipalUser), got.Principal.ValueString())
1823
assert.Equal(t, "org-123", got.OrganizationID.ValueString())
24+
assert.Equal(t, "pro", got.OrganizationTier.ValueString())
1925
}

internal/provider/data_source.go

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,24 @@ func (d *runnerDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
8383
"metrics": schema.SingleNestedAttribute{
8484
Computed: true,
8585
Attributes: map[string]schema.Attribute{
86-
"enabled": schema.BoolAttribute{Computed: true},
87-
"url": schema.StringAttribute{Computed: true},
88-
"username": schema.StringAttribute{Computed: true},
86+
"enabled": schema.BoolAttribute{Computed: true},
87+
"managed_metrics_enabled": schema.BoolAttribute{Computed: true, MarkdownDescription: "When true, the runner pushes metrics to the management plane instead of directly to the remote_write endpoint."},
88+
"url": schema.StringAttribute{Computed: true},
89+
"username": schema.StringAttribute{Computed: true},
90+
},
91+
},
92+
"update_window": schema.SingleNestedAttribute{
93+
Computed: true,
94+
MarkdownDescription: "Daily time window (UTC) during which auto-updates are allowed.",
95+
Attributes: map[string]schema.Attribute{
96+
"start_hour": schema.Int64Attribute{
97+
Computed: true,
98+
MarkdownDescription: "Start of the update window as a UTC hour (0-23).",
99+
},
100+
"end_hour": schema.Int64Attribute{
101+
Computed: true,
102+
MarkdownDescription: "End of the update window as a UTC hour (0-23).",
103+
},
89104
},
90105
},
91106
},
@@ -158,20 +173,9 @@ func mapRunnerToDataSourceModel(runner gitpod.Runner) runnerDataSourceModel {
158173
}
159174

160175
m.Spec = &runnerDataSourceSpecModel{
161-
DesiredPhase: stringValueOrNull(string(runner.Spec.DesiredPhase)),
162-
Variant: stringValueOrNull(string(runner.Spec.Variant)),
163-
Configuration: &runnerDataSourceConfigModel{
164-
AutoUpdate: types.BoolValue(runner.Spec.Configuration.AutoUpdate),
165-
DevcontainerImageCacheEnabled: types.BoolValue(runner.Spec.Configuration.DevcontainerImageCacheEnabled),
166-
Region: stringValueOrNull(runner.Spec.Configuration.Region),
167-
ReleaseChannel: stringValueOrNull(string(runner.Spec.Configuration.ReleaseChannel)),
168-
LogLevel: stringValueOrNull(string(runner.Spec.Configuration.LogLevel)),
169-
Metrics: &runnerDataSourceMetricsModel{
170-
Enabled: types.BoolValue(runner.Spec.Configuration.Metrics.Enabled),
171-
URL: stringValueOrNull(runner.Spec.Configuration.Metrics.URL),
172-
Username: stringValueOrNull(runner.Spec.Configuration.Metrics.Username),
173-
},
174-
},
176+
DesiredPhase: stringValueOrNull(string(runner.Spec.DesiredPhase)),
177+
Variant: stringValueOrNull(string(runner.Spec.Variant)),
178+
Configuration: mapRunnerConfigToDataSourceModel(runner),
175179
}
176180

177181
statusAttrTypes := map[string]attr.Type{
@@ -191,6 +195,29 @@ func mapRunnerToDataSourceModel(runner gitpod.Runner) runnerDataSourceModel {
191195
return m
192196
}
193197

198+
func mapRunnerConfigToDataSourceModel(runner gitpod.Runner) *runnerDataSourceConfigModel {
199+
cfg := &runnerDataSourceConfigModel{
200+
AutoUpdate: types.BoolValue(runner.Spec.Configuration.AutoUpdate),
201+
DevcontainerImageCacheEnabled: types.BoolValue(runner.Spec.Configuration.DevcontainerImageCacheEnabled),
202+
Region: stringValueOrNull(runner.Spec.Configuration.Region),
203+
ReleaseChannel: stringValueOrNull(string(runner.Spec.Configuration.ReleaseChannel)),
204+
LogLevel: stringValueOrNull(string(runner.Spec.Configuration.LogLevel)),
205+
Metrics: &runnerDataSourceMetricsModel{
206+
Enabled: types.BoolValue(runner.Spec.Configuration.Metrics.Enabled),
207+
ManagedMetricsEnabled: types.BoolValue(runner.Spec.Configuration.Metrics.ManagedMetricsEnabled),
208+
URL: stringValueOrNull(runner.Spec.Configuration.Metrics.URL),
209+
Username: stringValueOrNull(runner.Spec.Configuration.Metrics.Username),
210+
},
211+
}
212+
if startHour, endHour, ok := mapUpdateWindowValues(runner.Spec.Configuration.UpdateWindow); ok {
213+
cfg.UpdateWindow = &runnerDataSourceUpdateWindowModel{
214+
StartHour: startHour,
215+
EndHour: endHour,
216+
}
217+
}
218+
return cfg
219+
}
220+
194221
// Data source models — separate from resource models since all fields
195222
// are computed and there's no password field (API doesn't return it).
196223

@@ -210,16 +237,23 @@ type runnerDataSourceSpecModel struct {
210237
}
211238

212239
type runnerDataSourceConfigModel struct {
213-
AutoUpdate types.Bool `tfsdk:"auto_update"`
214-
DevcontainerImageCacheEnabled types.Bool `tfsdk:"devcontainer_image_cache_enabled"`
215-
Region types.String `tfsdk:"region"`
216-
ReleaseChannel types.String `tfsdk:"release_channel"`
217-
LogLevel types.String `tfsdk:"log_level"`
218-
Metrics *runnerDataSourceMetricsModel `tfsdk:"metrics"`
240+
AutoUpdate types.Bool `tfsdk:"auto_update"`
241+
DevcontainerImageCacheEnabled types.Bool `tfsdk:"devcontainer_image_cache_enabled"`
242+
Region types.String `tfsdk:"region"`
243+
ReleaseChannel types.String `tfsdk:"release_channel"`
244+
LogLevel types.String `tfsdk:"log_level"`
245+
Metrics *runnerDataSourceMetricsModel `tfsdk:"metrics"`
246+
UpdateWindow *runnerDataSourceUpdateWindowModel `tfsdk:"update_window"`
247+
}
248+
249+
type runnerDataSourceUpdateWindowModel struct {
250+
StartHour types.Int64 `tfsdk:"start_hour"`
251+
EndHour types.Int64 `tfsdk:"end_hour"`
219252
}
220253

221254
type runnerDataSourceMetricsModel struct {
222-
Enabled types.Bool `tfsdk:"enabled"`
223-
URL types.String `tfsdk:"url"`
224-
Username types.String `tfsdk:"username"`
255+
Enabled types.Bool `tfsdk:"enabled"`
256+
ManagedMetricsEnabled types.Bool `tfsdk:"managed_metrics_enabled"`
257+
URL types.String `tfsdk:"url"`
258+
Username types.String `tfsdk:"username"`
225259
}

internal/provider/helpers.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"time"
66

7+
gitpod "github.com/gitpod-io/gitpod-sdk-go"
78
"github.com/hashicorp/terraform-plugin-framework/types"
89
)
910

@@ -50,3 +51,16 @@ func timeValueOrNull(value time.Time) types.String {
5051
}
5152
return types.StringValue(value.Format(time.RFC3339Nano))
5253
}
54+
55+
func mapUpdateWindowValues(window gitpod.UpdateWindow) (types.Int64, types.Int64, bool) {
56+
if window.JSON.RawJSON() == "" {
57+
return types.Int64Null(), types.Int64Null(), false
58+
}
59+
60+
endHour := types.Int64Null()
61+
if !window.JSON.EndHour.IsMissing() {
62+
endHour = types.Int64Value(window.EndHour)
63+
}
64+
65+
return types.Int64Value(window.StartHour), endHour, true
66+
}

0 commit comments

Comments
 (0)