Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Feature/storage (#31)
Browse files Browse the repository at this point in the history
storage resource added
  • Loading branch information
0ndi authored May 24, 2021
1 parent e9155be commit 2c973d0
Show file tree
Hide file tree
Showing 16 changed files with 1,067 additions and 27 deletions.
4 changes: 4 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ vet:
exit 1; \
fi

doc-generate:
go install -mod=mod github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
tfplugindocs

fmt:
gofmt -w $(GOFMT_FILES)

Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,6 @@ resource "gcore_lbmember" "lbm2" {
- **gcore_cdn_api** (String) CDN API
- **gcore_client_id** (String) Client id
- **gcore_platform** (String) Platform ulr is used for generate jwt
- **gcore_storage_api** (String) Storage API
- **password** (String)
- **user_name** (String)
51 changes: 51 additions & 0 deletions docs/resources/gcore_storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gcore_storage Resource - terraform-provider-gcorelabs"
subcategory: ""
description: |-
Represent storage resource.
---

# gcore_storage (Resource)

Represent storage resource.

## Example Usage

```terraform
provider gcore {
user_name = "test"
password = "test"
gcore_platform = "https://api.gcdn.co"
gcore_storage_api = "https://storage.gcorelabs.com/api"
}
resource "gcore_storage" "tf_example_s3" {
name = "tf_example"
location = "s-ed1"
type = "s3"
link_key_id = 199
}
```

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

### Required

- **location** (String) A location of new storage resource. One of (s-ed1, s-darz1, s-ws1, ams, sin, fra, mia)
- **name** (String) A name of new storage resource.
- **type** (String) A type of new storage resource. One of (sftp, s3)

### Optional

- **client_id** (Number) An client id of new storage resource.
- **expires** (String) A expires date of storage resource.
- **generate_sftp_password** (Boolean) An auto generated sftp password for new storage resource.
- **id** (String) The ID of this resource.
- **link_key_id** (Number) An key id to link with new storage resource.
- **server_alias** (String) An alias of storage resource.
- **sftp_password** (String) A sftp password for new storage resource.
- **storage_id** (Number) An id of new storage resource.


42 changes: 42 additions & 0 deletions docs/resources/gcore_storage_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gcore_storage_key Resource - terraform-provider-gcorelabs"
subcategory: ""
description: |-
Represent storage key resource.
---

# gcore_storage_key (Resource)

Represent storage key resource.

## Example Usage

```terraform
provider gcore {
user_name = "test"
password = "test"
gcore_platform = "https://api.gcdn.co"
gcore_storage_api = "https://storage.gcorelabs.com/api"
}
resource "gcore_storage_key" "terraform_test_key" {
name = "terraform_test_key"
key = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+M7Q== [email protected]"
}
```

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

### Required

- **key** (String) A body of of new storage key resource.
- **name** (String) A name of new storage key resource.

### Optional

- **id** (String) The ID of this resource.
- **key_id** (Number) An id of of new storage key resource.


13 changes: 13 additions & 0 deletions examples/resources/gcore_storage/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
provider gcore {
user_name = "test"
password = "test"
gcore_platform = "https://api.gcdn.co"
gcore_storage_api = "https://storage.gcorelabs.com/api"
}

resource "gcore_storage" "tf_example_s3" {
name = "tf_example"
location = "s-ed1"
type = "s3"
link_key_id = 199
}
11 changes: 11 additions & 0 deletions examples/resources/gcore_storage_key/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
provider gcore {
user_name = "test"
password = "test"
gcore_platform = "https://api.gcdn.co"
gcore_storage_api = "https://storage.gcorelabs.com/api"
}

resource "gcore_storage_key" "terraform_test_key" {
name = "terraform_test_key"
key = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+M7Q== [email protected]"
}
21 changes: 19 additions & 2 deletions gcore/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package gcore

import (
"context"
"fmt"
"net/http"

storageSDK "github.com/G-Core/gcorelabs-storage-sdk-go"
gcdn "github.com/G-Core/gcorelabscdn-go"
gcdnProvider "github.com/G-Core/gcorelabscdn-go/gcore/provider"
gcorecloud "github.com/G-Core/gcorelabscloud-go"
Expand Down Expand Up @@ -43,6 +45,12 @@ func Provider() *schema.Provider {
Description: "CDN API",
DefaultFunc: schema.EnvDefaultFunc("GCORE_CDN_API", ""),
},
"gcore_storage_api": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Storage API",
DefaultFunc: schema.EnvDefaultFunc("GCORE_STORAGE_API", ""),
},
"gcore_client_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand All @@ -67,6 +75,8 @@ func Provider() *schema.Provider {
"gcore_baremetal": resourceBmInstance(),
"gcore_snapshot": resourceSnapshot(),
"gcore_servergroup": resourceServerGroup(),
"gcore_storage": resourceStorage(),
"gcore_storage_key": resourceStorageKey(),
"gcore_cdn_resource": resourceCDNResource(),
"gcore_cdn_origingroup": resourceCDNOriginGroup(),
"gcore_cdn_rule": resourceCDNRule(),
Expand Down Expand Up @@ -98,6 +108,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
password := d.Get("password").(string)
api := d.Get("gcore_api").(string)
cdnAPI := d.Get("gcore_cdn_api").(string)
storageAPI := d.Get("gcore_storage_api").(string)
platform := d.Get("gcore_platform").(string)
clientID := d.Get("gcore_client_id").(string)

Expand All @@ -121,9 +132,15 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
}))
cdnService := gcdn.NewService(cdnProvider)

