diff --git a/selectel/domains_v2.go b/selectel/domains_v2.go index c61446e8..a16a37be 100644 --- a/selectel/domains_v2.go +++ b/selectel/domains_v2.go @@ -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" @@ -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 +} diff --git a/selectel/provider.go b/selectel/provider.go index c1f5dfcd..4ad8912d 100644 --- a/selectel/provider.go +++ b/selectel/provider.go @@ -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(), @@ -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 diff --git a/selectel/resource_selectel_domains_rrset_v2.go b/selectel/resource_selectel_domains_rrset_v2.go index b705e703..b2762819 100644 --- a/selectel/resource_selectel_domains_rrset_v2.go +++ b/selectel/resource_selectel_domains_rrset_v2.go @@ -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, @@ -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 -} diff --git a/selectel/resource_selectel_domains_zone_v2.go b/selectel/resource_selectel_domains_zone_v2.go index a29d2c83..1473208b 100644 --- a/selectel/resource_selectel_domains_zone_v2.go +++ b/selectel/resource_selectel_domains_zone_v2.go @@ -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" @@ -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, @@ -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 -} diff --git a/website/docs/d/domains_domain_v1.html.markdown b/website/docs/d/domains_domain_v1.html.markdown index edcba2bf..19adbebb 100644 --- a/website/docs/d/domains_domain_v1.html.markdown +++ b/website/docs/d/domains_domain_v1.html.markdown @@ -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 diff --git a/website/docs/d/domains_rrset_v2.html.markdown b/website/docs/d/domains_rrset_v2.html.markdown new file mode 100644 index 00000000..ee46a559 --- /dev/null +++ b/website/docs/d/domains_rrset_v2.html.markdown @@ -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. diff --git a/website/docs/d/domains_zone_v2.html.markdown b/website/docs/d/domains_zone_v2.html.markdown new file mode 100644 index 00000000..f2f63d4b --- /dev/null +++ b/website/docs/d/domains_zone_v2.html.markdown @@ -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. diff --git a/website/docs/r/domains_domain_v1.html.markdown b/website/docs/r/domains_domain_v1.html.markdown index a9498fad..f01c961a 100644 --- a/website/docs/r/domains_domain_v1.html.markdown +++ b/website/docs/r/domains_domain_v1.html.markdown @@ -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 diff --git a/website/docs/r/domains_record_v1.html.markdown b/website/docs/r/domains_record_v1.html.markdown index 822bf577..9ce0d811 100644 --- a/website/docs/r/domains_record_v1.html.markdown +++ b/website/docs/r/domains_record_v1.html.markdown @@ -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 diff --git a/website/docs/r/domains_rrset_v2.html.markdown b/website/docs/r/domains_rrset_v2.html.markdown new file mode 100644 index 00000000..71d7edf5 --- /dev/null +++ b/website/docs/r/domains_rrset_v2.html.markdown @@ -0,0 +1,237 @@ +--- +layout: "selectel" +page_title: "Selectel: selectel_domains_rrset_v2" +sidebar_current: "docs-selectel-resource-domains-rrset-v2" +description: |- + Creates and manages a rrset in Selectel DNS Hosting using public API v2. +--- + +# selectel\_domains\_rrset\_v2 + +Creates and manages a rrset in DNS Hosting using public API v2. For more information about rrset, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/records/). + +## Example usage + +### A RRSet + +```hcl +resource "selectel_domains_rrset_v2" "a_rrset_1" { + zone_id = "zone_id" + name = "a.example.com." + type = "A" + ttl = 60 + records { + content = "127.0.0.1" + } + records { + content = "127.0.0.2" + disabled = true + } +} + +``` + +### AAAA RRSet + +```hcl +resource "selectel_domains_rrset_v2" "aaaa_rrset_1" { + zone_id = "zone_id" + name = "aaaa.example.com." + type = "AAAA" + ttl = 60 + records { + content = "2400:cb00:2049:1::a29f:1804" + } +} + +``` + +### TXT RRSet + +```hcl +resource "selectel_domains_rrset_v2" "txt_rrset_1" { + zone_id = "zone_id" + name = "txt.example.com." + type = "TXT" + ttl = 60 + records { + content = "\"hello, world!\"" + } +} +``` + +### CNAME RRSet + +```hcl +resource "selectel_domains_rrset_v2" "cname_rrset_1" { + zone_id = "zone_id" + name = "cname.example.com." + type = "CNAME" + ttl = 60 + records { + content = "origin.com." + } +} +``` + +### NS RRSet + +```hcl +resource "selectel_domains_rrset_v2" "ns_rrset_1" { + zone_id = "zone_id" + name = "example.com." + type = "NS" + ttl = 86400 + records { + content = "ns5.selectel.org" + } +} +``` + +### MX RRSet + +Content includes: "priority host" + +```hcl +resource "selectel_domains_rrset_v2" "mx_rrset_1" { + zone_id = "zone_id" + name = "mx.example.com." + type = "MX" + ttl = 60 + records { + content = "10 mail.example.org." + } +} +``` + +### SRV RRSet + +Content includes: "priority weight port target" + +```hcl +resource "selectel_domains_rrset_v2" "srv_rrset_1" { + zone_id = "zone_id" + name = "_sip._tcp.example.com." + type = "SRV" + ttl = 120 + records { + content = "10 20 30 mail.example.org." + } +} +``` + +### SSHFP RRSet + +Content includes: "algorithm fingerprint_type fingerprint" + +```hcl +resource "selectel_domains_rrset_v2" "sshfp_rrset_1" { + zone_id = "zone_id" + name = "sshfp.example.com." + type = "SSHFP" + ttl = 60 + records { + content = "1 1 7491973e5f8b39d5327cd4e08bc81b05f7710b49" + } +} +``` + +### ALIAS RRSet + +```hcl +resource "selectel_domains_rrset_v2" "alias_rrset_1" { + zone_id = "zone_id" + name = "example1.com." + type = "ALIAS" + ttl = 60 + records { + content = "example2.com." + } +} +``` + +### CAA RRSet + +Content includes: "flag tag value" + +```hcl +resource "selectel_domains_rrset_v2" "caa_rrset_1" { + zone_id = "zone_id" + name = "example.com." + type = "CAA" + ttl = 60 + records { + content = "128 issue \"letsencrypt.com.\"" + } +} +``` + +## Argument Reference + +* `zone_id` - (Required) Zone ID. + +* `name` - (Required) Name of the zone rrset. The name format depends on the rrset type, see the examples above. + +* `type` - (Required) Type of the rrset. + +* `ttl` - (Required) Time-to-live for the rrset in seconds. The available range is from 60 to 604800. + +* `records` - (Required) Set of records: + + * `content` - (Required) Value for record. + + * `disabled` - (Optional, default: false) Shows if record available or not. + +* `project_id` - (Optional) Selectel project ID. + +* `comment` - (Optional) Comment for rrset. + +## Attributes Reference + +* `zone_id` - Zone ID. + +* `name` - Name of the rrset. + +* `type` - Type of the rrset. + +* `ttl` - Time-to-live for the rrset in seconds. + +* `records` - Set of records: + + * `content` - Value for record. + + * `disabled` - Shows if record available or not. + +* `project_id` - Selectel project ID. + +* `comment` - Comment for rrset. + +* `managed_by` - Rrset owner. + +## Import + +You can import a rrset: + +```shell +export OS_DOMAIN_NAME= +export OS_USERNAME= +export OS_PASSWORD= +export SEL_PROJECT_ID= +terraform import selectel_domains_rrset_v2.rrset_1 // +``` + +where: + +* `` — Selectel account ID. The account ID is in the top right corner of the [Control panel](https://my.selectel.ru/). Learn more about [Registration](https://docs.selectel.ru/control-panel-actions/account/registration/). + +* `` — Name of the service user. To get the name, in the top right corner of the [Control panel](https://my.selectel.ru/profile/users_management/users?type=service), go to the account menu ⟶ **Profile and Settings** ⟶ **User management** ⟶ the **Service users** tab ⟶ copy the name of the required user. Learn more about [Service users](https://docs.selectel.ru/control-panel-actions/users-and-roles/user-types-and-roles/). + +* `` — Password of the service user. + +* `` — Selectel project ID. + +* `` — Zone name. + +* `` — Rrset name. + +* `` — Type of rrset. diff --git a/website/docs/r/domains_zone_v2.html.markdown b/website/docs/r/domains_zone_v2.html.markdown new file mode 100644 index 00000000..23fc28ce --- /dev/null +++ b/website/docs/r/domains_zone_v2.html.markdown @@ -0,0 +1,84 @@ +--- +layout: "selectel" +page_title: "Selectel: selectel_domains_zone_v2" +sidebar_current: "docs-selectel-resource-domains-zone-v2" +description: |- + Creates and manages a zone in Selectel DNS Hosting using public API v2. +--- + +# selectel\_domains\_zone\_v2 + +Creates and manages a zone in DNS Hosting using public API v2. For more information about zones, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/zones/). + +## Example usage + +```hcl +resource "selectel_domains_zone_v2" "zone_1" { + name = "example.com." +} +``` + +With specific project id. + +```hcl +resource "selectel_domains_zone_v2" "zone_1" { + name = "example.com." + project_id = "project_id" +} +``` + +## Argument Reference + +* `name` - (Required) Zone name. Changing this creates a new zone name. + +* `project_id` - (Optional) Selectel project id. Scope for creating zone. + +* `comment` - (Optional) Comment for zone. + +* `disabled` - (Optional) Set zone available or not. + +## Attributes Reference + +* `id` - Unique identifier of the zone. + +* `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. + +## Import + +You can import a zone: + +```shell +export OS_DOMAIN_NAME= +export OS_USERNAME= +export OS_PASSWORD= +export SEL_PROJECT_ID= +terraform import selectel_domains_zone_v2.zone_1 +``` + +where: + +* `` — Selectel account ID. The account ID is in the top right corner of the [Control panel](https://my.selectel.ru/). Learn more about [Registration](https://docs.selectel.ru/control-panel-actions/account/registration/). + +* `` — Name of the service user. To get the name, in the top right corner of the [Control panel](https://my.selectel.ru/profile/users_management/users?type=service), go to the account menu ⟶ **Profile and Settings** ⟶ **User management** ⟶ the **Service users** tab ⟶ copy the name of the required user. Learn more about [Service users](https://docs.selectel.ru/control-panel-actions/users-and-roles/user-types-and-roles/). + +* `` — Password of the service user. + +* `` — Selectel project ID. + +* `` — Zone name. diff --git a/website/selectel.erb b/website/selectel.erb index f6bb4f35..a45ce37a 100644 --- a/website/selectel.erb +++ b/website/selectel.erb @@ -16,6 +16,12 @@ > selectel_domains_domain_v1 + > + selectel_domains_zone_v2 + + > + selectel_domains_rrset_v2 + > selectel_dbaas_datastore_type_v1 @@ -94,6 +100,12 @@ > selectel_domains_record_v1 + > + selectel_domains_zone_v2 + + > + selectel_domains_rrset_v2 +