Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Scalr/epic/SCALRCORE-19846
SCALRCORE-19846 Publish Modules to preview API
- Loading branch information
Showing
12 changed files
with
393 additions
and
20 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
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,32 @@ | ||
--- | ||
layout: "scalr" | ||
page_title: "Scalr: scalr_module_version" | ||
sidebar_current: "docs-datasource-module-version-x" | ||
description: |- Get information on the module version. | ||
--- | ||
|
||
# scalr_module_version Data Source | ||
|
||
This data source is used to retrieve module version data by module source and semantic version. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "scalr_module_version" "example" { | ||
source = "env-xxxxxx/resource-name/scalr" | ||
version = "1.0.0" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `source` - (Required) The module source. | ||
* `version` - (Optional) The semantic version based on module version was created. | ||
|
||
## Attribute Reference | ||
|
||
All arguments plus: | ||
|
||
* `id` - The identifier of а module version. Example: `modver-xxxx` |
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
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,59 @@ | ||
--- | ||
layout: "scalr" | ||
page_title: "Scalr: scalr_module" | ||
sidebar_current: "docs-resource-scalr-module" | ||
description: |- | ||
Manages module. | ||
--- | ||
|
||
# scalr_module Resource | ||
|
||
Manages the state of a module in the Private Modules Registry. Create and destroy operations are available only. | ||
|
||
## Example Usage | ||
|
||
Basic usage: | ||
|
||
```hcl | ||
resource "scalr_module" "example" { | ||
account_id = "acc-xxxxxxxxx" | ||
environment_id = "env-xxxxxxxxx" | ||
vcs_provider_id = "vcs-xxxxxxxxx" | ||
vcs_repo { | ||
identifier = "org/repo" | ||
path = "example/terraform-<provider>-<name>" | ||
tag_prefix = "aws/" | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
* `vcs_provider_id` - (Required) The identifier of a VCS provider in the format `vcs-<RANDOM STRING>` | ||
* `account_id` - (Optional) The identifier of the account in the format `acc-<RANDOM STRING>`. If it is not specified the module will be registered globally and available across the whole installation. | ||
* `environment_id` - (Optional) The identifier of an environment in the format `env-<RANDOM STRING>`. If it is not specified the module will be registered at the account level and available across all environments within the account specified in `account_id` attribute. | ||
* `vcs_repo` - (Required) Source configuration of a VCS repository | ||
|
||
The `vcs_repo` block supports: | ||
|
||
* `identifier` - (Required) The identifier of a VCS repository in the format `:org/:repo` (`:org/:project/:name` is used for Azure DevOps). It refers to a organization and a repository name in a VCS provider. | ||
* `path` - (Optional) The path to the root module folder. It Is expected to have the format '<path>/terraform-<provider_name>-<module_name>', where `<path>` stands for any folder within the repository inclusively a repository root. | ||
* `tag_prefix` - (Optional) Registry ignores tags which do not match specified prefix, e.g. `aws/`. | ||
|
||
|
||
## Attribute Reference | ||
|
||
All arguments plus: | ||
|
||
* `id` - The identifier of a module in the format `mod--<RANDOM STRING>`. | ||
* `module_provider` - Module provider name, e.g `aws`, `azurerm`, `google`, etc. | ||
* `name` - Name of the module, e.g. `rds`, `compute`, `kubernetes-engine` | ||
|
||
* `source` - The source of a remote module in the private registry, e.g `env-xxxx/aws/vpc` | ||
|
||
## Import | ||
|
||
To import module use module ID as the import ID. For example: | ||
```shell | ||
terraform import scalr_module.example mod-tk4315k3lofu4i0 | ||
``` |
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
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
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
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,67 @@ | ||
package scalr | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
scalr "github.com/scalr/go-scalr" | ||
) | ||
|
||
func dataSourceModuleVersion() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceModuleVersionRead, | ||
Schema: map[string]*schema.Schema{ | ||
"source": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"version": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}} | ||
} | ||
|
||
func dataSourceModuleVersionRead(d *schema.ResourceData, meta interface{}) error { | ||
scalrClient := meta.(*scalr.Client) | ||
|
||
source := d.Get("source").(string) | ||
module, err := scalrClient.Modules.ReadBySource(ctx, source) | ||
if err != nil { | ||
if errors.Is(err, scalr.ErrResourceNotFound{}) { | ||
return fmt.Errorf("Could not find module with source %s", source) | ||
} | ||
return fmt.Errorf("Error retrieving module: %v", err) | ||
} | ||
log.Printf("[DEBUG] Download module by source: %s", source) | ||
|
||
var mv *scalr.ModuleVersion | ||
var version string | ||
if v, ok := d.GetOk("version"); ok { | ||
version = v.(string) | ||
mv, err = scalrClient.ModuleVersions.ReadBySemanticVersion(ctx, module.ID, version) | ||
} else { | ||
if module.LatestModuleVersion == nil { | ||
return errors.New("The module has no version tags") | ||
} | ||
mv, err = scalrClient.ModuleVersions.Read(ctx, module.LatestModuleVersion.ID) | ||
} | ||
|
||
if err != nil { | ||
if errors.Is(err, scalr.ErrResourceNotFound{}) { | ||
return fmt.Errorf("Could not find module with source %s and version %s", source, version) | ||
} | ||
return fmt.Errorf("Error retrieving module version: %v", err) | ||
} | ||
log.Printf("[DEBUG] Download module version by source %s version: %s", source, version) | ||
|
||
d.SetId(mv.ID) | ||
d.Set("version", mv.Version) | ||
return nil | ||
} |
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
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
Oops, something went wrong.