From db719e4c0a98a2beaeb64d92691d1a520efae66c Mon Sep 17 00:00:00 2001 From: Nelson Susanto Date: Wed, 9 Oct 2024 10:27:34 +1100 Subject: [PATCH] Remove users datasource in SDK --- octopusdeploy/data_source_users.go | 46 ----------------------- octopusdeploy/data_source_users_test.go | 50 ------------------------- 2 files changed, 96 deletions(-) delete mode 100644 octopusdeploy/data_source_users.go delete mode 100644 octopusdeploy/data_source_users_test.go diff --git a/octopusdeploy/data_source_users.go b/octopusdeploy/data_source_users.go deleted file mode 100644 index c541d86d7..000000000 --- a/octopusdeploy/data_source_users.go +++ /dev/null @@ -1,46 +0,0 @@ -package octopusdeploy - -import ( - "context" - "time" - - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/users" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func dataSourceUsers() *schema.Resource { - return &schema.Resource{ - Description: "Provides information about existing users.", - ReadContext: dataSourceUsersRead, - Schema: getUserDataSchema(), - } -} - -func dataSourceUsersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - query := users.UsersQuery{ - Filter: d.Get("filter").(string), - IDs: expandArray(d.Get("ids").([]interface{})), - Skip: d.Get("skip").(int), - Take: d.Get("take").(int), - } - - spaceID := d.Get("space_id").(string) - - client := meta.(*client.Client) - existingUsers, err := users.Get(client, spaceID, query) - if err != nil { - return diag.FromErr(err) - } - - flattenedUsers := []interface{}{} - for _, user := range existingUsers.Items { - flattenedUsers = append(flattenedUsers, flattenUser(user)) - } - - d.Set("users", flattenedUsers) - d.SetId("Users " + time.Now().UTC().String()) - - return nil -} diff --git a/octopusdeploy/data_source_users_test.go b/octopusdeploy/data_source_users_test.go deleted file mode 100644 index e022c30ce..000000000 --- a/octopusdeploy/data_source_users_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package octopusdeploy - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccDataSourceUsers(t *testing.T) { - localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha) - name := fmt.Sprintf("data.octopusdeploy_users.%s", localName) - username := "d" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ProtoV6ProviderFactories: ProtoV6ProviderFactories(), - Steps: []resource.TestStep{ - { - Config: testAccDataSourceUsersConfig(localName, username), - Check: resource.ComposeTestCheckFunc( - testAccCheckUsersDataSourceID(name), - resource.TestCheckResourceAttrSet(name, "users.#"), - )}, - }, - }) -} - -func testAccCheckUsersDataSourceID(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - all := s.RootModule().Resources - rs, ok := all[n] - if !ok { - return fmt.Errorf("cannot find Users data source: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("snapshot Users source ID not set") - } - return nil - } -} - -func testAccDataSourceUsersConfig(localName string, username string) string { - return fmt.Sprintf(`data "octopusdeploy_users" "%s" { - filter = "%s" - }`, localName, username) -}