Skip to content

Commit dbd04cc

Browse files
committed
Enable release_id support for pipeline promotions
- Flow team has added Promotion#release_id API support - Remove error check that blocked release_id usage - Add release_id to API call when provided - Update documentation with release_id examples and remove outdated notes - Remove obsolete unit test for release_id validation - Pipeline promotions now support both latest and specific release promotion - Validated with local terraform config - both promotion types work perfectly
1 parent ef12b74 commit dbd04cc

File tree

3 files changed

+24
-46
lines changed

3 files changed

+24
-46
lines changed

docs/resources/pipeline_promotion.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,26 @@ A pipeline promotion allows you to deploy releases from one app to other apps wi
1515
pipeline. This enables infrastructure-as-code workflow for promoting code between pipeline stages
1616
such as staging to production.
1717

18-
Currently promotes the latest release from the source app. Support for promoting specific releases
19-
(`release_id` parameter) requires additional API support from the Heroku platform team.
18+
You can promote either the latest release from the source app, or specify a particular release by ID.
2019

2120
## Example Usage
2221

2322
```hcl
24-
# Basic promotion from staging to production
23+
# Basic promotion from staging to production (latest release)
2524
resource "heroku_pipeline_promotion" "staging_to_prod" {
2625
pipeline = heroku_pipeline.my_app.id
2726
source_app_id = heroku_app.staging.id
2827
targets = [heroku_app.production.id]
2928
}
3029
30+
# Promotion of a specific release
31+
resource "heroku_pipeline_promotion" "specific_release" {
32+
pipeline = heroku_pipeline.my_app.id
33+
source_app_id = heroku_app.staging.id
34+
release_id = "01234567-89ab-cdef-0123-456789abcdef"
35+
targets = [heroku_app.production.id]
36+
}
37+
3138
# Promotion to multiple target apps
3239
resource "heroku_pipeline_promotion" "staging_to_multiple" {
3340
pipeline = heroku_pipeline.my_app.id
@@ -46,8 +53,7 @@ The following arguments are supported:
4653
* `pipeline` - (Required) The UUID of the pipeline containing the apps.
4754
* `source_app_id` - (Required) The UUID of the source app to promote from.
4855
* `targets` - (Required) Set of UUIDs of target apps to promote to.
49-
* `release_id` - (Optional) **Not yet supported**. The UUID of a specific release to promote.
50-
Currently returns an error as this requires additional Heroku platform API support.
56+
* `release_id` - (Optional) The UUID of a specific release to promote. If not specified, promotes the latest release from the source app.
5157

5258
## Attributes Reference
5359

@@ -64,9 +70,5 @@ The following attributes are exported:
6470
* All apps (source and targets) must be in the same pipeline.
6571
* All apps must have the same generation (Cedar or Fir). See [`heroku_pipeline`](./pipeline.html) for generation compatibility requirements.
6672
* The source app must have at least one release to promote.
67-
* Promotions copy the latest release from the source app to all target apps.
68-
69-
## Future Enhancement
73+
* Promotions copy either the latest release (if no `release_id` specified) or the specified release to all target apps.
7074

71-
The `release_id` parameter will be supported once the Heroku platform team adds the necessary API
72-
functionality. This will enable promoting specific releases rather than just the latest release.

heroku/resource_heroku_pipeline_promotion.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Pipeline Promotion Resource
22
//
33
// This resource allows promoting releases between apps in a Heroku Pipeline.
4-
// Currently promotes the latest release from the source app to target apps.
5-
//
6-
// DEPENDENCY: The 'release_id' field requires Flow team to add Promotion#release_id
7-
// API support. Until then, only latest release promotion is supported.
4+
// Supports promoting either the latest release or a specific release by ID.
85
package heroku
96

107
import (
@@ -45,7 +42,7 @@ func resourceHerokuPipelinePromotion() *schema.Resource {
4542
Optional: true,
4643
ForceNew: true,
4744
ValidateFunc: validation.IsUUID,
48-
Description: "Specific release ID to promote (requires Flow team API update)",
45+
Description: "Specific release ID to promote (optional, defaults to latest release)",
4946
},
5047

5148
"targets": {
@@ -86,12 +83,7 @@ func resourceHerokuPipelinePromotionCreate(d *schema.ResourceData, meta interfac
8683

8784
log.Printf("[DEBUG] Creating pipeline promotion")
8885

89-
// Check if release_id is specified - this requires Flow team API support
90-
if releaseID, ok := d.GetOk("release_id"); ok {
91-
return fmt.Errorf("release_id parameter (%s) is not yet supported - waiting for Flow team to add Promotion#release_id API support", releaseID.(string))
92-
}
93-
94-
// Build promotion options using current API
86+
// Build promotion options with release_id support
9587
pipelineID := d.Get("pipeline").(string)
9688
sourceAppID := d.Get("source_app_id").(string)
9789
targets := d.Get("targets").(*schema.Set)
@@ -102,6 +94,15 @@ func resourceHerokuPipelinePromotionCreate(d *schema.ResourceData, meta interfac
10294
ID *string `json:"id,omitempty" url:"id,omitempty,key"`
10395
}{ID: &sourceAppID}
10496

97+
// Add release_id if specified
98+
if releaseID, ok := d.GetOk("release_id"); ok {
99+
releaseIDStr := releaseID.(string)
100+
opts.Source.Release = &struct {
101+
ID *string `json:"id,omitempty" url:"id,omitempty,key"`
102+
}{ID: &releaseIDStr}
103+
log.Printf("[DEBUG] Promoting specific release: %s", releaseIDStr)
104+
}
105+
105106
// Convert targets set to slice
106107
for _, target := range targets.List() {
107108
targetAppID := target.(string)

heroku/resource_heroku_pipeline_promotion_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package heroku
22

33
import (
4-
"strings"
54
"testing"
65

76
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -54,27 +53,3 @@ func TestResourceHerokuPipelinePromotion_Schema(t *testing.T) {
5453
t.Errorf("targets field should be TypeSet")
5554
}
5655
}
57-
58-
func TestResourceHerokuPipelinePromotion_ReleaseIdValidation(t *testing.T) {
59-
// This test validates that release_id parameter currently returns an error
60-
// Once Flow team adds API support, this test should be updated
61-
62-
d := schema.TestResourceDataRaw(t, resourceHerokuPipelinePromotion().Schema, map[string]interface{}{
63-
"pipeline": "01234567-89ab-cdef-0123-456789abcdef",
64-
"source_app_id": "01234567-89ab-cdef-0123-456789abcdef",
65-
"release_id": "01234567-89ab-cdef-0123-456789abcdef",
66-
"targets": []interface{}{"01234567-89ab-cdef-0123-456789abcdef"},
67-
})
68-
69-
meta := &Config{} // Mock config
70-
71-
err := resourceHerokuPipelinePromotionCreate(d, meta)
72-
if err == nil {
73-
t.Error("Expected error when release_id is provided, but got none")
74-
}
75-
76-
expectedError := "release_id parameter"
77-
if err != nil && !strings.Contains(err.Error(), expectedError) {
78-
t.Errorf("Expected error to contain '%s', got: %s", expectedError, err.Error())
79-
}
80-
}

0 commit comments

Comments
 (0)