Skip to content

Commit

Permalink
Added docs. Added ForceNew for not editable fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchudik authored Feb 1, 2024
1 parent 6629170 commit 08378f2
Show file tree
Hide file tree
Showing 12 changed files with 527 additions and 64 deletions.
58 changes: 58 additions & 0 deletions selectel/domains_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"regexp"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
domainsV2 "github.com/selectel/domains-go/pkg/v2"
Expand Down Expand Up @@ -110,3 +112,59 @@ func getRrsetByNameAndType(ctx context.Context, client domainsV2.DNSClient[domai

return nil, errGettingObject(objectRrset, fmt.Sprintf("Name: %s. Type: %s.", rrsetName, rrsetType), ErrRrsetNotFound)
}

func setZoneToResourceData(d *schema.ResourceData, zone *domainsV2.Zone) error {
d.SetId(zone.ID)
d.Set("name", zone.Name)
d.Set("comment", zone.Comment)
d.Set("created_at", zone.CreatedAt.Format(time.RFC3339))
d.Set("updated_at", zone.UpdatedAt.Format(time.RFC3339))
d.Set("delegation_checked_at", zone.DelegationCheckedAt.Format(time.RFC3339))
d.Set("last_check_status", zone.LastCheckStatus)
d.Set("last_delegated_at", zone.LastDelegatedAt.Format(time.RFC3339))
d.Set("project_id", strings.ReplaceAll(zone.ProjectID, "-", ""))
d.Set("disabled", zone.Disabled)

return nil
}

func setRrsetToResourceData(d *schema.ResourceData, rrset *domainsV2.RRSet) error {
d.SetId(rrset.ID)
d.Set("name", rrset.Name)
d.Set("comment", rrset.Comment)
d.Set("managed_by", rrset.ManagedBy)
d.Set("ttl", rrset.TTL)
d.Set("type", rrset.Type)
d.Set("zone_id", rrset.ZoneID)
d.Set("records", generateSetFromRecords(rrset.Records))

return nil
}

// generateSetFromRecords - generate terraform TypeList from records in rrset.
func generateSetFromRecords(records []domainsV2.RecordItem) []interface{} {
recordsAsList := []interface{}{}
for _, record := range records {
recordsAsList = append(recordsAsList, map[string]interface{}{
"content": record.Content,
"disabled": record.Disabled,
})
}

return recordsAsList
}

// generateRecordsFromSet - generate records for Rrset from terraform TypeList.
func generateRecordsFromSet(recordsSet *schema.Set) []domainsV2.RecordItem {
records := []domainsV2.RecordItem{}
for _, recordItem := range recordsSet.List() {
if record, isOk := recordItem.(map[string]interface{}); isOk {
records = append(records, domainsV2.RecordItem{
Content: record["content"].(string),
Disabled: record["disabled"].(bool),
})
}
}

return records
}
6 changes: 3 additions & 3 deletions selectel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Provider() *schema.Provider {
},
},
DataSourcesMap: map[string]*schema.Resource{
"selectel_domains_domain_v1": dataSourceDomainsDomainV1(),
"selectel_domains_domain_v1": dataSourceDomainsDomainV1(), // DEPRECATED
"selectel_domains_zone_v2": dataSourceDomainsZoneV2(),
"selectel_domains_rrset_v2": dataSourceDomainsRrsetV2(),
"selectel_dbaas_datastore_type_v1": dataSourceDBaaSDatastoreTypeV1(),
Expand All @@ -125,8 +125,8 @@ func Provider() *schema.Provider {
"selectel_vpc_crossregion_subnet_v2": resourceVPCCrossRegionSubnetV2(), // DEPRECATED
"selectel_mks_cluster_v1": resourceMKSClusterV1(),
"selectel_mks_nodegroup_v1": resourceMKSNodegroupV1(),
"selectel_domains_domain_v1": resourceDomainsDomainV1(),
"selectel_domains_record_v1": resourceDomainsRecordV1(),
"selectel_domains_domain_v1": resourceDomainsDomainV1(), // DEPRECATED
"selectel_domains_record_v1": resourceDomainsRecordV1(), // DEPRECATED
"selectel_domains_zone_v2": resourceDomainsZoneV2(),
"selectel_domains_rrset_v2": resourceDomainsRrsetV2(),
"selectel_dbaas_datastore_v1": resourceDBaaSDatastoreV1(), // DEPRECATED
Expand Down
45 changes: 4 additions & 41 deletions selectel/resource_selectel_domains_rrset_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ func resourceDomainsRrsetV2() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"zone_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"comment": {
Type: schema.TypeString,
Expand Down Expand Up @@ -229,44 +233,3 @@ func resourceDomainsRrsetV2Delete(ctx context.Context, d *schema.ResourceData, m

return nil
}

func setRrsetToResourceData(d *schema.ResourceData, rrset *domainsV2.RRSet) error {
d.SetId(rrset.ID)
d.Set("name", rrset.Name)
d.Set("comment", rrset.Comment)
d.Set("managed_by", rrset.ManagedBy)
d.Set("ttl", rrset.TTL)
d.Set("type", rrset.Type)
d.Set("zone_id", rrset.ZoneID)
d.Set("records", generateSetFromRecords(rrset.Records))

return nil
}

// generateSetFromRecords - generate terraform TypeList from records in rrset.
func generateSetFromRecords(records []domainsV2.RecordItem) []interface{} {
recordsAsList := []interface{}{}
for _, record := range records {
recordsAsList = append(recordsAsList, map[string]interface{}{
"content": record.Content,
"disabled": record.Disabled,
})
}

return recordsAsList
}

// generateRecordsFromSet - generate records for Rrset from terraform TypeList.
func generateRecordsFromSet(recordsSet *schema.Set) []domainsV2.RecordItem {
records := []domainsV2.RecordItem{}
for _, recordItem := range recordsSet.List() {
if record, isOk := recordItem.(map[string]interface{}); isOk {
records = append(records, domainsV2.RecordItem{
Content: record["content"].(string),
Disabled: record["disabled"].(bool),
})
}
}

return records
}
19 changes: 2 additions & 17 deletions selectel/resource_selectel_domains_zone_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package selectel
import (
"context"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -24,11 +22,13 @@ func resourceDomainsZoneV2() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"project_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"comment": {
Type: schema.TypeString,
Expand Down Expand Up @@ -206,18 +206,3 @@ func resourceDomainsZoneV2Delete(ctx context.Context, d *schema.ResourceData, me

return nil
}

func setZoneToResourceData(d *schema.ResourceData, zone *domainsV2.Zone) error {
d.SetId(zone.ID)
d.Set("name", zone.Name)
d.Set("comment", zone.Comment)
d.Set("created_at", zone.CreatedAt.Format(time.RFC3339))
d.Set("updated_at", zone.UpdatedAt.Format(time.RFC3339))
d.Set("delegation_checked_at", zone.DelegationCheckedAt.Format(time.RFC3339))
d.Set("last_check_status", zone.LastCheckStatus)
d.Set("last_delegated_at", zone.LastDelegatedAt.Format(time.RFC3339))
d.Set("project_id", strings.ReplaceAll(zone.ProjectID, "-", ""))
d.Set("disabled", zone.Disabled)

return nil
}
4 changes: 3 additions & 1 deletion website/docs/d/domains_domain_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description: |-

# selectel\_domains\_domain_v1

Provides an ID of a domain in DNS Hosting. For more information about domains in DNS Hosting, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/domains/).
~> **Note:** This is deprecated datasource. Using the `selectel_domains_zone_v2` datasource. They utilize different API and created zones live on different authoritative servers. Zone created in v2 API is entirely new zone, and not available via v1 api and vice versa.

Provides an ID of a domain in DNS Hosting. For more information about domains in DNS Hosting, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/zones/).

## Example Usage

Expand Down
64 changes: 64 additions & 0 deletions website/docs/d/domains_rrset_v2.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
layout: "selectel"
page_title: "Selectel: selectel_domains_rrset_v2"
sidebar_current: "docs-selectel-datasource-domains-rrset-v2"
description: |-
Provides a rrset info in Selectel DNS Hosting using public API v2.
---

# selectel\_domains\_rrset_v2

Provides a rrset info in DNS Hosting. For more information about rrset in DNS Hosting, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/records/).

