Skip to content

Commit

Permalink
fix: [CDS-83586]: GitOps repository and org level import (#746)
Browse files Browse the repository at this point in the history
* fix: [CDS-83586]: GitOps repository and org level import

* changes to support org level entities

* moving the iam cluster test to different function

* updating the cluster test to use sa cluster
  • Loading branch information
manavjot-harness committed Nov 9, 2023
1 parent a218211 commit e96534e
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 158 deletions.
8 changes: 8 additions & 0 deletions helpers/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ var GitopsAgentResourceImporter = &schema.ResourceImporter{
return []*schema.ResourceData{d}, nil
}

if len(parts) == 3 { //Org level
d.Set("org_id", parts[0])
d.Set("agent_id", parts[1])
d.Set("identifier", parts[2])
d.SetId(parts[2])
return []*schema.ResourceData{d}, nil
}

if len(parts) == 4 { //Project level
d.Set("org_id", parts[0])
d.Set("project_id", parts[1])
Expand Down
10 changes: 10 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ func GitopsAgentProjectLevelResourceImportStateIdFunc(resourceName string) resou
}
}

func GitopsAgentOrgLevelResourceImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
primary := s.RootModule().Resources[resourceName].Primary
id := primary.ID
orgId := primary.Attributes["org_id"]
agentId := primary.Attributes["agent_id"]
return fmt.Sprintf("%s/%s/%s", orgId, agentId, id), nil
}
}

func GitopsAgentAccountLevelResourceImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
primary := s.RootModule().Resources[resourceName].Primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,50 +68,66 @@ func testAccDataSourceGitopsApplication(id string, accountId string, name string
type = "PreProduction"
}
resource "harness_platform_gitops_repository" "test" {
identifier = "%[1]s"
account_id = "%[2]s"
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
agent_id = "%[4]s"
repo {
repo = "https://github.com/harness-apps/hosted-gitops-example-apps"
name = "%[1]s"
insecure = true
connection_type = "HTTPS_ANONYMOUS"
}
upsert = true
}
resource "harness_platform_gitops_applications" "test" {
application {
metadata {
annotations = {}
labels = {
"harness.io/serviceRef" = harness_platform_service.test.id
"harness.io/envRef" = harness_platform_environment.test.id
}
name = "%[1]s"
}
spec {
sync_policy {
sync_options = [
"PrunePropagationPolicy=undefined",
"CreateNamespace=false",
"Validate=false",
"skipSchemaValidations=false",
"autoCreateNamespace=false",
"pruneLast=false",
"applyOutofSyncOnly=false",
"Replace=false",
"retry=false"
]
}
source {
target_revision = "master"
repo_url = "%[9]s"
path = "helm-guestbook"
}
destination {
namespace = "%[6]s"
server = "%[7]s"
}
}
}
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
account_id = "%[2]s"
identifier = "%[1]s"
name = "%[3]s"
cluster_id = "%[8]s"
repo_id = "%[10]s"
agent_id = "%[4]s"
depends_on = [harness_platform_gitops_repository.test]
application {
metadata {
annotations = {}
labels = {
"harness.io/serviceRef" = harness_platform_service.test.id
"harness.io/envRef" = harness_platform_environment.test.id
}
name = "%[1]s"
}
spec {
sync_policy {
sync_options = [
"PrunePropagationPolicy=undefined",
"CreateNamespace=false",
"Validate=false",
"skipSchemaValidations=false",
"autoCreateNamespace=false",
"pruneLast=false",
"applyOutofSyncOnly=false",
"Replace=false",
"retry=false"
]
}
source {
target_revision = "master"
repo_url = "%[9]s"
path = "helm-guestbook"
}
destination {
namespace = "%[6]s"
server = "%[7]s"
}
}
}
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
account_id = "%[2]s"
identifier = "%[1]s"
name = "%[3]s"
cluster_id = "%[8]s"
repo_id = "%[10]s"
agent_id = "%[4]s"
}
data "harness_platform_gitops_applications" "test"{
depends_on = [harness_platform_gitops_applications.test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,49 +160,66 @@ func testAccResourceGitopsApplicationHelm(id string, accountId string, name stri
type = "PreProduction"
}
resource "harness_platform_gitops_repository" "test" {
identifier = "%[1]s"
account_id = "%[2]s"
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
agent_id = "%[4]s"
repo {
repo = "https://github.com/harness-apps/hosted-gitops-example-apps"
name = "%[1]s"
insecure = true
connection_type = "HTTPS_ANONYMOUS"
}
upsert = true
}
resource "harness_platform_gitops_applications" "test" {
application {
metadata {
annotations = {}
labels = {
"harness.io/serviceRef" = harness_platform_service.test.id
"harness.io/envRef" = harness_platform_environment.test.id
}
name = "%[1]s"
}
spec {
sync_policy {
sync_options = [
"PrunePropagationPolicy=undefined",
"CreateNamespace=false",
"Validate=false",
"skipSchemaValidations=false",
"autoCreateNamespace=false",
"pruneLast=false",
"applyOutofSyncOnly=false",
"Replace=false",
"retry=false"
]
}
source {
target_revision = "master"
repo_url = "%[9]s"
path = "helm-guestbook"
}
destination {
namespace = "%[6]s"
server = "%[7]s"
}
}
}
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
account_id = "%[2]s"
identifier = "%[1]s"
cluster_id = "%[8]s"
repo_id = "%[10]s"
agent_id = "%[4]s"
depends_on = [harness_platform_gitops_repository.test]
application {
metadata {
annotations = {}
labels = {
"harness.io/serviceRef" = harness_platform_service.test.id
"harness.io/envRef" = harness_platform_environment.test.id
}
name = "%[1]s"
}
spec {
sync_policy {
sync_options = [
"PrunePropagationPolicy=undefined",
"CreateNamespace=false",
"Validate=false",
"skipSchemaValidations=false",
"autoCreateNamespace=false",
"pruneLast=false",
"applyOutofSyncOnly=false",
"Replace=false",
"retry=false"
]
}
source {
target_revision = "master"
repo_url = "%[9]s"
path = "helm-guestbook"
}
destination {
namespace = "%[6]s"
server = "%[7]s"
}
}
}
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
account_id = "%[2]s"
identifier = "%[1]s"
cluster_id = "%[8]s"
repo_id = "%[10]s"
agent_id = "%[4]s"
name = "%[3]s"
}
`, id, accountId, name, agentId, clusterName, namespace, clusterServer, clusterId, repo, repoId)
}
Expand Down Expand Up @@ -234,55 +251,71 @@ func testAccResourceGitopsApplicationKustomize(id string, accountId string, name
tags = ["foo:bar", "baz"]
type = "PreProduction"
}
resource "harness_platform_gitops_repository" "test" {
identifier = "%[1]s"
account_id = "%[2]s"
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
agent_id = "%[4]s"
repo {
repo = "https://github.com/harness-apps/hosted-gitops-example-apps"
name = "%[1]s"
insecure = true
connection_type = "HTTPS_ANONYMOUS"
}
upsert = true
}
resource "harness_platform_gitops_applications" "test" {
application {
metadata {
annotations = {}
labels = {
"harness.io/serviceRef" = harness_platform_service.test.id
"harness.io/envRef" = harness_platform_environment.test.id
depends_on = [harness_platform_gitops_repository.test]
application {
metadata {
annotations = {}
labels = {
"harness.io/serviceRef" = harness_platform_service.test.id
"harness.io/envRef" = harness_platform_environment.test.id
}
name = "%[1]s"
}
spec {
sync_policy {
sync_options = [
"PrunePropagationPolicy=undefined",
"CreateNamespace=false",
"Validate=false",
"skipSchemaValidations=false",
"autoCreateNamespace=false",
"pruneLast=false",
"applyOutofSyncOnly=false",
"Replace=false",
"retry=false"
]
}
source {
target_revision = "master"
repo_url = "%[9]s"
path = "kustomize-guestbook"
kustomize {
images = [
"gcr.io/heptio-images/ks-guestbook-demo:0.1"
]
}
name = "%[1]s"
}
spec {
sync_policy {
sync_options = [
"PrunePropagationPolicy=undefined",
"CreateNamespace=false",
"Validate=false",
"skipSchemaValidations=false",
"autoCreateNamespace=false",
"pruneLast=false",
"applyOutofSyncOnly=false",
"Replace=false",
"retry=false"
]
}
source {
target_revision = "master"
repo_url = "%[9]s"
path = "kustomize-guestbook"
kustomize {
images = [
"gcr.io/heptio-images/ks-guestbook-demo:0.1"
]
}
}
destination {
namespace = "%[6]s"
server = "%[7]s"
}
}
}
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
account_id = "%[2]s"
identifier = "%[1]s"
cluster_id = "%[8]s"
repo_id = "%[10]s"
agent_id = "%[4]s"
name = "%[3]s"
}
destination {
namespace = "%[6]s"
server = "%[7]s"
}
}
}
project_id = harness_platform_project.test.id
org_id = harness_platform_organization.test.id
account_id = "%[2]s"
identifier = "%[1]s"
cluster_id = "%[8]s"
repo_id = "%[10]s"
agent_id = "%[4]s"
name = "%[3]s"
}
`, id, accountId, name, agentId, clusterName, namespace, clusterServer, clusterId, repo, repoId)
}
Loading

0 comments on commit e96534e

Please sign in to comment.