stHost, stPath, err := ExtractHosAndPath(storageAPI)
if err != nil {
return nil, diag.FromErr(fmt.Errorf("storage api url: %w", err))
}

config := Config{
Provider: provider,
CDNClient: cdnService,
Provider: provider,
CDNClient: cdnService,
StorageClient: storageSDK.NewSDK(stHost, stPath, storageSDK.WithBearerAuth(provider.AccessToken)),
}

return &config, diags
Expand Down
3 changes: 3 additions & 0 deletions gcore/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
GCORE_USERNAME_VAR VarName = "GCORE_USERNAME"
GCORE_PASSWORD_VAR VarName = "GCORE_PASSWORD"
GCORE_CDN_URL_VAR VarName = "GCORE_CDN_URL"
GCORE_STORAGE_URL_VAR VarName = "GCORE_STORAGE_API"
GCORE_IMAGE_VAR VarName = "GCORE_IMAGE"
GCORE_SECGROUP_VAR VarName = "GCORE_SECGROUP"
GCORE_EXT_NET_VAR VarName = "GCORE_EXT_NET"
Expand Down Expand Up @@ -56,6 +57,7 @@ var (
GCORE_VOLUME_ID = getEnv(GCORE_VOLUME_ID_VAR)
GCORE_CDN_ORIGINGROUP_ID = getEnv(GCORE_CDN_ORIGINGROUP_ID_VAR)
GCORE_CDN_RESOURCE_ID = getEnv(GCORE_CDN_RESOURCE_ID_VAR)
GCORE_STORAGE_API = getEnv(GCORE_STORAGE_URL_VAR)
)

var varsMap = map[VarName]string{
Expand All @@ -73,6 +75,7 @@ var varsMap = map[VarName]string{
GCORE_VOLUME_ID_VAR: GCORE_VOLUME_ID,
GCORE_CDN_ORIGINGROUP_ID_VAR: GCORE_CDN_ORIGINGROUP_ID,
GCORE_CDN_RESOURCE_ID_VAR: GCORE_CDN_RESOURCE_ID,
GCORE_STORAGE_URL_VAR: GCORE_STORAGE_API,
}

func testAccPreCheckVars(t *testing.T, vars ...VarName) {
Expand Down
Loading

0 comments on commit 2c973d0

Please sign in to comment.