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

CI-8165: fixing github conn #553

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/553.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:fix
resource/harness_platform_connector_github: adding support for execute_on_delegate.
```
3 changes: 0 additions & 3 deletions .changelog/567.txt

This file was deleted.

1 change: 1 addition & 0 deletions docs/resources/platform_connector_github.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions internal/service/platform/connector/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions internal/service/platform/connector/github_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
184 changes: 184 additions & 0 deletions internal/service/platform/connector/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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" {
Expand Down