Skip to content

Commit 36303bb

Browse files
Add Fir generation support to heroku_app data source (#415)
- Add generation field to schema and read function - Update documentation to support both Cedar and Fir apps - Add test coverage for Fir app data source behavior - Remove classic buildpacks limitation from docs Resolves: W-19773193 Update docs/data-sources/app.md Update docs/data-sources/app.md Signed-off-by: Johnny Winn <[email protected]> Co-authored-by: Sandy Lai <[email protected]>
1 parent fcb2977 commit 36303bb

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

docs/data-sources/app.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,23 @@ description: |-
1010

1111
Use this data source to get information about a Heroku app.
1212

13-
~> **NOTE:** This resource is only supported for apps that use [classic buildpacks](https://devcenter.heroku.com/articles/buildpacks#classic-buildpacks).
13+
This data source supports both the [Cedar and Fir generations](https://devcenter.heroku.com/articles/generations) of Heroku apps.
1414

1515
## Example Usage
1616

1717
```hcl-terraform
1818
# Lookup an existing Heroku app
1919
data "heroku_app" "default" {
20-
name = "my-cool-app"
20+
name = "my-cool-app"
21+
}
22+
23+
# Example: Check app generation and buildpacks
24+
output "app_generation" {
25+
value = data.heroku_app.default.generation
26+
}
27+
28+
output "app_buildpacks" {
29+
value = data.heroku_app.default.buildpacks
2130
}
2231
```
2332

@@ -39,7 +48,9 @@ The following attributes are exported:
3948

4049
* `stack`: The application [stack](https://devcenter.heroku.com/articles/stack) is what platform to run the application in.
4150

42-
* `buildpacks`: A list of buildpacks that this app uses.
51+
* `generation`: The generation of the app platform (`cedar` or `fir`).
52+
53+
* `buildpacks`: The list of buildpacks that this app uses. Empty for apps using Cloud Native Buildpacks, such as Fir-generation apps, which list buildpacks in `project.toml` instead.
4354

4455
* `space`: The [space](https://devcenter.heroku.com/articles/private-spaces) in which the app runs. Not present for [Common Runtime](https://devcenter.heroku.com/articles/dyno-runtime#common-runtime) apps.
4556

heroku/data_source_heroku_app.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func dataSourceHerokuApp() *schema.Resource {
3535
Default: nil,
3636
},
3737

38+
"generation": {
39+
Type: schema.TypeString,
40+
Computed: true,
41+
Description: "Generation of the app platform (cedar or fir)",
42+
},
43+
3844
"internal_routing": {
3945
Type: schema.TypeBool,
4046
Computed: true,
@@ -139,6 +145,7 @@ func dataSourceHerokuAppRead(d *schema.ResourceData, m interface{}) error {
139145

140146
d.Set("buildpacks", app.Buildpacks)
141147
d.Set("config_vars", app.Vars)
148+
d.Set("generation", app.Generation)
142149

143150
releaseRange := heroku.ListRange{
144151
Field: "version",
@@ -147,7 +154,7 @@ func dataSourceHerokuAppRead(d *schema.ResourceData, m interface{}) error {
147154
}
148155
releases, err := client.ReleaseList(context.Background(), app.App.ID, &releaseRange)
149156
if err != nil {
150-
return fmt.Errorf("Failed to fetch releases for app '%s': %s", name, err)
157+
return fmt.Errorf("failed to fetch releases for app '%s': %s", name, err)
151158
}
152159
for _, r := range releases {
153160
if r.Status == "succeeded" {

heroku/data_source_heroku_app_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func TestAccDatasourceHerokuApp_Basic(t *testing.T) {
3434
"data.heroku_app.foobar", "buildpacks.0", "https://github.com/heroku/heroku-buildpack-multi-procfile"),
3535
resource.TestCheckResourceAttr(
3636
"data.heroku_app.foobar", "acm", "false"),
37+
resource.TestCheckResourceAttr(
38+
"data.heroku_app.foobar", "generation", "cedar"),
3739
),
3840
},
3941
},
@@ -89,6 +91,41 @@ func TestAccDatasourceHerokuApp_Organization(t *testing.T) {
8991
})
9092
}
9193

94+
// testStep_AccDatasourceHerokuApp_Generation_Fir tests the data source with a Fir app
95+
func testStep_AccDatasourceHerokuApp_Generation_Fir(t *testing.T, spaceConfig, spaceName string) resource.TestStep {
96+
randString := acctest.RandString(5)
97+
appName := fmt.Sprintf("tftest-app-ds-fir-%s", randString)
98+
99+
config := fmt.Sprintf(`%s
100+
101+
resource "heroku_app" "data_source_test" {
102+
name = "%s"
103+
region = heroku_space.foobar.region
104+
space = heroku_space.foobar.name
105+
106+
organization {
107+
name = "%s"
108+
}
109+
}
110+
111+
data "heroku_app" "data_source_test" {
112+
name = heroku_app.data_source_test.name
113+
}`,
114+
spaceConfig, appName, testAccConfig.GetOrganizationOrSkip(t))
115+
116+
return resource.TestStep{
117+
Config: config,
118+
Check: resource.ComposeTestCheckFunc(
119+
resource.TestCheckResourceAttr("data.heroku_app.data_source_test", "name", appName),
120+
resource.TestCheckResourceAttr("data.heroku_app.data_source_test", "generation", "fir"),
121+
resource.TestCheckResourceAttr("data.heroku_app.data_source_test", "stack", "cnb"),
122+
resource.TestCheckResourceAttr("data.heroku_app.data_source_test", "buildpacks.#", "0"),
123+
resource.TestCheckResourceAttrSet("data.heroku_app.data_source_test", "id"),
124+
resource.TestCheckResourceAttrSet("data.heroku_app.data_source_test", "space"),
125+
),
126+
}
127+
}
128+
92129
func testAccCheckHerokuApp_basic(appName string) string {
93130
return fmt.Sprintf(`
94131
resource "heroku_app" "foobar" {

heroku/resource_heroku_space_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ func TestAccHerokuSpace_Fir(t *testing.T) {
8888
testStep_AccHerokuApp_Generation_Fir(t, spaceConfig, spaceName),
8989
// Step 3: Test Fir build generation behavior (valid build)
9090
testStep_AccHerokuBuild_Generation_FirValid(spaceConfig, spaceName),
91-
// Step 4: Test Fir telemetry drain functionality
91+
// Step 4: Test Fir app data source functionality
92+
testStep_AccDatasourceHerokuApp_Generation_Fir(t, spaceConfig, spaceName),
93+
// Step 5: Test Fir telemetry drain functionality
9294
testStep_AccHerokuTelemetryDrain_Generation_Fir(t, spaceConfig, spaceName),
9395
},
9496
})

0 commit comments

Comments
 (0)