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

chore!: Github Repository Feed migration #677

Merged
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
1 change: 0 additions & 1 deletion octopusdeploy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func Provider() *schema.Provider {
"octopusdeploy_deployment_process": resourceDeploymentProcess(),
"octopusdeploy_docker_container_registry": resourceDockerContainerRegistry(),
"octopusdeploy_dynamic_worker_pool": resourceDynamicWorkerPool(),
"octopusdeploy_github_repository_feed": resourceGitHubRepositoryFeed(),
"octopusdeploy_gcp_account": resourceGoogleCloudPlatformAccount(),
"octopusdeploy_kubernetes_agent_deployment_target": resourceKubernetesAgentDeploymentTarget(),
"octopusdeploy_kubernetes_cluster_deployment_target": resourceKubernetesClusterDeploymentTarget(),
Expand Down
104 changes: 0 additions & 104 deletions octopusdeploy/resource_github_repository_feed.go

This file was deleted.

1 change: 1 addition & 0 deletions octopusdeploy_framework/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func()
NewGitCredentialResource,
NewHelmFeedResource,
NewArtifactoryGenericFeedResource,
NewGitHubRepositoryFeedResource,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package octopusdeploy_framework

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestGitHubFeed_UpgradeFromSDK_ToPluginFramework(t *testing.T) {
// override the path to check for terraformrc file and test against the real 0.21.1 version
os.Setenv("TF_CLI_CONFIG_FILE=", "")

resource.Test(t, resource.TestCase{
CheckDestroy: testGitHubFeedDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"octopusdeploy": {
VersionConstraint: "0.21.1",
Source: "OctopusDeployLabs/octopusdeploy",
},
},
Config: gitHubconfig,
},
{
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Config: gitHubconfig,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
},
{
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Config: updatedGitHubConfig,
Check: resource.ComposeTestCheckFunc(
testGitHubFeedUpdated(t),
),
},
},
})
}

const gitHubconfig = `resource "octopusdeploy_github_repository_feed" "feed_github_repository_migration" {
name = "Test GitHub Feed"
feed_uri = "https://api.github.com"
username = "username"
password = "password"
download_attempts = 6
download_retry_backoff_seconds = 11
}`

const updatedGitHubConfig = `resource "octopusdeploy_github_repository_feed" "feed_github_repository_migration" {
name = "Updated Test GitHub Feed"
feed_uri = "https://api.github.com/updated"
username = "username_Updated"
password = "password_Updated"
download_attempts = 7
download_retry_backoff_seconds = 12
}`

func testGitHubFeedDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "octopusdeploy_github_repository_feed" {
continue
}

feed, err := octoClient.Feeds.GetByID(rs.Primary.ID)
if err == nil && feed != nil {
return fmt.Errorf("feed (%s) still exists", rs.Primary.ID)
}
}

return nil
}

func testGitHubFeedUpdated(t *testing.T) resource.TestCheckFunc {
return func(s *terraform.State) error {
feedId := s.RootModule().Resources["octopusdeploy_github_repository_feed"+".feed_github_repository_migration"].Primary.ID
feed, err := octoClient.Feeds.GetByID(feedId)
if err != nil {
return fmt.Errorf("Failed to retrieve feed by ID: %s", err)
}

githubRepositoryFeed := feed.(*feeds.GitHubRepositoryFeed)

assert.Equal(t, "Feeds-1001", githubRepositoryFeed.ID, "Feed ID did not match expected value")
assert.Equal(t, "Updated Test GitHub Feed", githubRepositoryFeed.Name, "Feed name did not match expected value")
assert.Equal(t, "username_Updated", githubRepositoryFeed.Username, "Feed username did not match expected value")
assert.Equal(t, true, githubRepositoryFeed.Password.HasValue, "Feed password should be set")
assert.Equal(t, "https://api.github.com/updated", githubRepositoryFeed.FeedURI, "Feed URI did not match expected value")
assert.Equal(t, 7, githubRepositoryFeed.DownloadAttempts, "Feed download attempts did not match expected value")
assert.Equal(t, 12, githubRepositoryFeed.DownloadRetryBackoffSeconds, "Feed download retry_backoff_seconds did not match expected value")

return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
)

func TestResource_UpgradeFromSDK_ToPluginFramework(t *testing.T) {
func TestMavenResource_UpgradeFromSDK_ToPluginFramework(t *testing.T) {
// override the path to check for terraformrc file and test against the real 0.21.1 version
os.Setenv("TF_CLI_CONFIG_FILE=", "")

Expand Down
Loading
Loading