Skip to content

Commit

Permalink
Skip heroku_review_app_config.deploy_target.id region lookup for space (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
ryanbrainard authored Apr 11, 2023
1 parent 0858940 commit 3a83337
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions heroku/resource_heroku_review_app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
heroku "github.com/heroku/heroku-go/v5"
)

const (
DeployTargetTypeSpace = "space"
DeployTargeTypeRegion = "region"
)

func resourceHerokuReviewAppConfig() *schema.Resource {
return &schema.Resource{
CreateContext: resourceHerokuReviewAppConfigCreate,
Expand Down Expand Up @@ -52,7 +57,7 @@ func resourceHerokuReviewAppConfig() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"space", "region"}, false),
ValidateFunc: validation.StringInSlice([]string{DeployTargetTypeSpace, DeployTargeTypeRegion}, false),
},
},
},
Expand Down Expand Up @@ -327,20 +332,30 @@ func resourceHerokuReviewAppConfigRead(ctx context.Context, d *schema.ResourceDa

deployTarget := make([]map[string]interface{}, 0)
if reviewAppConfig.DeployTarget != nil {
// Lookup region info as the /review-app-config endpoint returns the region UUID
// for the deploy target ID instead of the name (ex. 'us').
region, regionGetErr := client.RegionInfo(ctx, reviewAppConfig.DeployTarget.ID)
if regionGetErr != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("Unable to retrieve region %s", reviewAppConfig.DeployTarget.ID),
Detail: regionGetErr.Error(),
})
return diags
var deployTargetId string
switch reviewAppConfig.DeployTarget.Type {
case DeployTargeTypeRegion:
// Lookup region info as the /review-app-config endpoint returns the region UUID
// for the deploy target ID instead of the name (ex. 'us').
region, regionGetErr := client.RegionInfo(ctx, reviewAppConfig.DeployTarget.ID)
if regionGetErr != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("Unable to retrieve region %s", reviewAppConfig.DeployTarget.ID),
Detail: regionGetErr.Error(),
})
return diags
}

deployTargetId = region.Name
case DeployTargetTypeSpace:
deployTargetId = reviewAppConfig.DeployTarget.ID
default:
panic("unknown deploy target type")
}

deployTarget = append(deployTarget, map[string]interface{}{
"id": region.Name,
"id": deployTargetId,
"type": reviewAppConfig.DeployTarget.Type,
})
}
Expand Down

0 comments on commit 3a83337

Please sign in to comment.