Skip to content

Commit

Permalink
feat: Add util functions for endpoint formatting
Browse files Browse the repository at this point in the history
feat: Add documentation about object storage endpoint

feat: Add mapRegionWithEnv util func

docs: Add env configuration guide

feat: remove endpoint from docs

feat: Modify endpoint extracting func
  • Loading branch information
Geun-Oh committed Sep 10, 2024
1 parent 0d30a6f commit aa936e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
9 changes: 6 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ provider "ncloud" {

### Environment variables

You can provide your credentials via `NCLOUD_ACCESS_KEY` and `NCLOUD_SECRET_KEY`,
environment variables, representing your Ncloud Access Key and Secret Key, respectively.
`NCLOUD_REGION` is also used, if applicable:
* `NCLOUD_ACCESS_KEY` - (Required) Ncloud access key.
* `NCLOUD_SECRET_KEY` - (Required) Ncloud secret key.
* `NCLOUD_REGION` - (Required) Ncloud region.

~> **Note** `access_key`, `secret_key` : [Get authentication keys for your account](http://docs.ncloud.com/en/api_new/api_new-1-1.html#preparation)

If applicable
```hcl
terraform {
required_providers {
Expand Down
4 changes: 3 additions & 1 deletion internal/conn/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func NewS3Client(region string, api *ncloud.APIKey, site, endpointFromEnv string
return newClient
}

// API docs: https://api.ncloud-docs.com/docs/platform-region-getregionlist
// Common object storage docs; https://api.ncloud-docs.com/docs/storage-objectstorage
func genEndpointWithCode(region, site string) string {
var s3Endpoint string
switch site {
Expand All @@ -48,7 +50,7 @@ func genEndpointWithCode(region, site string) string {
case "fin":
s3Endpoint = fmt.Sprintf("https://%[1]s.object.fin-ncloudstorage.com", strings.ToLower(region))
default:
s3Endpoint = fmt.Sprintf("https://%[1]s.object.ncloudstorage.com", strings.ToLower(region))
s3Endpoint = fmt.Sprintf("https://%[1]s.object.ncloudstorage.com", strings.ToLower(region[:2]))
}

return s3Endpoint
Expand Down
10 changes: 2 additions & 8 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,8 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
Region: region.(string),
}

// Set endpoint
var obs_endpoint string

if endpoint, ok := getOrFromEnv(d, "obs_endpoint", "NCLOUD_OBS_ENDPOINT"); ok {
obs_endpoint = (endpoint).(string)
} else {
obs_endpoint = ""
}
// Set endpoint (only for debugging)
obs_endpoint := os.Getenv("NCLOUD_OBS_ENDPOINT")

if client, err := config.Client(providerConfig.Site, obs_endpoint); err != nil {
return nil, diag.FromErr(err)
Expand Down

0 comments on commit aa936e5

Please sign in to comment.