Skip to content

Commit b6d9741

Browse files
authored
Add cluster attributes to pipeline resource, data source (#927)
* Add cluster id/name attributes to pipeline resource, data source * Use docker registry
1 parent e23f297 commit b6d9741

File tree

8 files changed

+38
-1
lines changed

8 files changed

+38
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM public.ecr.aws/docker/library/golang:1.24.2@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e
1+
FROM golang:1.24.2@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e
22

33
RUN apt-get update \
44
&& apt-get install -y unzip

buildkite/data_source_pipeline.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type pipelineDataSourceModel struct {
2020
Slug types.String `tfsdk:"slug"`
2121
UUID types.String `tfsdk:"uuid"`
2222
WebhookUrl types.String `tfsdk:"webhook_url"`
23+
ClusterId types.String `tfsdk:"cluster_id"`
24+
ClusterName types.String `tfsdk:"cluster_name"`
2325
}
2426

2527
type pipelineDatasource struct {
@@ -82,6 +84,14 @@ func (*pipelineDatasource) Schema(ctx context.Context, req datasource.SchemaRequ
8284
Computed: true,
8385
MarkdownDescription: "The Buildkite webhook URL that triggers builds on this pipeline.",
8486
},
87+
"cluster_id": schema.StringAttribute{
88+
Computed: true,
89+
MarkdownDescription: "The GraphQL ID of the cluster the pipeline is (optionally) attached to.",
90+
},
91+
"cluster_name": schema.StringAttribute{
92+
Computed: true,
93+
MarkdownDescription: "The name of the cluster the pipeline is (optionally) attached to.",
94+
},
8595
},
8696
}
8797
}
@@ -123,6 +133,8 @@ func (c *pipelineDatasource) Read(ctx context.Context, req datasource.ReadReques
123133
state.Slug = types.StringValue(pipeline.Pipeline.Slug)
124134
state.UUID = types.StringValue(pipeline.Pipeline.PipelineUuid)
125135
state.WebhookUrl = types.StringValue(pipeline.Pipeline.WebhookURL)
136+
state.ClusterId = types.StringPointerValue(pipeline.Pipeline.Cluster.Id)
137+
state.ClusterName = types.StringPointerValue(pipeline.Pipeline.Cluster.Name)
126138

127139
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
128140
}

buildkite/generated.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildkite/graphql/pipeline.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ fragment PipelineFields on Pipeline {
99
cluster {
1010
# @genqlient(pointer: true)
1111
id
12+
# @genqlient(pointer: true)
13+
name
1214
}
1315
# @genqlient(pointer: true)
1416
color

buildkite/resource_pipeline.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type pipelineResourceModel struct {
7777
CancelIntermediateBuildsBranchFilter types.String `tfsdk:"cancel_intermediate_builds_branch_filter"`
7878
Color types.String `tfsdk:"color"`
7979
ClusterId types.String `tfsdk:"cluster_id"`
80+
ClusterName types.String `tfsdk:"cluster_name"`
8081
DefaultTeamId types.String `tfsdk:"default_team_id"`
8182
DefaultBranch types.String `tfsdk:"default_branch"`
8283
DefaultTimeoutInMinutes types.Int64 `tfsdk:"default_timeout_in_minutes"`
@@ -490,6 +491,10 @@ func (*pipelineResource) Schema(ctx context.Context, req resource.SchemaRequest,
490491
MarkdownDescription: "Attach this pipeline to the given cluster GraphQL ID.",
491492
Optional: true,
492493
},
494+
"cluster_name": schema.StringAttribute{
495+
MarkdownDescription: "The name of the cluster the pipeline is (optionally) attached to.",
496+
Computed: true,
497+
},
493498
"default_team_id": schema.StringAttribute{
494499
MarkdownDescription: "The GraphQL ID of the team to use as the default owner of the pipeline.",
495500
Optional: true,
@@ -998,6 +1003,7 @@ func setPipelineModel(model *pipelineResourceModel, data pipelineResponse) {
9981003
model.CancelIntermediateBuilds = types.BoolValue(data.GetCancelIntermediateBuilds())
9991004
model.CancelIntermediateBuildsBranchFilter = types.StringValue(data.GetCancelIntermediateBuildsBranchFilter())
10001005
model.ClusterId = types.StringPointerValue(data.GetCluster().Id)
1006+
model.ClusterName = types.StringPointerValue(data.GetCluster().Name)
10011007
model.Color = types.StringPointerValue(data.GetColor())
10021008
model.DefaultBranch = types.StringValue(data.GetDefaultBranch())
10031009
model.DefaultTimeoutInMinutes = types.Int64PointerValue(defaultTimeoutInMinutes)

buildkite/resource_pipeline_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
9090
// check state values are correct
9191
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "branch_configuration"),
9292
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_id"),
93+
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_name"),
9394
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "true"),
9495
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "false"),
9596
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds_branch_filter", ""),
@@ -203,6 +204,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
203204
// check state values are correct
204205
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "branch_configuration"),
205206
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_id"),
207+
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_name"),
206208
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "true"),
207209
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "false"),
208210
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds_branch_filter", ""),
@@ -435,6 +437,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
435437
// check state values are correct
436438
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "branch_configuration"),
437439
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_id"),
440+
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_name"),
438441
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "true"),
439442
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "false"),
440443
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds_branch_filter", ""),
@@ -556,6 +559,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
556559
Config: config,
557560
Check: resource.ComposeAggregateTestCheckFunc(
558561
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_id", "buildkite_cluster.cluster", "id"),
562+
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_name", "buildkite_cluster.cluster", "name"),
559563
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "tags.0", "llama"),
560564
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "false"),
561565
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "true"),
@@ -660,6 +664,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
660664
return nil
661665
},
662666
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_id", "buildkite_cluster.cluster", "id"),
667+
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_name", "buildkite_cluster.cluster", "name"),
663668
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "provider_settings.ignore_default_branch_pull_requests", "true"),
664669
aggregateRemoteCheck(&pipeline),
665670
),

docs/data-sources/pipeline.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ data "buildkite_pipeline" "pipeline" {
3030

3131
### Read-Only
3232

33+
- `cluster_id` (String) The GraphQL ID of the cluster the pipeline is (optionally) attached to.
34+
- `cluster_name` (String) The name of the cluster the pipeline is (optionally) attached to.
3335
- `default_branch` (String) The default branch to prefill when new builds are created or triggered.
3436
- `description` (String) The description of the pipeline.
3537
- `id` (String) The GraphQL ID of the pipeline.

docs/resources/pipeline.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ resource "github_repository_webhook" "my_webhook" {
159159
### Read-Only
160160

161161
- `badge_url` (String) The badge URL showing build state.
162+
- `cluster_name` (String) The name of the cluster the pipeline is (optionally) attached to.
162163
- `id` (String) The GraphQL ID of the pipeline.
163164
- `uuid` (String) The UUID of the pipeline.
164165
- `webhook_url` (String) The webhook URL used to trigger builds from VCS providers.

0 commit comments

Comments
 (0)