## Example Usage

```hcl
data "selectel_domains_rrset_v2" "rrset_1" {
name = "example.com."
type = "A"
zone_id = "zone_id"
}
```

With specific project id.

```hcl
data "selectel_domains_rrset_v2" "rrset_1" {
name = "example.com."
type = "A"
zone_id = "zone_id"
ptoject_id = "project_id"
}
```

## Argument Reference

* `name` - (Required) Rrset name.

* `type` - (Required) Rrset type.

* `zone_id` - (Required) Zone ID.

* `project_id` - (Optional) Selectel project ID.

## Attributes Reference

* `name` - Rrset name.

* `type` - Rrset type.

* `zone_id` - Zone ID.

* `project_id` - Selectel project ID.

* `ttl` - Rrset TTL.

* `comment` - Comment for rrset.

* `managed_by` - Rrset owner.

* `records` - Set of records:

* `content` - Value for record.

* `disabled` - Shows if record available or not.
54 changes: 54 additions & 0 deletions website/docs/d/domains_zone_v2.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
layout: "selectel"
page_title: "Selectel: selectel_domains_zone_v2"
sidebar_current: "docs-selectel-datasource-domains-zone-v2"
description: |-
Provides a zone info in Selectel DNS Hosting using public API v2.
---

# selectel\_domains\_zone_v2

