Skip to content

Commit

Permalink
feat: [IAC-2624]: Add module registry to terraform provider (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
nassergonzalez authored Nov 12, 2024
1 parent 8d1dcbb commit 7eb49ac
Show file tree
Hide file tree
Showing 11 changed files with 676 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changelog/1099.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:new-resource
harness_platform_infra_module - added a new resource for iacm module registry
harness_platform_infra_module - added a new data source for iacm module registry
```
43 changes: 43 additions & 0 deletions docs/data-sources/platform_infra_module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_platform_infra_module Data Source - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Data source for retrieving modules from the module registry.
---

# harness_platform_infra_module (Data Source)

Data source for retrieving modules from the module registry.

## Example Usage

```terraform
data "harness_platform_infra_module" "test" {
identifier = "identifier"
name = "name"
system = "system"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (String) Identifier of the module
- `name` (String) Name of the module
- `system` (String) Provider of the module

### Optional

- `created` (Number) Timestamp when the module was created
- `description` (String) Description of the module
- `repository` (String) For account connectors, the repository where the module is stored
- `repository_branch` (String) Repository Branch in which the module should be accessed
- `repository_commit` (String) Repository Commit in which the module should be accessed
- `repository_connector` (String) Repository Connector is the reference to the connector for the repository
- `repository_path` (String) Repository Path is the path in which the module resides
- `repository_url` (String) URL where the module is stored
- `synced` (Number) Timestamp when the module was last synced
- `tags` (String) Tags associated with the module
50 changes: 50 additions & 0 deletions docs/resources/platform_infra_module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_platform_infra_module Resource - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Resource for managing Terraform/Tofu Modules.
---

# harness_platform_infra_module (Resource)

Resource for managing Terraform/Tofu Modules.

## Example Usage

```terraform
resource "harness_platform_infra_module" "example" {
description = "example"
name = "name"
system = "provider"
repository = "https://github.com/org/repo"
repository_branch = "main"
repository_path = "tf/aws/basic"
repository_connector = harness_platform_connector_github.test.id
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) Name of the module.
- `system` (String) Provider of the module.

### Optional

- `description` (String) Description of the module.
- `repository` (String) For account connectors, the repository where the module can be found
- `repository_branch` (String) Name of the branch to fetch the code from. This cannot be set if repository commit is set.
- `repository_commit` (String) Tag to fetch the code from. This cannot be set if repository branch is set.
- `repository_connector` (String) Reference to the connector to be used to fetch the code.
- `repository_path` (String) Path to the module within the repository.

## Import

Import is supported using the following syntax:

```shell
terraform import harness_platform_infra_module.example <org_id>/<module_id>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "harness_platform_infra_module" "test" {
identifier = "identifier"
name = "name"
system = "system"
}
1 change: 1 addition & 0 deletions examples/resources/harness_platform_infra_module/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import harness_platform_infra_module.example <module_id>
9 changes: 9 additions & 0 deletions examples/resources/harness_platform_infra_module/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "harness_platform_infra_module" "example" {
description = "example"
name = "name"
system = "provider"
repository = "https://github.com/org/repo"
repository_branch = "main"
repository_path = "tf/aws/basic"
repository_connector = harness_platform_connector_github.test.id
}
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"github.com/harness/terraform-provider-harness/internal/service/platform/module_registry"
cdng_service "github.com/harness/terraform-provider-harness/internal/service/cd_nextgen/service"
"github.com/harness/terraform-provider-harness/internal/service/platform/service_account"
"log"
Expand Down Expand Up @@ -294,6 +295,7 @@ func Provider(version string) func() *schema.Provider {
"harness_governance_rule": governance_rule.DatasourceRule(),
"harness_governance_rule_set": governance_rule_set.DatasourceRuleSet(),
"harness_cluster_orchestrator": cluster_orchestrator.DataSourceClusterOrchestrator(),
"harness_platform_infra_module": module_registry.DataSourceInfraModule(),
},
ResourcesMap: map[string]*schema.Resource{
"harness_platform_template": pipeline_template.ResourceTemplate(),
Expand Down Expand Up @@ -441,6 +443,7 @@ func Provider(version string) func() *schema.Provider {
"harness_governance_rule": governance_rule.ResourceRule(),
"harness_governance_rule_set": governance_rule_set.ResourceRuleSet(),
"harness_cluster_orchestrator": cluster_orchestrator.ResourceClusterOrchestrator(),
"harness_platform_infra_module": module_registry.ResourceInfraModule(),
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package module_registry

import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

func DataSourceInfraModule() *schema.Resource {
resource := &schema.Resource{
Description: "Data source for retrieving modules from the module registry.",
ReadContext: resourceInfraModuleRead,
Schema: map[string]*schema.Schema{
"id": {
Description: "Identifier of the module",
Type: schema.TypeString,
Required: true,
},
"description": {
Description: "Description of the module",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": {
Description: "Name of the module",
Type: schema.TypeString,
Required: true,
},
"system": {
Description: "Provider of the module",
Type: schema.TypeString,
Required: true,
},
"repository": {
Description: "For account connectors, the repository where the module is stored",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"repository_branch": {
Description: "Repository Branch in which the module should be accessed",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"repository_commit": {
Description: "Repository Commit in which the module should be accessed",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"repository_connector": {
Description: "Repository Connector is the reference to the connector for the repository",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"repository_path": {
Description: "Repository Path is the path in which the module resides",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"created": {
Description: "Timestamp when the module was created",
Type: schema.TypeInt,
Computed: true,
Optional: true,
},
"repository_url": {
Description: "URL where the module is stored",
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"synced": {
Description: "Timestamp when the module was last synced",
Type: schema.TypeInt,
Computed: true,
Optional: true,
},
"tags": {
Description: "Tags associated with the module",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
return resource
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package module_registry_test

import (
"fmt"
"github.com/harness/terraform-provider-harness/internal/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"strings"
"testing"
)

func TestAccDataSourceInfraModule(t *testing.T) {
name := strings.ToLower(t.Name())
system := strings.ToLower(t.Name())
resourceName := "harness_platform_infra_module.test"
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceInfraModule(name, system),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "system", system),
),
},
},
})
}

func testAccDataSourceInfraModule(name string, system 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"]
credentials {
http {
username = "admin"
token_ref = "account.${harness_platform_secret_text.test.id}"
}
}
}
resource "harness_platform_infra_module" "test" {
name = "%[1]s"
system = "%[2]s"
description = "description"
repository = "https://github.com/org/repo"
repository_branch = "main"
repository_path = "tf/aws/basic"
repository_connector = "account.${harness_platform_connector_github.test.id}"
}
`, name, system)
}
Loading

0 comments on commit 7eb49ac

Please sign in to comment.