This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ~ extend updating resources * ~ fix creating sftp storage keys * + data sources for storage s3 & sftp * + data sources for storage sftp key + tests + examples + docs
- Loading branch information
Showing
21 changed files
with
906 additions
and
77 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,47 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gcore_storage_s3 Data Source - terraform-provider-gcorelabs" | ||
subcategory: "" | ||
description: |- | ||
Represent s3 storage resource. https://storage.gcorelabs.com/storage/list | ||
--- | ||
|
||
# gcore_storage_s3 (Data Source) | ||
|
||
Represent s3 storage resource. https://storage.gcorelabs.com/storage/list | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
provider gcore { | ||
user_name = "test" | ||
password = "test" | ||
permanent_api_token="123$321" // https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens | ||
ignore_creds_auth_error=true // if you want to manage storage resource only and provide permanent_api_token without user_name & password | ||
gcore_platform = "https://api.gcdn.co" | ||
gcore_storage_api = "https://storage.gcorelabs.com/api" | ||
} | ||
data "gcore_storage_s3" "example_s3" { | ||
name = "example" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
- **name** (String) A name of new storage resource. | ||
- **storage_id** (Number) An id of new storage resource. | ||
|
||
### Read-Only | ||
|
||
- **client_id** (Number) An client id of new storage resource. | ||
- **generated_endpoint** (String) A s3 entry point for new storage resource. | ||
- **generated_http_endpoint** (String) A http s3 entry point for new storage resource. | ||
- **generated_s3_endpoint** (String) A s3 endpoint for new storage resource. | ||
- **location** (String) A location of new storage resource. One of (s-ed1, s-darz1, s-ws1) | ||
|
||
|
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,49 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gcore_storage_sftp Data Source - terraform-provider-gcorelabs" | ||
subcategory: "" | ||
description: |- | ||
Represent sftp storage resource. https://storage.gcorelabs.com/storage/list | ||
--- | ||
|
||
# gcore_storage_sftp (Data Source) | ||
|
||
Represent sftp storage resource. https://storage.gcorelabs.com/storage/list | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
provider gcore { | ||
user_name = "test" | ||
password = "test" | ||
permanent_api_token="123$321" // https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens | ||
ignore_creds_auth_error=true // if you want to manage storage resource only and provide permanent_api_token without user_name & password | ||
gcore_platform = "https://api.gcdn.co" | ||
gcore_storage_api = "https://storage.gcorelabs.com/api" | ||
} | ||
data "gcore_storage_sftp" "example_sftp" { | ||
name = "example" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
- **name** (String) A name of storage resource. | ||
- **storage_id** (Number) An id of storage resource. | ||
|
||
### Read-Only | ||
|
||
- **client_id** (Number) An client id of storage resource. | ||
- **generated_http_endpoint** (String) A http sftp entry point for new storage resource. | ||
- **generated_sftp_endpoint** (String) A ssh sftp entry point for new storage resource. | ||
- **http_expires_header_value** (String) A expires date of storage resource. | ||
- **http_servername_alias** (String) An alias of storage resource. | ||
- **location** (String) A location of new storage resource. One of (ams, sin, fra, mia) | ||
- **ssh_key_id** (List of Number) An ssh keys IDs to link with new sftp storage resource only. https://storage.gcorelabs.com/ssh-key/list | ||
|
||
|
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,45 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gcore_storage_sftp_key Data Source - terraform-provider-gcorelabs" | ||
subcategory: "" | ||
description: |- | ||
Represent storage key resource. https://storage.gcorelabs.com/ssh-key/list | ||
--- | ||
|
||
# gcore_storage_sftp_key (Data Source) | ||
|
||
Represent storage key resource. https://storage.gcorelabs.com/ssh-key/list | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
provider gcore { | ||
user_name = "test" | ||
password = "test" | ||
permanent_api_token="123$321" // https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens | ||
ignore_creds_auth_error=true // if you want to manage storage resource only and provide permanent_api_token without user_name & password | ||
gcore_platform = "https://api.gcdn.co" | ||
gcore_storage_api = "https://storage.gcorelabs.com/api" | ||
} | ||
data "gcore_storage_sftp_key" "example_key" { | ||
name = "example" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- **name** (String) A name of storage key resource. | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
|
||
### Read-Only | ||
|
||
- **key_id** (Number) An id of of storage key resource. | ||
|
||
|
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,12 @@ | ||
provider gcore { | ||
user_name = "test" | ||
password = "test" | ||
permanent_api_token="123$321" // https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens | ||
ignore_creds_auth_error=true // if you want to manage storage resource only and provide permanent_api_token without user_name & password | ||
gcore_platform = "https://api.gcdn.co" | ||
gcore_storage_api = "https://storage.gcorelabs.com/api" | ||
} | ||
|
||
data "gcore_storage_s3" "example_s3" { | ||
name = "example" | ||
} |
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,12 @@ | ||
provider gcore { | ||
user_name = "test" | ||
password = "test" | ||
permanent_api_token="123$321" // https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens | ||
ignore_creds_auth_error=true // if you want to manage storage resource only and provide permanent_api_token without user_name & password | ||
gcore_platform = "https://api.gcdn.co" | ||
gcore_storage_api = "https://storage.gcorelabs.com/api" | ||
} | ||
|
||
data "gcore_storage_sftp" "example_sftp" { | ||
name = "example" | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/data-sources/gcore_storage_sftp_key/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,12 @@ | ||
provider gcore { | ||
user_name = "test" | ||
password = "test" | ||
permanent_api_token="123$321" // https://support.gcorelabs.com/hc/en-us/articles/360018625617-API-tokens | ||
ignore_creds_auth_error=true // if you want to manage storage resource only and provide permanent_api_token without user_name & password | ||
gcore_platform = "https://api.gcdn.co" | ||
gcore_storage_api = "https://storage.gcorelabs.com/api" | ||
} | ||
|
||
data "gcore_storage_sftp_key" "example_key" { | ||
name = "example" | ||
} |
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 gcore | ||
|
||
import ( | ||
"github.com/hashicorp/go-cty/cty" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"regexp" | ||
) | ||
|
||
func dataSourceStorageS3() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
StorageSchemaId: { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
AtLeastOneOf: []string{ | ||
StorageSchemaId, | ||
StorageSchemaName, | ||
}, | ||
Description: "An id of new storage resource.", | ||
}, | ||
StorageSchemaClientId: { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "An client id of new storage resource.", | ||
}, | ||
StorageSchemaName: { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics { | ||
storageName := i.(string) | ||
if !regexp.MustCompile(`^[\w\-]+$`).MatchString(storageName) || len(storageName) > 255 { | ||
return diag.Errorf("storage name can't be empty and can have only letters, numbers, dashes and underscores, it also should be less than 256 symbols") | ||
} | ||
return nil | ||
}, | ||
AtLeastOneOf: []string{ | ||
StorageSchemaId, | ||
StorageSchemaName, | ||
}, | ||
Description: "A name of new storage resource.", | ||
}, | ||
StorageSchemaLocation: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A location of new storage resource. One of (s-ed1, s-darz1, s-ws1)", | ||
}, | ||
StorageSchemaGenerateHTTPEndpoint: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A http s3 entry point for new storage resource.", | ||
}, | ||
StorageSchemaGenerateS3Endpoint: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A s3 endpoint for new storage resource.", | ||
}, | ||
StorageSchemaGenerateEndpoint: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A s3 entry point for new storage resource.", | ||
}, | ||
}, | ||
ReadContext: resourceStorageS3Read, | ||
Description: "Represent s3 storage resource. https://storage.gcorelabs.com/storage/list", | ||
} | ||
} |
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,83 @@ | ||
package gcore | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/G-Core/gcorelabs-storage-sdk-go/swagger/client/storage" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestStorageS3DataSource(t *testing.T) { | ||
random := time.Now().Nanosecond() | ||
resourceName := fmt.Sprintf("gcore_storage_s3.terraformtest%d_s3", random) | ||
dataSourceName := fmt.Sprintf("data.gcore_storage_s3.terraformtest%d_s3_data", random) | ||
|
||
templateCreate := func() string { | ||
return fmt.Sprintf(` | ||
resource "gcore_storage_s3" "terraformtest%d_s3" { | ||
name = "terraformtest%d" | ||
location = "s-ed1" | ||
} | ||
`, random, random) | ||
} | ||
|
||
templateRead := func() string { | ||
return fmt.Sprintf(` | ||
data "gcore_storage_s3" "terraformtest%d_s3_data" { | ||
name = "terraformtest%d" | ||
} | ||
`, random, random) | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheckVars(t, GCORE_USERNAME_VAR, GCORE_PASSWORD_VAR, GCORE_STORAGE_URL_VAR) | ||
}, | ||
CheckDestroy: func(s *terraform.State) error { | ||
config := testAccProvider.Meta().(*Config) | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "gcore_storage_s3" { | ||
continue | ||
} | ||
opts := []func(opt *storage.StorageListHTTPV2Params){ | ||
func(opt *storage.StorageListHTTPV2Params) { opt.Context = ctx }, | ||
func(opt *storage.StorageListHTTPV2Params) { opt.ID = &rs.Primary.ID }, | ||
} | ||
storages, err := config.StorageClient.StoragesList(opts...) | ||
if err != nil { | ||
return fmt.Errorf("find storage: %w", err) | ||
} | ||
if len(storages) == 0 { | ||
return nil | ||
} | ||
if storages[0].ProvisioningStatus == "ok" { | ||
return fmt.Errorf("storage #%s wasn't deleted correctrly", rs.Primary.ID) | ||
} | ||
} | ||
return nil | ||
}, | ||
ProviderFactories: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: templateCreate(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckResourceExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, StorageSchemaLocation, "s-ed1"), | ||
), | ||
}, | ||
{ | ||
Config: templateRead(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckResourceExists(dataSourceName), | ||
resource.TestCheckResourceAttr(dataSourceName, StorageSchemaLocation, "s-ed1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.