From bf711b129f133748e3caed1e712debe79adf3e4a Mon Sep 17 00:00:00 2001 From: Rajendra Baviskar Date: Fri, 26 May 2023 14:22:25 -0700 Subject: [PATCH 1/5] CI-8165: fixing github conn --- internal/service/platform/connector/github.go | 10 ++ .../service/platform/connector/github_test.go | 92 +++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/internal/service/platform/connector/github.go b/internal/service/platform/connector/github.go index 6882ccc32..b4e79e6c7 100644 --- a/internal/service/platform/connector/github.go +++ b/internal/service/platform/connector/github.go @@ -45,6 +45,11 @@ func ResourceConnectorGithub() *schema.Resource { Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "execute_on_delegate": { + Description: "Execute on delegate or not.", + Type: schema.TypeBool, + Optional: true, + }, "api_authentication": { Description: "Configuration for using the github api. API Access is required for using “Git Experience”, for creation of Git based triggers, Webhooks management and updating Git statuses.", Type: schema.TypeList, @@ -215,6 +220,10 @@ func buildConnectorGithub(d *schema.ResourceData) *nextgen.ConnectorInfo { connector.Github.Url = attr.(string) } + if attr, ok := d.GetOk("execute_on_delegate"); ok { + connector.Github.ExecuteOnDelegate = attr.(bool) + } + if attr, ok := d.GetOk("delegate_selectors"); ok { connector.Github.DelegateSelectors = utils.InterfaceSliceToStringSlice(attr.(*schema.Set).List()) } @@ -310,6 +319,7 @@ func readConnectorGithub(d *schema.ResourceData, connector *nextgen.ConnectorInf d.Set("url", connector.Github.Url) d.Set("connection_type", connector.Github.Type_.String()) d.Set("delegate_selectors", connector.Github.DelegateSelectors) + d.Set("execute_on_delegate", connector.Github.ExecuteOnDelegate) d.Set("validation_repo", connector.Github.ValidationRepo) if connector.Github.Authentication != nil { diff --git a/internal/service/platform/connector/github_test.go b/internal/service/platform/connector/github_test.go index c63bdfeff..77c591747 100644 --- a/internal/service/platform/connector/github_test.go +++ b/internal/service/platform/connector/github_test.go @@ -11,6 +11,58 @@ import ( "github.com/stretchr/testify/require" ) +func TestAccResourceConnectorGithub_HttpExecuteOnDelegateFalse(t *testing.T) { + + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) + name := id + updatedName := fmt.Sprintf("%s_updated", name) + resourceName := "harness_platform_connector_github.test" + + resource.UnitTest(t, resource.TestCase{ + PreCheck: func() { acctest.TestAccPreCheck(t) }, + ProviderFactories: acctest.ProviderFactories, + ExternalProviders: map[string]resource.ExternalProvider{ + "time": {}, + }, + CheckDestroy: testAccConnectorDestroy(resourceName), + Steps: []resource.TestStep{ + { + Config: testAccResourceConnectorGithub_httpExecuteOnDelegateFalse(id, name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", id), + resource.TestCheckResourceAttr(resourceName, "identifier", id), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(resourceName, "url", "https://github.com/account"), + resource.TestCheckResourceAttr(resourceName, "connection_type", "Account"), + resource.TestCheckResourceAttr(resourceName, "validation_repo", "some_repo"), + resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.username", "admin"), + resource.TestCheckResourceAttr(resourceName, "execute_on_delegate", "false"), + ), + }, + { + Config: testAccResourceConnectorGithub_httpExecuteOnDelegateFalse(id, updatedName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", id), + resource.TestCheckResourceAttr(resourceName, "identifier", id), + resource.TestCheckResourceAttr(resourceName, "name", updatedName), + resource.TestCheckResourceAttr(resourceName, "description", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.username", "admin"), + resource.TestCheckResourceAttr(resourceName, "execute_on_delegate", "false"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccResourceConnectorGithub_Http(t *testing.T) { id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) @@ -286,6 +338,46 @@ func TestAccResourceProject_DeleteUnderlyingResource(t *testing.T) { }) } +func testAccResourceConnectorGithub_httpExecuteOnDelegateFalse(id string, name string) string { + return fmt.Sprintf(` + resource "harness_platform_secret_text" "test" { + identifier = "%[1]s" + name = "%[2]s" + description = "test" + tags = ["foo:bar"] + + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "secret" + } + + resource "harness_platform_connector_github" "test" { + identifier = "%[1]s" + name = "%[2]s" + description = "test" + tags = ["foo:bar"] + + url = "https://github.com/account" + connection_type = "Account" + validation_repo = "some_repo" + delegate_selectors = ["harness-delegate"] + execute_on_delegate = false + credentials { + http { + username = "admin" + token_ref = "account.${harness_platform_secret_text.test.id}" + } + } + depends_on = [time_sleep.wait_4_seconds] + } + + resource "time_sleep" "wait_4_seconds" { + depends_on = [harness_platform_secret_text.test] + destroy_duration = "4s" + } +`, id, name) +} + func testAccResourceConnectorGithub_http(id string, name string) string { return fmt.Sprintf(` resource "harness_platform_secret_text" "test" { From 46b5c378fcaaafd627fe31b513576cbe707bca3d Mon Sep 17 00:00:00 2001 From: Rajendra Baviskar Date: Fri, 2 Jun 2023 13:42:59 -0700 Subject: [PATCH 2/5] CI-8165 adding tests --- .../service/platform/connector/github_test.go | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/internal/service/platform/connector/github_test.go b/internal/service/platform/connector/github_test.go index 77c591747..1cc539a09 100644 --- a/internal/service/platform/connector/github_test.go +++ b/internal/service/platform/connector/github_test.go @@ -63,6 +63,58 @@ func TestAccResourceConnectorGithub_HttpExecuteOnDelegateFalse(t *testing.T) { }) } +func TestAccResourceConnectorGithub_HttpExecuteOnDelegateTrue(t *testing.T) { + + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) + name := id + updatedName := fmt.Sprintf("%s_updated", name) + resourceName := "harness_platform_connector_github.test" + + resource.UnitTest(t, resource.TestCase{ + PreCheck: func() { acctest.TestAccPreCheck(t) }, + ProviderFactories: acctest.ProviderFactories, + ExternalProviders: map[string]resource.ExternalProvider{ + "time": {}, + }, + CheckDestroy: testAccConnectorDestroy(resourceName), + Steps: []resource.TestStep{ + { + Config: testAccResourceConnectorGithub_httpExecuteOnDelegateTrue(id, name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", id), + resource.TestCheckResourceAttr(resourceName, "identifier", id), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(resourceName, "url", "https://github.com/account"), + resource.TestCheckResourceAttr(resourceName, "connection_type", "Account"), + resource.TestCheckResourceAttr(resourceName, "validation_repo", "some_repo"), + resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.username", "admin"), + resource.TestCheckResourceAttr(resourceName, "execute_on_delegate", "true"), + ), + }, + { + Config: testAccResourceConnectorGithub_httpExecuteOnDelegateTrue(id, updatedName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "id", id), + resource.TestCheckResourceAttr(resourceName, "identifier", id), + resource.TestCheckResourceAttr(resourceName, "name", updatedName), + resource.TestCheckResourceAttr(resourceName, "description", "test"), + resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.http.0.username", "admin"), + resource.TestCheckResourceAttr(resourceName, "execute_on_delegate", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccResourceConnectorGithub_Http(t *testing.T) { id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) @@ -378,6 +430,46 @@ func testAccResourceConnectorGithub_httpExecuteOnDelegateFalse(id string, name s `, id, name) } +func testAccResourceConnectorGithub_httpExecuteOnDelegateTrue(id string, name string) string { + return fmt.Sprintf(` + resource "harness_platform_secret_text" "test" { + identifier = "%[1]s" + name = "%[2]s" + description = "test" + tags = ["foo:bar"] + + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "secret" + } + + resource "harness_platform_connector_github" "test" { + identifier = "%[1]s" + name = "%[2]s" + description = "test" + tags = ["foo:bar"] + + url = "https://github.com/account" + connection_type = "Account" + validation_repo = "some_repo" + delegate_selectors = ["harness-delegate"] + execute_on_delegate = true + credentials { + http { + username = "admin" + token_ref = "account.${harness_platform_secret_text.test.id}" + } + } + depends_on = [time_sleep.wait_4_seconds] + } + + resource "time_sleep" "wait_4_seconds" { + depends_on = [harness_platform_secret_text.test] + destroy_duration = "4s" + } +`, id, name) +} + func testAccResourceConnectorGithub_http(id string, name string) string { return fmt.Sprintf(` resource "harness_platform_secret_text" "test" { From 3ae9a6704ce05ac8d483ff6010a8eaacf66f8dc8 Mon Sep 17 00:00:00 2001 From: Rajendra Baviskar Date: Mon, 5 Jun 2023 14:31:04 -0700 Subject: [PATCH 3/5] adding change log --- .changelog/553.txt | 3 +++ docs/resources/platform_connector_github.md | 1 + 2 files changed, 4 insertions(+) create mode 100644 .changelog/553.txt diff --git a/.changelog/553.txt b/.changelog/553.txt new file mode 100644 index 000000000..a0a69ad5e --- /dev/null +++ b/.changelog/553.txt @@ -0,0 +1,3 @@ +```release-note:fix +resource/harness_platform_connector_github: adding support for execute_on_delegate. +``` diff --git a/docs/resources/platform_connector_github.md b/docs/resources/platform_connector_github.md index 16af6c4c1..c926d94cf 100644 --- a/docs/resources/platform_connector_github.md +++ b/docs/resources/platform_connector_github.md @@ -94,6 +94,7 @@ resource "harness_platform_connector_github" "test" { - `api_authentication` (Block List, Max: 1) Configuration for using the github api. API Access is required for using “Git Experience”, for creation of Git based triggers, Webhooks management and updating Git statuses. (see [below for nested schema](#nestedblock--api_authentication)) - `delegate_selectors` (Set of String) Tags to filter delegates for connection. - `description` (String) Description of the resource. +- `execute_on_delegate` (Boolean) Execute on delegate or not. - `org_id` (String) Unique identifier of the organization. - `project_id` (String) Unique identifier of the project. - `tags` (Set of String) Tags to associate with the resource. From 359eb48d5a821f3c461689bbe8673f5d42f253a7 Mon Sep 17 00:00:00 2001 From: Rajendra Baviskar Date: Tue, 6 Jun 2023 00:15:36 -0700 Subject: [PATCH 4/5] no message --- .changelog/567.txt | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .changelog/567.txt diff --git a/.changelog/567.txt b/.changelog/567.txt deleted file mode 100644 index 00e9d1e2a..000000000 --- a/.changelog/567.txt +++ /dev/null @@ -1,3 +0,0 @@ -```release-note:bug -resource/harness_platform_usergroup - ignore the order of users and user_emails when doing CRUD. -``` From 870fe629e633416f4113392c4e28938d8a52a3d7 Mon Sep 17 00:00:00 2001 From: Rajendra Baviskar Date: Wed, 7 Jun 2023 10:48:43 -0700 Subject: [PATCH 5/5] fixing data source --- internal/service/platform/connector/github.go | 1 + internal/service/platform/connector/github_data_source.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/internal/service/platform/connector/github.go b/internal/service/platform/connector/github.go index b4e79e6c7..2c0d1e97c 100644 --- a/internal/service/platform/connector/github.go +++ b/internal/service/platform/connector/github.go @@ -49,6 +49,7 @@ func ResourceConnectorGithub() *schema.Resource { Description: "Execute on delegate or not.", Type: schema.TypeBool, Optional: true, + Default: true, }, "api_authentication": { Description: "Configuration for using the github api. API Access is required for using “Git Experience”, for creation of Git based triggers, Webhooks management and updating Git statuses.", diff --git a/internal/service/platform/connector/github_data_source.go b/internal/service/platform/connector/github_data_source.go index 7995e5b8a..31913d3cc 100644 --- a/internal/service/platform/connector/github_data_source.go +++ b/internal/service/platform/connector/github_data_source.go @@ -36,6 +36,11 @@ func DatasourceConnectorGithub() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "execute_on_delegate": { + Description: "Execute on delegate or not.", + Type: schema.TypeBool, + Computed: true, + }, "api_authentication": { Description: "Configuration for using the github api. API Access is Computed for using “Git Experience”, for creation of Git based triggers, Webhooks management and updating Git statuses.", Type: schema.TypeList,