8000 CDI-980: Add gcore_cdn_client data source by andrei-lukyanchyk · Pull Request #183 · G-Core/terraform-provider-gcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

CDI-980: Add gcore_cdn_client data source #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/data-sources/cdn_client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gcore_cdn_client Data Source - terraform-provider-gcore"
subcategory: ""
description: |-
Represent CDN account data
---

# gcore_cdn_client (Data Source)

Represent CDN account data

## Example Usage

```terraform
provider gcore {
permanent_api_token = "251$d3361.............1b35f26d8"
}

data "gcore_cdn_client" "my_account" {}
```

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

### Read-Only

- `cname` (String) Domain zone to which a CNAME record of your CDN resources should be pointed.
- `id` (Number) ID of your CDN account.
5 changes: 5 additions & 0 deletions examples/data-sources/gcore_cdn_client/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider gcore {
permanent_api_token = "251$d3361.............1b35f26d8"
}

data "gcore_cdn_client" "my_account" {}
49 changes: 49 additions & 0 deletions gcore/data_source_gcore_cdn_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gcore

import (
"context"
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataClient() *schema.Resource {
return &schema.Resource{
ReadContext: dataClientRead,
Description: "Represent CDN account data",
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Description: "ID of your CDN account.",
Computed: true,
},
"cname": {
Type: schema.TypeString,
Description: "Domain zone to which a CNAME record of your CDN resources should be pointed.",
Computed: true,
},
},
}
}

func dataClientRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Println("[DEBUG] Start reading client")

config := m.(*Config)
client := config.CDNClient

result, err := client.ClientsMe().Get(ctx)
if err != nil {
return diag.FromErr(err)
}

log.Printf("[DEBUG] Client received: %v", *result)

d.SetId(fmt.Sprintf("%d", result.ID))
d.Set("cname", result.Cname)

log.Println("[DEBUG] Finish reading client")
return nil
}
2 changes: 1 addition & 1 deletion gcore/data_source_gcore_cdn_preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ func dataPresetRead(ctx context.Context, d *schema.ResourceData, m interface{})

d.SetId(strconv.Itoa(result.ID))

log.Println("[DEBUG] Finish reading origin shielding locations")
log.Println("[DEBUG] Finish reading presets")
return nil
}
1 change: 1 addition & 0 deletions gcore/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func Provider() *schema.Provider {
"gcore_ddos_profile_template": dataSourceDDoSProfileTemplate(),
"gcore_cdn_shielding_location": dataOriginShieldingLocation(),
"gcore_cdn_preset": dataPreset(),
"gcore_cdn_client": dataClient(),
"gcore_inference_flavor": dataSourceInferenceFlavor(),
},
ConfigureContextFunc: providerConfigure,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/AlekSi/pointer v1.2.0
github.com/G-Core/gcore-dns-sdk-go v0.2.9
github.com/G-Core/gcore-storage-sdk-go v0.1.34
github.com/G-Core/gcorelabscdn-go v1.0.25
github.com/G-Core/gcorelabscdn-go v1.0.26
github.com/G-Core/gcorelabscloud-go v0.11.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/G-Core/gcore-storage-sdk-go v0.1.34 h1:0GPQfz1kA6mQi6fiisGsh0Um4H9PZe
github.com/G-Core/gcore-storage-sdk-go v0.1.34/go.mod h1:BUAEZZZJJt/+luRFunqziv3+JnbVMLbQXDWz9kV8Te8=
github.com/G-Core/gcorelabscdn-go v1.0.25 h1:OS2uTmth12GzWw2tLeUFh4n9TUOie+gmE0e2cdg0EYk=
github.com/G-Core/gcorelabscdn-go v1.0.25/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.26 h1:22SqETUw64s+It/op1T7y3ukEOU62CJOsUcsfSkhvZs=
github.com/G-Core/gcorelabscdn-go v1.0.26/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscloud-go v0.11.0 h1:JzlEp0Cgm3i4lQFJKhscDK76uWYH2pQNzZOwKtvrMUQ=
github.com/G-Core/gcorelabscloud-go v0.11.0/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
Expand Down
0