Provides a zone info in DNS Hosting (API v2). For more information about zones in DNS Hosting, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/zones/).

## Example Usage

```hcl
data "selectel_domains_zone_v2" "zone_1" {
name = "example.com."
}
```

With specific project id.

```hcl
data "selectel_domains_zone_v2" "zone_1" {
name = "example.com."
project_id = "project_id"
}
```

## Argument Reference

* `name` - (Required) Zone name.

* `project_id` - (Optional) Selectel project ID.

## Attributes Reference

* `name` - Zone name.

* `project_id` - Selectel project id.

* `comment` - Comment for zone.

* `created_at` - Timestamp when zone was created.

* `updated_at` - Timestamp when zone was updated.

* `delegation_checked_at` - Timestamp of last delegation status check.

* `last_check_status` - Shows if zone delegated to selectel NS servers or not.

* `last_delegated_at` - Timestamp of last delegation status check when zone was delegated to selectel NS server.

* `disabled` - Shows if zone available or not.
4 changes: 3 additions & 1 deletion website/docs/r/domains_domain_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description: |-

# selectel\_domains\_domain\_v1

Creates and manages a domain in DNS Hosting using public API v1. For more information about domains, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/domains/).
~> **Note:** This is deprecated resource. Using the `selectel_domains_zone_v2` resource. They utilize different API and created zones live on different authoritative servers. Zone created in v2 API is entirely new zone, and not available via v1 api and vice versa.

Creates and manages a domain in DNS Hosting using public API v1. For more information about domains, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/zones/).

## Example usage

Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/domains_record_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description: |-

# selectel\_domains\_record\_v1

Creates and manages a record in DNS Hosting using public API v1. For more information about records, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/records/add-record/).
~> **Note:** This is deprecated resource. Using the `selectel_domains_rrset_v2` resource. They are not compatible. They utilize different API and created records live on different authoritative servers. Zone created in v2 API is entirely new zone, and not available via v1 api and vice versa.

Creates and manages a record in DNS Hosting using public API v1. For more information about records, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/records/).

## Example usage

Expand Down
Loading

0 comments on commit 08378f2

Please sign in to comment.