Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.23.0 release #347

Merged
merged 6 commits into from Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,10 +2,16 @@

All notable changes to this project will be documented in this file.

## Unreleased
## [v0.23.0](https://github.com/buildkite/terraform-provider-buildkite/compare/v0.22.0...v0.23.0)

### Added

- SUP-1305: Test Suite Team Resource addition[[PR #346](https://github.com/buildkite/terraform-provider-buildkite/pull/346)] @james2791
jradtilbrook marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

- Test Suite resource reads [replacing](https://github.com/buildkite/terraform-provider-buildkite/pull/346/commits/f4b911075bb58dc691896cfacef60f9b36032fb2) `team_owner_id` with `MANAGE_AND_READ` @james2791 @jradtilbrook
jradtilbrook marked this conversation as resolved.
Show resolved Hide resolved

## [v0.22.0](https://github.com/buildkite/terraform-provider-buildkite/compare/v0.21.2...v0.22.0)

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ terraform {
required_providers {
buildkite = {
source = "buildkite/buildkite"
version = "0.22.0"
version = "0.23.0"
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions buildkite/resource_test_suite.go
Expand Up @@ -132,15 +132,23 @@ func (ts *testSuiteResource) Read(ctx context.Context, req resource.ReadRequest,
teamToFind := state.TeamOwnerId.ValueString()
// Find either the team ID from the state (if set) or the first team linked with MANAGE_AND_READ
if suite, ok := graphqlResponse.Suite.(*getTestSuiteSuite); ok {
var found *getTestSuiteSuiteTeamsTeamSuiteConnectionEdgesTeamSuiteEdge
for _, teamSuite := range suite.Teams.Edges {
if teamSuite.Node.Team.Id == teamToFind {
found = &teamSuite
break
}
if teamSuite.Node.AccessLevel == SuiteAccessLevelsManageAndRead {
state.TeamOwnerId = types.StringValue(string(teamSuite.Node.Team.Id))
break
if teamSuite.Node.AccessLevel == SuiteAccessLevelsManageAndRead && found == nil {
found = &teamSuite
}
}
if found != nil {
state.TeamOwnerId = types.StringValue(string(found.Node.Team.Id))
} else {
// team from state doesnt exist
// and we didnt find another team with MANAGE_AND_READ
state.TeamOwnerId = types.StringUnknown()
}
}

if state.TeamOwnerId.IsUnknown() {
Expand Down
82 changes: 82 additions & 0 deletions buildkite/resource_test_suite_test.go
Expand Up @@ -112,6 +112,88 @@ func TestAcc_testSuiteUpdate(t *testing.T) {
})
}

func TestAcc_testSuiteTeamOwnerResolution(t *testing.T) {
t.Parallel()
var suite getTestSuiteSuite

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: protoV6ProviderFactories(),
CheckDestroy: testTestSuiteDestroy,
Steps: []resource.TestStep{
{
Config: `
resource "buildkite_team" "ateam" {
name = "a team"
default_team = false
privacy = "VISIBLE"
default_member_role = "MAINTAINER"
}
resource "buildkite_team" "bteam" {
name = "b team"
default_team = false
privacy = "VISIBLE"
default_member_role = "MAINTAINER"
}
resource "buildkite_test_suite" "suite" {
name = "test suite update"
default_branch = "main"
team_owner_id = resource.buildkite_team.bteam.id
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("buildkite_test_suite.suite", "id"),
resource.TestCheckResourceAttrSet("buildkite_test_suite.suite", "api_token"),
resource.TestCheckResourceAttr("buildkite_test_suite.suite", "default_branch", "main"),
resource.TestCheckResourceAttr("buildkite_test_suite.suite", "name", "test suite update"),
resource.TestCheckResourceAttrSet("buildkite_test_suite.suite", "team_owner_id"),
resource.TestCheckResourceAttrPair("buildkite_test_suite.suite", "team_owner_id", "buildkite_team.bteam", "id"),
checkTestSuiteExists("buildkite_test_suite.suite", &suite),
checkTestSuiteRemoteValue(&suite, "Name", "test suite update"),
checkTestSuiteRemoteValue(&suite, "DefaultBranch", "main"),
),
},
{
Config: `
resource "buildkite_team" "ateam" {
name = "a team"
default_team = false
privacy = "VISIBLE"
default_member_role = "MAINTAINER"
}
resource "buildkite_team" "bteam" {
name = "b team"
default_team = false
privacy = "VISIBLE"
default_member_role = "MAINTAINER"
}
resource "buildkite_test_suite" "suite" {
name = "test suite update"
default_branch = "main"
team_owner_id = resource.buildkite_team.bteam.id
}
resource "buildkite_test_suite_team" "team-a" {
test_suite_id = buildkite_test_suite.suite.id
team_id = buildkite_team.ateam.id
access_level = "MANAGE_AND_READ"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("buildkite_test_suite.suite", "id"),
resource.TestCheckResourceAttrSet("buildkite_test_suite.suite", "api_token"),
resource.TestCheckResourceAttr("buildkite_test_suite.suite", "default_branch", "main"),
resource.TestCheckResourceAttr("buildkite_test_suite.suite", "name", "test suite update"),
resource.TestCheckResourceAttrSet("buildkite_test_suite.suite", "team_owner_id"),
resource.TestCheckResourceAttrPair("buildkite_test_suite.suite", "team_owner_id", "buildkite_team.bteam", "id"),
checkTestSuiteExists("buildkite_test_suite.suite", &suite),
checkTestSuiteRemoteValue(&suite, "Name", "test suite update"),
checkTestSuiteRemoteValue(&suite, "DefaultBranch", "main"),
),
},
},
})
}

func checkTestSuiteRemoteValue(suite *getTestSuiteSuite, property, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if obj := reflect.ValueOf(*suite).FieldByName(property).String(); obj != value {
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Expand Up @@ -16,7 +16,7 @@ terraform {
required_providers {
buildkite = {
source = "buildkite/buildkite"
version = "0.22.0"
version = "0.23.0"
}
}
}
Expand Down