Skip to content

Add cluster attributes to pipeline resource, data source #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/docker/library/golang:1.24.2@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e
FROM golang:1.24.2@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e

RUN apt-get update \
&& apt-get install -y unzip
Expand Down
12 changes: 12 additions & 0 deletions buildkite/data_source_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type pipelineDataSourceModel struct {
Slug types.String `tfsdk:"slug"`
UUID types.String `tfsdk:"uuid"`
WebhookUrl types.String `tfsdk:"webhook_url"`
ClusterId types.String `tfsdk:"cluster_id"`
ClusterName types.String `tfsdk:"cluster_name"`
}

type pipelineDatasource struct {
Expand Down Expand Up @@ -82,6 +84,14 @@ func (*pipelineDatasource) Schema(ctx context.Context, req datasource.SchemaRequ
Computed: true,
MarkdownDescription: "The Buildkite webhook URL that triggers builds on this pipeline.",
},
"cluster_id": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The GraphQL ID of the cluster the pipeline is (optionally) attached to.",
},
"cluster_name": schema.StringAttribute{
Computed: true,
MarkdownDescription: "The name of the cluster the pipeline is (optionally) attached to.",
},
},
}
}
Expand Down Expand Up @@ -123,6 +133,8 @@ func (c *pipelineDatasource) Read(ctx context.Context, req datasource.ReadReques
state.Slug = types.StringValue(pipeline.Pipeline.Slug)
state.UUID = types.StringValue(pipeline.Pipeline.PipelineUuid)
state.WebhookUrl = types.StringValue(pipeline.Pipeline.WebhookURL)
state.ClusterId = types.StringPointerValue(pipeline.Pipeline.Cluster.Id)
state.ClusterName = types.StringPointerValue(pipeline.Pipeline.Cluster.Name)

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
9 changes: 9 additions & 0 deletions buildkite/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions buildkite/graphql/pipeline.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ fragment PipelineFields on Pipeline {
cluster {
# @genqlient(pointer: true)
id
# @genqlient(pointer: true)
name
}
# @genqlient(pointer: true)
color
Expand Down
6 changes: 6 additions & 0 deletions buildkite/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type pipelineResourceModel struct {
CancelIntermediateBuildsBranchFilter types.String `tfsdk:"cancel_intermediate_builds_branch_filter"`
Color types.String `tfsdk:"color"`
ClusterId types.String `tfsdk:"cluster_id"`
ClusterName types.String `tfsdk:"cluster_name"`
DefaultTeamId types.String `tfsdk:"default_team_id"`
DefaultBranch types.String `tfsdk:"default_branch"`
DefaultTimeoutInMinutes types.Int64 `tfsdk:"default_timeout_in_minutes"`
Expand Down Expand Up @@ -490,6 +491,10 @@ func (*pipelineResource) Schema(ctx context.Context, req resource.SchemaRequest,
MarkdownDescription: "Attach this pipeline to the given cluster GraphQL ID.",
Optional: true,
},
"cluster_name": schema.StringAttribute{
MarkdownDescription: "The name of the cluster the pipeline is (optionally) attached to.",
Computed: true,
},
"default_team_id": schema.StringAttribute{
MarkdownDescription: "The GraphQL ID of the team to use as the default owner of the pipeline.",
Optional: true,
Expand Down Expand Up @@ -998,6 +1003,7 @@ func setPipelineModel(model *pipelineResourceModel, data pipelineResponse) {
model.CancelIntermediateBuilds = types.BoolValue(data.GetCancelIntermediateBuilds())
model.CancelIntermediateBuildsBranchFilter = types.StringValue(data.GetCancelIntermediateBuildsBranchFilter())
model.ClusterId = types.StringPointerValue(data.GetCluster().Id)
model.ClusterName = types.StringPointerValue(data.GetCluster().Name)
model.Color = types.StringPointerValue(data.GetColor())
model.DefaultBranch = types.StringValue(data.GetDefaultBranch())
model.DefaultTimeoutInMinutes = types.Int64PointerValue(defaultTimeoutInMinutes)
Expand Down
5 changes: 5 additions & 0 deletions buildkite/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
// check state values are correct
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "branch_configuration"),
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_id"),
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_name"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "true"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "false"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds_branch_filter", ""),
Expand Down Expand Up @@ -203,6 +204,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
// check state values are correct
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "branch_configuration"),
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_id"),
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_name"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "true"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "false"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds_branch_filter", ""),
Expand Down Expand Up @@ -435,6 +437,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
// check state values are correct
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "branch_configuration"),
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_id"),
resource.TestCheckNoResourceAttr("buildkite_pipeline.pipeline", "cluster_name"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "true"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "false"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds_branch_filter", ""),
Expand Down Expand Up @@ -556,6 +559,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_id", "buildkite_cluster.cluster", "id"),
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_name", "buildkite_cluster.cluster", "name"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "tags.0", "llama"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "allow_rebuilds", "false"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "cancel_intermediate_builds", "true"),
Expand Down Expand Up @@ -660,6 +664,7 @@ func TestAccBuildkitePipelineResource(t *testing.T) {
return nil
},
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_id", "buildkite_cluster.cluster", "id"),
resource.TestCheckResourceAttrPair("buildkite_pipeline.pipeline", "cluster_name", "buildkite_cluster.cluster", "name"),
resource.TestCheckResourceAttr("buildkite_pipeline.pipeline", "provider_settings.ignore_default_branch_pull_requests", "true"),
aggregateRemoteCheck(&pipeline),
),
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ data "buildkite_pipeline" "pipeline" {

### Read-Only

- `cluster_id` (String) The GraphQL ID of the cluster the pipeline is (optionally) attached to.
- `cluster_name` (String) The name of the cluster the pipeline is (optionally) attached to.
- `default_branch` (String) The default branch to prefill when new builds are created or triggered.
- `description` (String) The description of the pipeline.
- `id` (String) The GraphQL ID of the pipeline.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ resource "github_repository_webhook" "my_webhook" {
### Read-Only

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