generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [IAC-2624]: Add module registry to terraform provider (#1099)
- Loading branch information
1 parent
8d1dcbb
commit 7eb49ac
Showing
11 changed files
with
676 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
5 changes: 5 additions & 0 deletions
5
examples/data-sources/harness_platform_infra_module/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import harness_platform_infra_module.example <module_id> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
internal/service/platform/module_registry/data_source_infra_module.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
70 changes: 70 additions & 0 deletions
70
internal/service/platform/module_registry/data_source_infra_module_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.