Skip to content

Commit 3a83337

Browse files
authored
Skip heroku_review_app_config.deploy_target.id region lookup for space (#368)
The current code assumes that the heroku_review_app_config.deploy_target is a region and tries to resolve it to a name, but in the case of a deploy target that is a Private Space, it should remain as the id, as space names would violate the schema and cause breaking changes. This skips the name look up if the type is space.
1 parent 0858940 commit 3a83337

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

heroku/resource_heroku_review_app_config.go

+27-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212
heroku "github.com/heroku/heroku-go/v5"
1313
)
1414

15+
const (
16+
DeployTargetTypeSpace = "space"
17+
DeployTargeTypeRegion = "region"
18+
)
19+
1520
func resourceHerokuReviewAppConfig() *schema.Resource {
1621
return &schema.Resource{
1722
CreateContext: resourceHerokuReviewAppConfigCreate,
@@ -52,7 +57,7 @@ func resourceHerokuReviewAppConfig() *schema.Resource {
5257
"type": {
5358
Type: schema.TypeString,
5459
Required: true,
55-
ValidateFunc: validation.StringInSlice([]string{"space", "region"}, false),
60+
ValidateFunc: validation.StringInSlice([]string{DeployTargetTypeSpace, DeployTargeTypeRegion}, false),
5661
},
5762
},
5863
},
@@ -327,20 +332,30 @@ func resourceHerokuReviewAppConfigRead(ctx context.Context, d *schema.ResourceDa
327332

328333
deployTarget := make([]map[string]interface{}, 0)
329334
if reviewAppConfig.DeployTarget != nil {
330-
// Lookup region info as the /review-app-config endpoint returns the region UUID
331-
// for the deploy target ID instead of the name (ex. 'us').
332-
region, regionGetErr := client.RegionInfo(ctx, reviewAppConfig.DeployTarget.ID)
333-
if regionGetErr != nil {
334-
diags = append(diags, diag.Diagnostic{
335-
Severity: diag.Error,
336-
Summary: fmt.Sprintf("Unable to retrieve region %s", reviewAppConfig.DeployTarget.ID),
337-
Detail: regionGetErr.Error(),
338-
})
339-
return diags
335+
var deployTargetId string
336+
switch reviewAppConfig.DeployTarget.Type {
337+
case DeployTargeTypeRegion:
338+
// Lookup region info as the /review-app-config endpoint returns the region UUID
339+
// for the deploy target ID instead of the name (ex. 'us').
340+
region, regionGetErr := client.RegionInfo(ctx, reviewAppConfig.DeployTarget.ID)
341+
if regionGetErr != nil {
342+
diags = append(diags, diag.Diagnostic{
343+
Severity: diag.Error,
344+
Summary: fmt.Sprintf("Unable to retrieve region %s", reviewAppConfig.DeployTarget.ID),
345+
Detail: regionGetErr.Error(),
346+
})
347+
return diags
348+
}
349+
350+
deployTargetId = region.Name
351+
case DeployTargetTypeSpace:
352+
deployTargetId = reviewAppConfig.DeployTarget.ID
353+
default:
354+
panic("unknown deploy target type")
340355
}
341356

342357
deployTarget = append(deployTarget, map[string]interface{}{
343-
"id": region.Name,
358+
"id": deployTargetId,
344359
"type": reviewAppConfig.DeployTarget.Type,
345360
})
346361
}

0 commit comments

Comments
 (0)