Skip to content

chore(terraform): use a util func to build internal terraform id#869

Merged
rubenhoenle merged 2 commits into
mainfrom
chore/internal-terraform-id-util
Jun 12, 2025
Merged

chore(terraform): use a util func to build internal terraform id#869
rubenhoenle merged 2 commits into
mainfrom
chore/internal-terraform-id-util

Conversation

@rubenhoenle

@rubenhoenle rubenhoenle commented Jun 5, 2025

Copy link
Copy Markdown
Member

Description

Instead of duplicating the code everywhere to build the internal terraform id for resource/datasource implementations, it's now a util func which can be called in a single line. Makes it much more easy to read IMO.

// BEFORE
idParts := []string{
  model.ProjectId.ValueString(),
  model.BarId.ValueString(),
}
  model.Id = types.StringValue(strings.Join(idParts, core.Separator),
)

// AFTER
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.BarId.ValueString())

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@rubenhoenle rubenhoenle self-assigned this Jun 5, 2025
@rubenhoenle rubenhoenle force-pushed the chore/internal-terraform-id-util branch from 4565d61 to d22ac04 Compare June 6, 2025 08:23

@marceljk marceljk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and makes it more readable!
I just found a few resources where the ID build can be adjusted:

id := model.ProjectId.ValueString() + core.Separator + model.DistributionId.ValueString() + core.Separator + *customDomain.Name
model.ID = types.StringValue(id)

id := *distribution.ProjectId + core.Separator + *distribution.Id
model.ID = types.StringValue(id)

modelId := strings.Join(apiIpRanges, ",")
model.Id = types.StringValue(modelId)

@rubenhoenle rubenhoenle force-pushed the chore/internal-terraform-id-util branch from d22ac04 to 6e2bf9a Compare June 12, 2025 12:33
@rubenhoenle rubenhoenle merged commit b313ef6 into main Jun 12, 2025
4 checks passed
@rubenhoenle rubenhoenle deleted the chore/internal-terraform-id-util branch June 12, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants