Skip to content

fix: Stack creation panics if no project is provided in the creation options#1284

Open
arybolovlev wants to merge 3 commits intomainfrom
fix-stacks-create-options-valid
Open

fix: Stack creation panics if no project is provided in the creation options#1284
arybolovlev wants to merge 3 commits intomainfrom
fix-stacks-create-options-valid

Conversation

@arybolovlev
Copy link
Contributor

Description

When a new Stack is created without the mandatory Project field in the StackCreateOptions structure, the creation process panics instead of returning a validation error.

The following code will panic because the Project field is a pointer, and the validation method does not check whether it is nil:

s, err := client.Stacks.Create(context.TODO(), tfc.StackCreateOptions{
    Name: "a-stack",
})

This PR adds a nil pointer check to ensure that the ErrRequiredProject error is returned if the Project field is not set, or if it is set but Project.ID is empty.

Testing plan

I have added a unit test for the valid() method of the StackCreateOptions structure.

External links

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

$ go test . -timeout 1m -count 1 -v -run='Test_validStackCreateOptions'
=== RUN   Test_validStackCreateOptions
=== PAUSE Test_validStackCreateOptions
=== CONT  Test_validStackCreateOptions
=== RUN   Test_validStackCreateOptions/with_empty_stack_name
=== RUN   Test_validStackCreateOptions/with_empty_project_option
=== RUN   Test_validStackCreateOptions/with_empty_project_ID
=== RUN   Test_validStackCreateOptions/with_valid_options
--- PASS: Test_validStackCreateOptions (0.00s)
    --- PASS: Test_validStackCreateOptions/with_empty_stack_name (0.00s)
    --- PASS: Test_validStackCreateOptions/with_empty_project_option (0.00s)
    --- PASS: Test_validStackCreateOptions/with_empty_project_ID (0.00s)
    --- PASS: Test_validStackCreateOptions/with_valid_options (0.00s)
PASS
ok  	github.com/hashicorp/go-tfe	0.333s

Rollback Plan

Roll back to the previous version.

Changes to Security Controls

No.

@arybolovlev arybolovlev marked this pull request as ready for review February 19, 2026 12:42
@arybolovlev arybolovlev requested a review from a team as a code owner February 19, 2026 12:42
@datadog-terraform-cloud-hashicorp
Copy link

datadog-terraform-cloud-hashicorp bot commented Feb 19, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 090bd3c | Docs | Was this helpful? Give us feedback!

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.

1 participant