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/.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. -``` 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. diff --git a/internal/service/platform/connector/github.go b/internal/service/platform/connector/github.go index 6882ccc32..2c0d1e97c 100644 --- a/internal/service/platform/connector/github.go +++ b/internal/service/platform/connector/github.go @@ -45,6 +45,12 @@ 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, + 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.", Type: schema.TypeList, @@ -215,6 +221,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 +320,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_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, diff --git a/internal/service/platform/connector/github_test.go b/internal/service/platform/connector/github_test.go index c63bdfeff..1cc539a09 100644 --- a/internal/service/platform/connector/github_test.go +++ b/internal/service/platform/connector/github_test.go @@ -11,6 +11,110 @@ 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_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)) @@ -286,6 +390,86 @@ 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_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" {