From ff070022e61a5a06201c3e4375e71f98b6b7d1d7 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Tue, 23 Jan 2024 21:28:00 +0300 Subject: [PATCH 01/16] Added entities for work with DNS v2 API. --- .../data_source_selectel_domains_rrset_v2.go | 90 ++++++ ...a_source_selectel_domains_rrset_v2_test.go | 68 +++++ .../data_source_selectel_domains_zone_v2.go | 82 ++++++ ...ta_source_selectel_domains_zone_v2_test.go | 68 +++++ selectel/domains_v2.go | 99 +++++++ selectel/domains_v2_test.go | 138 +++++++++ .../import_selectel_domains_rrset_v2_test.go | 60 ++++ .../import_selectel_domains_zone_v2_test.go | 31 ++ selectel/messages.go | 4 + selectel/provider.go | 6 + selectel/provider_test.go | 7 + .../resource_selectel_domains_rrset_v2.go | 266 ++++++++++++++++++ ...resource_selectel_domains_rrset_v2_test.go | 98 +++++++ selectel/resource_selectel_domains_zone_v2.go | 198 +++++++++++++ .../resource_selectel_domains_zone_v2_test.go | 63 +++++ 15 files changed, 1278 insertions(+) create mode 100644 selectel/data_source_selectel_domains_rrset_v2.go create mode 100644 selectel/data_source_selectel_domains_rrset_v2_test.go create mode 100644 selectel/data_source_selectel_domains_zone_v2.go create mode 100644 selectel/data_source_selectel_domains_zone_v2_test.go create mode 100644 selectel/domains_v2.go create mode 100644 selectel/domains_v2_test.go create mode 100644 selectel/import_selectel_domains_rrset_v2_test.go create mode 100644 selectel/import_selectel_domains_zone_v2_test.go create mode 100644 selectel/resource_selectel_domains_rrset_v2.go create mode 100644 selectel/resource_selectel_domains_rrset_v2_test.go create mode 100644 selectel/resource_selectel_domains_zone_v2.go create mode 100644 selectel/resource_selectel_domains_zone_v2_test.go diff --git a/selectel/data_source_selectel_domains_rrset_v2.go b/selectel/data_source_selectel_domains_rrset_v2.go new file mode 100644 index 00000000..55d9d818 --- /dev/null +++ b/selectel/data_source_selectel_domains_rrset_v2.go @@ -0,0 +1,90 @@ +package selectel + +import ( + "context" + "errors" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +var ( + ErrRrsetNotFound = errors.New("rrset not found") + ErrFoundMultipleRRsets = errors.New("found multiple rrsets") +) + +func dataSourceDomainsRrsetV2() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceDomainsRrsetV2Read, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "zone_id": { + Type: schema.TypeString, + Required: true, + }, + "type": { + Type: schema.TypeString, + Required: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "managed_by": { + Type: schema.TypeString, + Computed: true, + }, + "ttl": { + Type: schema.TypeInt, + Computed: true, + }, + "records": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "content": { + Type: schema.TypeString, + Computed: true, + }, + "disabled": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(err) + } + + rrsetName := d.Get("name").(string) + zoneID := d.Get("zone_id").(string) + rrsetType := d.Get("type").(string) + + zoneIDWithRrsetNameAndType := fmt.Sprintf("zone_id: %s, rrset_name: %s, rrset_type: %s", zoneID, rrsetName, rrsetType) + log.Println(msgGet(objectRrset, zoneIDWithRrsetNameAndType)) + + rrset, err := getRrsetByNameAndType(ctx, client, zoneID, rrsetName, rrsetType) + if err != nil { + return diag.FromErr(err) + } + + err = setRrsetToResourceData(d, rrset) + if err != nil { + return diag.FromErr(err) + } + + return nil +} diff --git a/selectel/data_source_selectel_domains_rrset_v2_test.go b/selectel/data_source_selectel_domains_rrset_v2_test.go new file mode 100644 index 00000000..02ad6a7a --- /dev/null +++ b/selectel/data_source_selectel_domains_rrset_v2_test.go @@ -0,0 +1,68 @@ +package selectel + +import ( + "errors" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + domainsV2 "github.com/selectel/domains-go/pkg/v2" +) + +func TestAccDomainsRrsetV2DataSourceBasic(t *testing.T) { + testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) + testRrsetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) + testRrsetType := domainsV2.TXT + testRrsetTTL := 60 + testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) + resourceZoneName := "zone_tf_acc_test_1" + resourceRrsetName := "rrset_tf_acc_test_1" + dataSourceRrrsetName := fmt.Sprintf("data.selectel_domains_rrset_v2.%[1]s", resourceRrsetName) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDomainsV2RrsetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDomainsRrsetV2DataSourceBasic(resourceRrsetName, testRrsetName, string(testRrsetType), testRrrsetContent, testRrsetTTL, resourceZoneName, testZoneName), + Check: resource.ComposeTestCheckFunc( + testAccDomainsRrsetV2ID(dataSourceRrrsetName), + resource.TestCheckResourceAttr(dataSourceRrrsetName, "name", testRrsetName), + resource.TestCheckResourceAttr(dataSourceRrrsetName, "type", string(testRrsetType)), + resource.TestCheckResourceAttrSet(dataSourceRrrsetName, "zone_id"), + ), + }, + }, + }) +} + +func testAccDomainsRrsetV2ID(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("can't find rrset: %s", name) + } + + if rs.Primary.ID == "" { + return errors.New("rrset data source ID not set") + } + + return nil + } +} + +func testAccDomainsRrsetV2DataSourceBasic(resourceRrsetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { + return fmt.Sprintf(` + %[1]s + + %[2]s + + data "selectel_domains_rrset_v2" %[3]q { + name = selectel_domains_rrset_v2.%[3]s.name + type = selectel_domains_rrset_v2.%[3]s.type + zone_id = selectel_domains_zone_v2.%[4]s.id + } +`, testAccDomainsZoneV2Basic(resourceZoneName, zoneName), testAccDomainsRrsetV2Basic(resourceRrsetName, rrsetName, rrsetType, rrsetContent, ttl, resourceZoneName), resourceRrsetName, resourceZoneName) +} diff --git a/selectel/data_source_selectel_domains_zone_v2.go b/selectel/data_source_selectel_domains_zone_v2.go new file mode 100644 index 00000000..57cddcbd --- /dev/null +++ b/selectel/data_source_selectel_domains_zone_v2.go @@ -0,0 +1,82 @@ +package selectel + +import ( + "context" + "errors" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +var ( + ErrZoneNotFound = errors.New("zone not found") + ErrFoundMultipleZones = errors.New("found multiple zones") +) + +func dataSourceDomainsZoneV2() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceDomainsZoneV2Read, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "created_at": { + Type: schema.TypeString, + Computed: true, + }, + "updated_at": { + Type: schema.TypeString, + Computed: true, + }, + "delegation_checked_at": { + Type: schema.TypeString, + Computed: true, + }, + "last_check_status": { + Type: schema.TypeBool, + Computed: true, + }, + "last_delegated_at": { + Type: schema.TypeString, + Computed: true, + }, + "project_id": { + Type: schema.TypeString, + Computed: true, + }, + "disabled": { + Type: schema.TypeBool, + Computed: true, + }, + }, + } +} + +func dataSourceDomainsZoneV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(err) + } + + zoneName := d.Get("name").(string) + + log.Println(msgGet(objectZone, zoneName)) + + zone, err := getZoneByName(ctx, client, zoneName) + if err != nil { + return diag.FromErr(err) + } + + err = setZoneToResourceData(d, zone) + if err != nil { + return diag.FromErr(errGettingObject(objectZone, zoneName, err)) + } + + return nil +} diff --git a/selectel/data_source_selectel_domains_zone_v2_test.go b/selectel/data_source_selectel_domains_zone_v2_test.go new file mode 100644 index 00000000..7ceaee9d --- /dev/null +++ b/selectel/data_source_selectel_domains_zone_v2_test.go @@ -0,0 +1,68 @@ +package selectel + +import ( + "context" + "errors" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccDomainsZoneV2DataSourceBasic(t *testing.T) { + testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) + resourceZoneName := "zone_tf_acc_test_1" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDomainsV2ZoneDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDomainsZoneV2DataSourceBasic(resourceZoneName, testZoneName), + Check: resource.ComposeTestCheckFunc( + testAccDomainsZoneV2Exists(fmt.Sprintf("data.selectel_domains_zone_v2.%[1]s", resourceZoneName)), + resource.TestCheckResourceAttr(fmt.Sprintf("data.selectel_domains_zone_v2.%[1]s", resourceZoneName), "name", testZoneName), + ), + }, + }, + }) +} + +func testAccDomainsZoneV2Exists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("can't find zone: %s", name) + } + + zoneID := rs.Primary.ID + if zoneID == "" { + return errors.New("zone ID not set in tf state") + } + + meta := testAccProvider.Meta() + client, err := getDomainsV2Client(meta) + if err != nil { + return err + } + ctx := context.Background() + _, err = client.GetZone(ctx, zoneID, nil) + if err != nil { + return errors.New("zone in api not found") + } + + return nil + } +} + +func testAccDomainsZoneV2DataSourceBasic(resourceName, zoneName string) string { + return fmt.Sprintf(` + %[1]s + + data "selectel_domains_zone_v2" %[2]q { + name = selectel_domains_zone_v2.%[2]s.name + } +`, testAccDomainsZoneV2Basic(resourceName, zoneName), resourceName, zoneName) +} diff --git a/selectel/domains_v2.go b/selectel/domains_v2.go new file mode 100644 index 00000000..fe081ea6 --- /dev/null +++ b/selectel/domains_v2.go @@ -0,0 +1,99 @@ +package selectel + +import ( + "context" + "errors" + "fmt" + "net/http" + "regexp" + "strconv" + + domainsV2 "github.com/selectel/domains-go/pkg/v2" +) + +var ErrProjectIDNotSetupForDNSV2 = errors.New("env variable SEL_PROJECT_ID or variable project_id must be set for the dns v2") + +func getDomainsV2Client(meta interface{}) (domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], error) { + config := meta.(*Config) + if config.ProjectID == "" { + return nil, ErrProjectIDNotSetupForDNSV2 + } + + selvpcClient, err := config.GetSelVPCClientWithProjectScope(config.ProjectID) + if err != nil { + return nil, fmt.Errorf("can't get selvpc client for domains v2: %w", err) + } + + httpClient := &http.Client{} + userAgent := "terraform-provider-selectel" + defaultApiURL := "https://api.selectel.ru/domains/v2" + hdrs := http.Header{} + hdrs.Add("X-Auth-Token", selvpcClient.GetXAuthToken()) + hdrs.Add("User-Agent", userAgent) + domainsClient := domainsV2.NewClient(defaultApiURL, httpClient, hdrs) + + return domainsClient, nil +} + +func getZoneByName(ctx context.Context, client domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], zoneName string) (*domainsV2.Zone, error) { + optsForSearchZone := map[string]string{ + "filter": zoneName, + "limit": "1000", + "offset": "0", + } + r, err := regexp.Compile(fmt.Sprintf("^%s.?", zoneName)) + if err != nil { + return nil, err + } + + for { + zones, err := client.ListZones(ctx, &optsForSearchZone) + if err != nil { + return nil, err + } + + for _, zone := range zones.GetItems() { + if r.MatchString(zone.Name) { + return zone, nil + } + } + optsForSearchZone["offset"] = strconv.Itoa(zones.GetNextOffset()) + if zones.GetNextOffset() == 0 { + break + } + } + + return nil, errGettingObject(objectZone, zoneName, ErrZoneNotFound) +} + +func getRrsetByNameAndType(ctx context.Context, client domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], zoneID, rrsetName, rrsetType string) (*domainsV2.RRSet, error) { + optsForSearchRrset := map[string]string{ + "name": rrsetName, + "rrset_types": rrsetType, + "limit": "1000", + "offset": "0", + } + + r, err := regexp.Compile(fmt.Sprintf("^%s.?", rrsetName)) + if err != nil { + return nil, errGettingObject(objectRrset, rrsetName, err) + } + + for { + rrsets, err := client.ListRRSets(ctx, zoneID, &optsForSearchRrset) + if err != nil { + return nil, errGettingObject(objectRrset, rrsetName, err) + } + for _, rrset := range rrsets.GetItems() { + if r.MatchString(rrset.Name) && string(rrset.Type) == rrsetType { + return rrset, nil + } + } + optsForSearchRrset["offset"] = strconv.Itoa(rrsets.GetNextOffset()) + if rrsets.GetNextOffset() == 0 { + break + } + } + + return nil, errGettingObject(objectRrset, fmt.Sprintf("Name: %s. Type: %s.", rrsetName, rrsetType), ErrRrsetNotFound) +} diff --git a/selectel/domains_v2_test.go b/selectel/domains_v2_test.go new file mode 100644 index 00000000..a64bcad0 --- /dev/null +++ b/selectel/domains_v2_test.go @@ -0,0 +1,138 @@ +package selectel + +import ( + "context" + "strconv" + "testing" + + domainsV2 "github.com/selectel/domains-go/pkg/v2" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +type mockedDNSv2Client struct { + mock.Mock + domainsV2.Client +} + +func (client *mockedDNSv2Client) ListZones(ctx context.Context, opts *map[string]string) (domainsV2.Listable[domainsV2.Zone], error) { + args := client.Called(ctx, opts) + zones := args.Get(0).(domainsV2.Listable[domainsV2.Zone]) + err := args.Error(1) + return zones, err +} + +func (client *mockedDNSv2Client) ListRRSets(ctx context.Context, zoneID string, opts *map[string]string) (domainsV2.Listable[domainsV2.RRSet], error) { + args := client.Called(ctx, zoneID, opts) + rrsets := args.Get(0).(domainsV2.Listable[domainsV2.RRSet]) + err := args.Error(1) + return rrsets, err +} + +func TestGetZoneByName_whenNeededZoneInResponseWithOffset(t *testing.T) { + nameForSearch := "test.xyz." + correctIdForSearch := "mocked-uuid-2" + + mDnsClient := new(mockedDNSv2Client) + ctx := context.Background() + nextOffset := 3 + opts1 := &map[string]string{ + "filter": nameForSearch, + "limit": "1000", + "offset": "0", + } + opts2 := &map[string]string{ + "filter": nameForSearch, + "limit": "1000", + "offset": strconv.Itoa(nextOffset), + } + incorrectNameForSearch := "a." + nameForSearch + incorrectIdForSearch := "mocked-uuid-1" + zonesWithNextOffset := domainsV2.Listable[domainsV2.Zone](domainsV2.List[domainsV2.Zone]{ + Count: 1, + NextOffset: nextOffset, + Items: []*domainsV2.Zone{ + { + UUID: incorrectIdForSearch, + Name: incorrectNameForSearch, + }, + }, + }) + mDnsClient.On("ListZones", ctx, opts1).Return(zonesWithNextOffset, nil) + zonesWithoutNextOffset := domainsV2.Listable[domainsV2.Zone](domainsV2.List[domainsV2.Zone]{ + Count: 1, + NextOffset: 0, + Items: []*domainsV2.Zone{ + { + UUID: correctIdForSearch, + Name: nameForSearch, + }, + }, + }) + mDnsClient.On("ListZones", ctx, opts2).Return(zonesWithoutNextOffset, nil) + + zone, err := getZoneByName(ctx, mDnsClient, nameForSearch) + + assert.NoError(t, err) + + assert.NotNil(t, zone) + assert.Equal(t, correctIdForSearch, zone.UUID) + assert.Equal(t, nameForSearch, zone.Name) +} + +func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T) { + rrsetNameForSearch := "test.xyz." + rrsetTypeForSearch := "A" + correctIdForSearch := "mocked-uuid-2" + mockedZoneID := "mopcked-zone-id" + mDnsClient := new(mockedDNSv2Client) + ctx := context.Background() + nextOffset := 3 + opts1 := &map[string]string{ + "name": rrsetNameForSearch, + "rrset_types": rrsetTypeForSearch, + "limit": "1000", + "offset": "0", + } + opts2 := &map[string]string{ + "name": rrsetNameForSearch, + "rrset_types": rrsetTypeForSearch, + "limit": "1000", + "offset": strconv.Itoa(nextOffset), + } + incorrectNameForSearch := "a." + rrsetNameForSearch + incorrectIdForSearch := "mocked-uuid-1" + rrsetWithNextOffset := domainsV2.Listable[domainsV2.RRSet](domainsV2.List[domainsV2.RRSet]{ + Count: 1, + NextOffset: nextOffset, + Items: []*domainsV2.RRSet{ + { + UUID: incorrectIdForSearch, + Name: incorrectNameForSearch, + Type: domainsV2.RecordType(rrsetTypeForSearch), + }, + }, + }) + mDnsClient.On("ListRRSets", ctx, mockedZoneID, opts1).Return(rrsetWithNextOffset, nil) + rrsetsWithoutNextOffset := domainsV2.Listable[domainsV2.RRSet](domainsV2.List[domainsV2.RRSet]{ + Count: 1, + NextOffset: 0, + Items: []*domainsV2.RRSet{ + { + UUID: correctIdForSearch, + Name: rrsetNameForSearch, + Type: domainsV2.RecordType(rrsetTypeForSearch), + }, + }, + }) + mDnsClient.On("ListRRSets", ctx, mockedZoneID, opts2).Return(rrsetsWithoutNextOffset, nil) + + rrset, err := getRrsetByNameAndType(ctx, mDnsClient, mockedZoneID, rrsetNameForSearch, rrsetTypeForSearch) + + assert.NoError(t, err) + + assert.NotNil(t, rrset) + assert.Equal(t, correctIdForSearch, rrset.UUID) + assert.Equal(t, rrsetNameForSearch, rrset.Name) + assert.Equal(t, rrsetTypeForSearch, string(rrset.Type)) +} diff --git a/selectel/import_selectel_domains_rrset_v2_test.go b/selectel/import_selectel_domains_rrset_v2_test.go new file mode 100644 index 00000000..4d28ea44 --- /dev/null +++ b/selectel/import_selectel_domains_rrset_v2_test.go @@ -0,0 +1,60 @@ +package selectel + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + domainsV2 "github.com/selectel/domains-go/pkg/v2" +) + +func TestAccDomainsRrsetV2ImportBasic(t *testing.T) { + testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) + testRrsetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) + testRrsetType := domainsV2.TXT + testRrsetTTL := 60 + testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) + resourceZoneName := "zone_tf_acc_test_1" + resourceRrsetName := "rrset_tf_acc_test_1" + fullResourceName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRrsetName) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDomainsV2ZoneDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDomainsRrsetV2WithZoneBasic( + resourceRrsetName, testRrsetName, string(testRrsetType), testRrrsetContent, testRrsetTTL, + resourceZoneName, testZoneName, + ), + }, + { + ImportStateIdFunc: getTestRrsetIDForImport, + ResourceName: fullResourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func getTestRrsetIDForImport(s *terraform.State) (string, error) { + resourceZoneFullName := "selectel_domains_zone_v2.zone_tf_acc_test_1" + resourceRrsetFullName := "selectel_domains_rrset_v2.rrset_tf_acc_test_1" + resourceZone, ok := s.RootModule().Resources[resourceZoneFullName] + if !ok { + return "", fmt.Errorf("Not found zone: %s", resourceZoneFullName) + } + resourceRrset, ok := s.RootModule().Resources[resourceRrsetFullName] + if !ok { + return "", fmt.Errorf("Not found rrset: %s", resourceRrsetFullName) + } + + return fmt.Sprintf("%s/%s/%s", + resourceZone.Primary.Attributes["name"], + resourceRrset.Primary.Attributes["name"], + resourceRrset.Primary.Attributes["type"], + ), nil +} diff --git a/selectel/import_selectel_domains_zone_v2_test.go b/selectel/import_selectel_domains_zone_v2_test.go new file mode 100644 index 00000000..78a9d41a --- /dev/null +++ b/selectel/import_selectel_domains_zone_v2_test.go @@ -0,0 +1,31 @@ +package selectel + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDomainsZoneV2ImportBasic(t *testing.T) { + resourceName := "zone_tf_acc_test_1" + fullResourceName := fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceName) + testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDomainsV2ZoneDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDomainsZoneV2Basic(resourceName, testZoneName), + }, + { + ResourceName: fullResourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/selectel/messages.go b/selectel/messages.go index fd8b31b4..786e3833 100644 --- a/selectel/messages.go +++ b/selectel/messages.go @@ -17,3 +17,7 @@ func msgUpdate(object, id string, options interface{}) string { func msgDelete(object, id string) string { return fmt.Sprintf("[DEBUG] Deleting %s '%s'", object, id) } + +func msgImport(object, id string) string { + return fmt.Sprintf("[DEBUG] Importing %s '%s'", object, id) +} diff --git a/selectel/provider.go b/selectel/provider.go index 053e2e3c..c1f5dfcd 100644 --- a/selectel/provider.go +++ b/selectel/provider.go @@ -24,6 +24,8 @@ const ( objectNodegroup = "nodegroup" objectDomain = "domain" objectRecord = "record" + objectZone = "zone" + objectRrset = "rrset" objectDatastore = "datastore" objectDatabase = "database" objectGrant = "grant" @@ -98,6 +100,8 @@ func Provider() *schema.Provider { }, DataSourcesMap: map[string]*schema.Resource{ "selectel_domains_domain_v1": dataSourceDomainsDomainV1(), + "selectel_domains_zone_v2": dataSourceDomainsZoneV2(), + "selectel_domains_rrset_v2": dataSourceDomainsRrsetV2(), "selectel_dbaas_datastore_type_v1": dataSourceDBaaSDatastoreTypeV1(), "selectel_dbaas_available_extension_v1": dataSourceDBaaSAvailableExtensionV1(), "selectel_dbaas_flavor_v1": dataSourceDBaaSFlavorV1(), @@ -123,6 +127,8 @@ func Provider() *schema.Provider { "selectel_mks_nodegroup_v1": resourceMKSNodegroupV1(), "selectel_domains_domain_v1": resourceDomainsDomainV1(), "selectel_domains_record_v1": resourceDomainsRecordV1(), + "selectel_domains_zone_v2": resourceDomainsZoneV2(), + "selectel_domains_rrset_v2": resourceDomainsRrsetV2(), "selectel_dbaas_datastore_v1": resourceDBaaSDatastoreV1(), // DEPRECATED "selectel_dbaas_postgresql_datastore_v1": resourceDBaaSPostgreSQLDatastoreV1(), "selectel_dbaas_mysql_datastore_v1": resourceDBaaSMySQLDatastoreV1(), diff --git a/selectel/provider_test.go b/selectel/provider_test.go index f01b9d2a..63ba8d82 100644 --- a/selectel/provider_test.go +++ b/selectel/provider_test.go @@ -45,6 +45,13 @@ func testAccSelectelPreCheck(t *testing.T) { } } +func testAccSelectelPreCheckWithProjectID(t *testing.T) { + testAccSelectelPreCheck(t) + if v := os.Getenv("SEL_PROJECT_ID"); v == "" { + t.Fatal("SEL_PROJECT_ID must be set for acceptance tests") + } +} + func testAccCheckSelectelImportEnv(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] diff --git a/selectel/resource_selectel_domains_rrset_v2.go b/selectel/resource_selectel_domains_rrset_v2.go new file mode 100644 index 00000000..c06d903f --- /dev/null +++ b/selectel/resource_selectel_domains_rrset_v2.go @@ -0,0 +1,266 @@ +package selectel + +import ( + "context" + "errors" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + domainsV2 "github.com/selectel/domains-go/pkg/v2" +) + +func resourceDomainsRrsetV2() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceDomainsRrsetV2Create, + ReadContext: resourceDomainsRrsetV2Read, + UpdateContext: resourceDomainsRrsetV2Update, + DeleteContext: resourceDomainsRrsetV2Delete, + Importer: &schema.ResourceImporter{ + StateContext: resourceDomainsRrsetV2ImportState, + }, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "zone_id": { + Type: schema.TypeString, + Required: true, + }, + "type": { + Type: schema.TypeString, + Required: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "managed_by": { + Type: schema.TypeString, + Computed: true, + }, + "ttl": { + Type: schema.TypeInt, + Required: true, + }, + "records": { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "content": { + Type: schema.TypeString, + Required: true, + }, + "disabled": { + Type: schema.TypeBool, + Default: false, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func resourceDomainsRrsetV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + zoneID := d.Get("zone_id").(string) + selMutexKV.Lock(zoneID) + defer selMutexKV.Unlock(zoneID) + + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(err) + } + + recordType := domainsV2.RecordType(d.Get("type").(string)) + recordsSet := d.Get("records").(*schema.Set) + records := generateRecordsFromSet(recordsSet) + createOpts := &domainsV2.RRSet{ + Name: d.Get("name").(string), + Type: recordType, + TTL: d.Get("ttl").(int), + ZoneUUID: zoneID, + Records: records, + } + + if comment := d.Get("comment"); comment != nil { + createOpts.Comment = comment.(string) + } + if managedBy := d.Get("managed_by"); managedBy != nil { + createOpts.ManagedBy = managedBy.(string) + } + + rrset, err := client.CreateRRSet(ctx, zoneID, createOpts) + if err != nil { + return diag.FromErr(errCreatingObject(objectRrset, err)) + } + + err = setRrsetToResourceData(d, rrset) + if err != nil { + return diag.FromErr(errCreatingObject(objectRrset, err)) + } + + return nil +} + +func resourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(err) + } + + rrsetID := d.Id() + zoneID := d.Get("zone_id").(string) + zoneIDWithRrsetID := fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID) + + log.Print(msgGet(objectRrset, zoneIDWithRrsetID)) + + rrset, err := client.GetRRSet(ctx, zoneID, rrsetID) + if err != nil { + d.SetId("") + return diag.FromErr(errGettingObject(objectRrset, zoneIDWithRrsetID, err)) + } + + err = setRrsetToResourceData(d, rrset) + if err != nil { + return diag.FromErr(errGettingObject(objectRrset, zoneIDWithRrsetID, err)) + } + + return nil +} + +func resourceDomainsRrsetV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + client, err := getDomainsV2Client(meta) + if err != nil { + return nil, err + } + + parts := strings.Split(d.Id(), "/") + if len(parts) != 3 { + return nil, errors.New("id must include three parts: zone_name/rrset_name/rrset_type") + } + + zoneName := parts[0] + rrsetName := parts[1] + rrsetType := parts[2] + + log.Print(msgImport(objectRrset, fmt.Sprintf("%s/%s/%s", zoneName, rrsetName, rrsetType))) + + zone, err := getZoneByName(ctx, client, zoneName) + if err != nil { + return nil, err + } + + rrset, err := getRrsetByNameAndType(ctx, client, zone.UUID, rrsetName, rrsetType) + if err != nil { + return nil, err + } + + err = setRrsetToResourceData(d, rrset) + if err != nil { + return nil, err + } + + return []*schema.ResourceData{d}, nil +} + +func resourceDomainsRrsetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + rrsetID := d.Id() + zoneID := d.Get("zone_id").(string) + + selMutexKV.Lock(zoneID) + defer selMutexKV.Unlock(zoneID) + + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(errUpdatingObject(objectRrset, rrsetID, err)) + } + + if d.HasChanges("ttl", "comment", "records") { + recordsSet := d.Get("records").(*schema.Set) + records := generateRecordsFromSet(recordsSet) + + updateOpts := &domainsV2.RRSet{ + Name: d.Get("name").(string), + Type: domainsV2.RecordType(d.Get("type").(string)), + TTL: d.Get("ttl").(int), + ZoneUUID: zoneID, + Comment: d.Get("comment").(string), + ManagedBy: d.Get("managed_by").(string), + Records: records, + } + err = client.UpdateRRSet(ctx, zoneID, rrsetID, updateOpts) + if err != nil { + return diag.FromErr(errUpdatingObject(objectRrset, rrsetID, err)) + } + } + + return resourceDomainsRrsetV2Read(ctx, d, meta) +} + +func resourceDomainsRrsetV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + zoneID := d.Get("zone_id").(string) + rrsetID := d.Id() + selMutexKV.Lock(zoneID) + defer selMutexKV.Unlock(zoneID) + + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(errDeletingObject(objectRrset, rrsetID, err)) + } + + log.Print(msgDelete(objectRrset, fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID))) + + err = client.DeleteRRSet(ctx, zoneID, rrsetID) + if err != nil { + return diag.FromErr(errDeletingObject(objectRrset, rrsetID, err)) + } + + return nil +} + +func setRrsetToResourceData(d *schema.ResourceData, rrset *domainsV2.RRSet) error { + d.SetId(rrset.UUID) + 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.ZoneUUID) + 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_rrset_v2_test.go b/selectel/resource_selectel_domains_rrset_v2_test.go new file mode 100644 index 00000000..6c102f0d --- /dev/null +++ b/selectel/resource_selectel_domains_rrset_v2_test.go @@ -0,0 +1,98 @@ +package selectel + +import ( + "context" + "errors" + "fmt" + "log" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + domainsV2 "github.com/selectel/domains-go/pkg/v2" +) + +func TestAccDomainsRrsetV2Basic(t *testing.T) { + testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) + testRrsetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) + testRrsetType := domainsV2.TXT + testRrsetTTL := 60 + testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) + resourceZoneName := "zone_tf_acc_test_1" + resourceRrsetName := "rrset_tf_acc_test_1" + dataSourceRrrsetName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRrsetName) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDomainsV2ZoneDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDomainsRrsetV2WithZoneBasic(resourceRrsetName, testRrsetName, string(testRrsetType), testRrrsetContent, testRrsetTTL, resourceZoneName, testZoneName), + Check: resource.ComposeTestCheckFunc( + testAccDomainsRrsetV2ID(dataSourceRrrsetName), + resource.TestCheckResourceAttr(dataSourceRrrsetName, "name", testRrsetName), + resource.TestCheckResourceAttr(dataSourceRrrsetName, "type", string(testRrsetType)), + resource.TestCheckResourceAttrSet(dataSourceRrrsetName, "zone_id"), + ), + }, + }, + }) +} + +func testAccDomainsRrsetV2WithZoneBasic(resourceRrsetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { + return fmt.Sprintf(` + %[7]s + + resource "selectel_domains_rrset_v2" %[1]q { + name = %[2]q + type = %[3]q + ttl = %[4]d + zone_id = selectel_domains_zone_v2.%[6]s.id + records { + content = %[5]q + disabled = false + } + }`, resourceRrsetName, rrsetName, rrsetType, ttl, rrsetContent, resourceZoneName, testAccDomainsZoneV2Basic(resourceZoneName, zoneName)) +} + +func testAccDomainsRrsetV2Basic(resourceRrsetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName string) string { + return fmt.Sprintf(` + resource "selectel_domains_rrset_v2" %[1]q { + name = %[2]q + type = %[3]q + ttl = %[4]d + zone_id = selectel_domains_zone_v2.%[5]s.id + records { + content = %[6]q + disabled = false + } + }`, resourceRrsetName, rrsetName, rrsetType, ttl, resourceZoneName, rrsetContent) +} + +func testAccCheckDomainsV2RrsetDestroy(s *terraform.State) error { + meta := testAccProvider.Meta() + client, err := getDomainsV2Client(meta) + if err != nil { + return err + } + + ctx := context.Background() + + for _, rs := range s.RootModule().Resources { + log.Printf("RT: %s", rs.Type) + if rs.Type != "selectel_domains_rrset_v2" { + continue + } + + zoneID := rs.Primary.Attributes["zone_id"] + rrsetID := rs.Primary.ID + + _, err = client.GetRRSet(ctx, zoneID, rrsetID) + if err == nil { + return errors.New("rrset still exists") + } + } + + return nil +} diff --git a/selectel/resource_selectel_domains_zone_v2.go b/selectel/resource_selectel_domains_zone_v2.go new file mode 100644 index 00000000..6cd156fb --- /dev/null +++ b/selectel/resource_selectel_domains_zone_v2.go @@ -0,0 +1,198 @@ +package selectel + +import ( + "context" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + domainsV2 "github.com/selectel/domains-go/pkg/v2" +) + +func resourceDomainsZoneV2() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceDomainsZoneV2Create, + ReadContext: resourceDomainsZoneV2Read, + DeleteContext: resourceDomainsZoneV2Delete, + UpdateContext: resourceDomainsZoneV2Update, + Importer: &schema.ResourceImporter{ + StateContext: resourceDomainsZoneV2ImportState, + }, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "created_at": { + Type: schema.TypeString, + Computed: true, + }, + "updated_at": { + Type: schema.TypeString, + Computed: true, + }, + "delegation_checked_at": { + Type: schema.TypeString, + Computed: true, + }, + "last_check_status": { + Type: schema.TypeBool, + Computed: true, + }, + "last_delegated_at": { + Type: schema.TypeString, + Computed: true, + }, + "project_id": { + Type: schema.TypeString, + Computed: true, + }, + "disabled": { + Type: schema.TypeBool, + Computed: true, + }, + }, + } +} + +func resourceDomainsZoneV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(err) + } + + zoneName := d.Get("name").(string) + createOpts := &domainsV2.Zone{ + Name: zoneName, + } + + log.Println(msgCreate(objectZone, zoneName)) + + zone, err := client.CreateZone(ctx, createOpts) + if err != nil { + return diag.FromErr(errCreatingObject(objectZone, err)) + } + + err = setZoneToResourceData(d, zone) + if err != nil { + return diag.FromErr(errCreatingObject(objectZone, err)) + } + + return nil +} + +func resourceDomainsZoneV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(err) + } + + zoneName := d.Get("name").(string) + + log.Println(msgGet(objectZone, zoneName)) + zone, err := getZoneByName(ctx, client, zoneName) + if err != nil { + return diag.FromErr(errGettingObject(objectZone, zoneName, err)) + } + + err = setZoneToResourceData(d, zone) + if err != nil { + return diag.FromErr(errGettingObject(objectZone, zoneName, err)) + } + + return nil +} + +func resourceDomainsZoneV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + client, err := getDomainsV2Client(meta) + if err != nil { + return nil, err + } + + zoneName := d.Id() + + log.Println(msgImport(objectZone, zoneName)) + + zone, err := getZoneByName(ctx, client, zoneName) + if err != nil { + return nil, err + } + + err = setZoneToResourceData(d, zone) + if err != nil { + return nil, err + } + + return []*schema.ResourceData{d}, nil +} + +func resourceDomainsZoneV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + zoneID := d.Id() + + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(errUpdatingObject(objectZone, zoneID, err)) + } + + if d.HasChange("comment") { + comment := d.Get("comment").(string) + + log.Println(msgUpdate(objectZone, zoneID, comment)) + + err = client.UpdateZoneComment(ctx, zoneID, comment) + if err != nil { + return diag.FromErr(errUpdatingObject(objectZone, zoneID, err)) + } + } + + if d.HasChange("disabled") { + disabled := d.Get("disabled").(bool) + + log.Println(msgUpdate(objectZone, zoneID, disabled)) + + err = client.UpdateZoneState(ctx, zoneID, disabled) + if err != nil { + return diag.FromErr(errUpdatingObject(objectZone, zoneID, err)) + } + } + + return nil +} + +func resourceDomainsZoneV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getDomainsV2Client(meta) + if err != nil { + return diag.FromErr(err) + } + + zoneID := d.Id() + + log.Println(msgDelete(objectZone, zoneID)) + + err = client.DeleteZone(ctx, zoneID) + if err != nil { + return diag.FromErr(errDeletingObject(objectZone, zoneID, err)) + } + + return nil +} + +func setZoneToResourceData(d *schema.ResourceData, zone *domainsV2.Zone) error { + d.SetId(zone.UUID) + 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", zone.ProjectID) + d.Set("disabled", zone.Disabled) + + return nil +} diff --git a/selectel/resource_selectel_domains_zone_v2_test.go b/selectel/resource_selectel_domains_zone_v2_test.go new file mode 100644 index 00000000..6019bae0 --- /dev/null +++ b/selectel/resource_selectel_domains_zone_v2_test.go @@ -0,0 +1,63 @@ +package selectel + +import ( + "context" + "errors" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccDomainsZoneV2Basic(t *testing.T) { + testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) + resourceZoneName := "zone_tf_acc_test_1" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDomainsV2ZoneDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDomainsZoneV2Basic(resourceZoneName, testZoneName), + Check: resource.ComposeTestCheckFunc( + testAccDomainsZoneV2Exists(fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceZoneName)), + resource.TestCheckResourceAttr(fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceZoneName), "name", testZoneName), + ), + }, + }, + }) +} + +func testAccDomainsZoneV2Basic(resourceName, zoneName string) string { + return fmt.Sprintf(` + resource "selectel_domains_zone_v2" %[1]q { + name = %[2]q + }`, resourceName, zoneName) +} + +func testAccCheckDomainsV2ZoneDestroy(s *terraform.State) error { + meta := testAccProvider.Meta() + client, err := getDomainsV2Client(meta) + if err != nil { + return err + } + + ctx := context.Background() + + for _, rs := range s.RootModule().Resources { + if rs.Type != "selectel_domains_zone_v2" { + continue + } + + zoneID := rs.Primary.ID + + _, err = client.GetZone(ctx, zoneID, nil) + if err == nil { + return errors.New("domain still exists") + } + } + + return nil +} From 75a282b2ce2ca67026d7c167d4810fd0767a78e2 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Tue, 23 Jan 2024 21:47:55 +0300 Subject: [PATCH 02/16] Resolve merge conflicts in go.mod and go.sum after added entities for work with DNS v2 API. --- go.mod | 5 +++-- go.sum | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 54a98503..a9ffd50f 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/selectel/craas-go v0.3.0 github.com/selectel/dbaas-go v0.9.0 - github.com/selectel/domains-go v0.5.0 + github.com/selectel/domains-go v1.0.0 github.com/selectel/go-selvpcclient/v3 v3.1.1 github.com/selectel/mks-go v0.12.0 - github.com/stretchr/testify v1.7.2 + github.com/stretchr/testify v1.8.4 ) require ( @@ -51,6 +51,7 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/objx v0.5.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect github.com/vmihailenco/tagparser v0.1.1 // indirect diff --git a/go.sum b/go.sum index 2647168d..89cca769 100644 --- a/go.sum +++ b/go.sum @@ -104,7 +104,7 @@ github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1 github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc= +github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= @@ -157,6 +157,8 @@ github.com/selectel/domains-go v0.5.0 h1:RCrWY/9KHVtfdA+X8M+DDzsjILxFChhY70HnJEu github.com/selectel/domains-go v0.5.0/go.mod h1:AhXhwyMSTkpEWFiBLUvzFP76W+WN+ZblwmjLJLt7y58= github.com/selectel/go-selvpcclient/v3 v3.1.1 h1:C1q2LqqosiapoLpnGITGmysg0YCSQYDo2Gh69CioevM= github.com/selectel/go-selvpcclient/v3 v3.1.1/go.mod h1:NM7IXhh1IzqZ88DOw1Qc5Ez3tULLViXo95l5+rKPuyQ= +github.com/selectel/domains-go v1.0.0 h1:F3itzB+wdPAg9j6l+mVJFANC6hyShqBa9VykYfV+row= +github.com/selectel/domains-go v1.0.0/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA= github.com/selectel/mks-go v0.12.0 h1:nLWHK8BXkhFlXvjFqf7WRrdAfvmrOhQzDSLx7BGa6aM= github.com/selectel/mks-go v0.12.0/go.mod h1:FcFqF3WvZIhztyAt1+ZySKf0zWmCEvg9e2gRwxVyQOw= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= @@ -164,12 +166,18 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= From 60394c55dc7906d49cf7247ca2429e45cd5f4a12 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Tue, 23 Jan 2024 22:05:38 +0300 Subject: [PATCH 03/16] Fix test: import zone for dns v2. --- selectel/import_selectel_domains_zone_v2_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/selectel/import_selectel_domains_zone_v2_test.go b/selectel/import_selectel_domains_zone_v2_test.go index 78a9d41a..c8f09e31 100644 --- a/selectel/import_selectel_domains_zone_v2_test.go +++ b/selectel/import_selectel_domains_zone_v2_test.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccDomainsZoneV2ImportBasic(t *testing.T) { @@ -25,7 +26,17 @@ func TestAccDomainsZoneV2ImportBasic(t *testing.T) { ResourceName: fullResourceName, ImportState: true, ImportStateVerify: true, + ImportStateIdFunc: getTestZoneIDForImport, }, }, }) } + +func getTestZoneIDForImport(s *terraform.State) (string, error) { + resourceZoneFullName := "selectel_domains_zone_v2.zone_tf_acc_test_1" + resourceZone, ok := s.RootModule().Resources[resourceZoneFullName] + if !ok { + return "", fmt.Errorf("Not found zone: %s", resourceZoneFullName) + } + return resourceZone.Primary.Attributes["name"], nil +} From 4db5403fd490b05984200bce8c9ef72563bff60a Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Tue, 23 Jan 2024 22:40:39 +0300 Subject: [PATCH 04/16] Fix linters --- ...a_source_selectel_domains_rrset_v2_test.go | 4 +- ...ta_source_selectel_domains_zone_v2_test.go | 3 +- selectel/domains_v2.go | 4 +- selectel/domains_v2_test.go | 38 ++++++++++--------- .../import_selectel_domains_rrset_v2_test.go | 2 - .../import_selectel_domains_zone_v2_test.go | 7 ++-- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/selectel/data_source_selectel_domains_rrset_v2_test.go b/selectel/data_source_selectel_domains_rrset_v2_test.go index 02ad6a7a..88cc216c 100644 --- a/selectel/data_source_selectel_domains_rrset_v2_test.go +++ b/selectel/data_source_selectel_domains_rrset_v2_test.go @@ -11,14 +11,14 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) +const resourceRrsetName = "rrset_tf_acc_test_1" + func TestAccDomainsRrsetV2DataSourceBasic(t *testing.T) { testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) testRrsetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) testRrsetType := domainsV2.TXT testRrsetTTL := 60 testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) - resourceZoneName := "zone_tf_acc_test_1" - resourceRrsetName := "rrset_tf_acc_test_1" dataSourceRrrsetName := fmt.Sprintf("data.selectel_domains_rrset_v2.%[1]s", resourceRrsetName) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, diff --git a/selectel/data_source_selectel_domains_zone_v2_test.go b/selectel/data_source_selectel_domains_zone_v2_test.go index 7ceaee9d..17ea2595 100644 --- a/selectel/data_source_selectel_domains_zone_v2_test.go +++ b/selectel/data_source_selectel_domains_zone_v2_test.go @@ -11,9 +11,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) +const resourceZoneName = "zone_tf_acc_test_1" + func TestAccDomainsZoneV2DataSourceBasic(t *testing.T) { testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) - resourceZoneName := "zone_tf_acc_test_1" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, ProviderFactories: testAccProviders, diff --git a/selectel/domains_v2.go b/selectel/domains_v2.go index fe081ea6..b0525759 100644 --- a/selectel/domains_v2.go +++ b/selectel/domains_v2.go @@ -26,11 +26,11 @@ func getDomainsV2Client(meta interface{}) (domainsV2.DNSClient[domainsV2.Zone, d httpClient := &http.Client{} userAgent := "terraform-provider-selectel" - defaultApiURL := "https://api.selectel.ru/domains/v2" + defaultAPIURL := "https://api.selectel.ru/domains/v2" hdrs := http.Header{} hdrs.Add("X-Auth-Token", selvpcClient.GetXAuthToken()) hdrs.Add("User-Agent", userAgent) - domainsClient := domainsV2.NewClient(defaultApiURL, httpClient, hdrs) + domainsClient := domainsV2.NewClient(defaultAPIURL, httpClient, hdrs) return domainsClient, nil } diff --git a/selectel/domains_v2_test.go b/selectel/domains_v2_test.go index a64bcad0..73a1565d 100644 --- a/selectel/domains_v2_test.go +++ b/selectel/domains_v2_test.go @@ -19,6 +19,7 @@ func (client *mockedDNSv2Client) ListZones(ctx context.Context, opts *map[string args := client.Called(ctx, opts) zones := args.Get(0).(domainsV2.Listable[domainsV2.Zone]) err := args.Error(1) + return zones, err } @@ -26,14 +27,15 @@ func (client *mockedDNSv2Client) ListRRSets(ctx context.Context, zoneID string, args := client.Called(ctx, zoneID, opts) rrsets := args.Get(0).(domainsV2.Listable[domainsV2.RRSet]) err := args.Error(1) + return rrsets, err } func TestGetZoneByName_whenNeededZoneInResponseWithOffset(t *testing.T) { nameForSearch := "test.xyz." - correctIdForSearch := "mocked-uuid-2" + correctIDForSearch := "mocked-uuid-2" - mDnsClient := new(mockedDNSv2Client) + mDNSClient := new(mockedDNSv2Client) ctx := context.Background() nextOffset := 3 opts1 := &map[string]string{ @@ -47,45 +49,45 @@ func TestGetZoneByName_whenNeededZoneInResponseWithOffset(t *testing.T) { "offset": strconv.Itoa(nextOffset), } incorrectNameForSearch := "a." + nameForSearch - incorrectIdForSearch := "mocked-uuid-1" + incorrectIDForSearch := "mocked-uuid-1" zonesWithNextOffset := domainsV2.Listable[domainsV2.Zone](domainsV2.List[domainsV2.Zone]{ Count: 1, NextOffset: nextOffset, Items: []*domainsV2.Zone{ { - UUID: incorrectIdForSearch, + UUID: incorrectIDForSearch, Name: incorrectNameForSearch, }, }, }) - mDnsClient.On("ListZones", ctx, opts1).Return(zonesWithNextOffset, nil) + mDNSClient.On("ListZones", ctx, opts1).Return(zonesWithNextOffset, nil) zonesWithoutNextOffset := domainsV2.Listable[domainsV2.Zone](domainsV2.List[domainsV2.Zone]{ Count: 1, NextOffset: 0, Items: []*domainsV2.Zone{ { - UUID: correctIdForSearch, + UUID: correctIDForSearch, Name: nameForSearch, }, }, }) - mDnsClient.On("ListZones", ctx, opts2).Return(zonesWithoutNextOffset, nil) + mDNSClient.On("ListZones", ctx, opts2).Return(zonesWithoutNextOffset, nil) - zone, err := getZoneByName(ctx, mDnsClient, nameForSearch) + zone, err := getZoneByName(ctx, mDNSClient, nameForSearch) assert.NoError(t, err) assert.NotNil(t, zone) - assert.Equal(t, correctIdForSearch, zone.UUID) + assert.Equal(t, correctIDForSearch, zone.UUID) assert.Equal(t, nameForSearch, zone.Name) } func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T) { rrsetNameForSearch := "test.xyz." rrsetTypeForSearch := "A" - correctIdForSearch := "mocked-uuid-2" + correctIDForSearch := "mocked-uuid-2" mockedZoneID := "mopcked-zone-id" - mDnsClient := new(mockedDNSv2Client) + mDNSClient := new(mockedDNSv2Client) ctx := context.Background() nextOffset := 3 opts1 := &map[string]string{ @@ -101,38 +103,38 @@ func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T "offset": strconv.Itoa(nextOffset), } incorrectNameForSearch := "a." + rrsetNameForSearch - incorrectIdForSearch := "mocked-uuid-1" + incorrectIDForSearch := "mocked-uuid-1" rrsetWithNextOffset := domainsV2.Listable[domainsV2.RRSet](domainsV2.List[domainsV2.RRSet]{ Count: 1, NextOffset: nextOffset, Items: []*domainsV2.RRSet{ { - UUID: incorrectIdForSearch, + UUID: incorrectIDForSearch, Name: incorrectNameForSearch, Type: domainsV2.RecordType(rrsetTypeForSearch), }, }, }) - mDnsClient.On("ListRRSets", ctx, mockedZoneID, opts1).Return(rrsetWithNextOffset, nil) + mDNSClient.On("ListRRSets", ctx, mockedZoneID, opts1).Return(rrsetWithNextOffset, nil) rrsetsWithoutNextOffset := domainsV2.Listable[domainsV2.RRSet](domainsV2.List[domainsV2.RRSet]{ Count: 1, NextOffset: 0, Items: []*domainsV2.RRSet{ { - UUID: correctIdForSearch, + UUID: correctIDForSearch, Name: rrsetNameForSearch, Type: domainsV2.RecordType(rrsetTypeForSearch), }, }, }) - mDnsClient.On("ListRRSets", ctx, mockedZoneID, opts2).Return(rrsetsWithoutNextOffset, nil) + mDNSClient.On("ListRRSets", ctx, mockedZoneID, opts2).Return(rrsetsWithoutNextOffset, nil) - rrset, err := getRrsetByNameAndType(ctx, mDnsClient, mockedZoneID, rrsetNameForSearch, rrsetTypeForSearch) + rrset, err := getRrsetByNameAndType(ctx, mDNSClient, mockedZoneID, rrsetNameForSearch, rrsetTypeForSearch) assert.NoError(t, err) assert.NotNil(t, rrset) - assert.Equal(t, correctIdForSearch, rrset.UUID) + assert.Equal(t, correctIDForSearch, rrset.UUID) assert.Equal(t, rrsetNameForSearch, rrset.Name) assert.Equal(t, rrsetTypeForSearch, string(rrset.Type)) } diff --git a/selectel/import_selectel_domains_rrset_v2_test.go b/selectel/import_selectel_domains_rrset_v2_test.go index 4d28ea44..1dd92f01 100644 --- a/selectel/import_selectel_domains_rrset_v2_test.go +++ b/selectel/import_selectel_domains_rrset_v2_test.go @@ -16,8 +16,6 @@ func TestAccDomainsRrsetV2ImportBasic(t *testing.T) { testRrsetType := domainsV2.TXT testRrsetTTL := 60 testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) - resourceZoneName := "zone_tf_acc_test_1" - resourceRrsetName := "rrset_tf_acc_test_1" fullResourceName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRrsetName) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, diff --git a/selectel/import_selectel_domains_zone_v2_test.go b/selectel/import_selectel_domains_zone_v2_test.go index c8f09e31..84e934d7 100644 --- a/selectel/import_selectel_domains_zone_v2_test.go +++ b/selectel/import_selectel_domains_zone_v2_test.go @@ -10,17 +10,15 @@ import ( ) func TestAccDomainsZoneV2ImportBasic(t *testing.T) { - resourceName := "zone_tf_acc_test_1" - fullResourceName := fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceName) + fullResourceName := fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceZoneName) testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, ProviderFactories: testAccProviders, CheckDestroy: testAccCheckDomainsV2ZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsZoneV2Basic(resourceName, testZoneName), + Config: testAccDomainsZoneV2Basic(resourceZoneName, testZoneName), }, { ResourceName: fullResourceName, @@ -38,5 +36,6 @@ func getTestZoneIDForImport(s *terraform.State) (string, error) { if !ok { return "", fmt.Errorf("Not found zone: %s", resourceZoneFullName) } + return resourceZone.Primary.Attributes["name"], nil } From da2062484658eb9e1f4328668eb9d21281e61c5d Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Fri, 26 Jan 2024 15:13:19 +0300 Subject: [PATCH 05/16] Update entities selectel_domains_v2 for work with domains-go 1.0.2. Added optional field project_id for entities selectel_domains_v2. Fix work with optional fields. --- go.mod | 2 +- go.sum | 8 +-- .../data_source_selectel_domains_rrset_v2.go | 10 ++- .../data_source_selectel_domains_zone_v2.go | 11 ++-- ...ta_source_selectel_domains_zone_v2_test.go | 4 +- selectel/domains_v2.go | 23 +++++-- selectel/domains_v2_test.go | 60 ++++++++++++++++-- .../resource_selectel_domains_rrset_v2.go | 46 ++++++++------ ...resource_selectel_domains_rrset_v2_test.go | 11 ++-- selectel/resource_selectel_domains_zone_v2.go | 63 +++++++++++++------ .../resource_selectel_domains_zone_v2_test.go | 11 ++-- 11 files changed, 169 insertions(+), 80 deletions(-) diff --git a/go.mod b/go.mod index a9ffd50f..2b7aca5f 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/selectel/craas-go v0.3.0 github.com/selectel/dbaas-go v0.9.0 - github.com/selectel/domains-go v1.0.0 + github.com/selectel/domains-go v1.0.2 github.com/selectel/go-selvpcclient/v3 v3.1.1 github.com/selectel/mks-go v0.12.0 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 89cca769..0a488940 100644 --- a/go.sum +++ b/go.sum @@ -153,12 +153,12 @@ github.com/selectel/craas-go v0.3.0 h1:tXiw3LNN+ZVV0wZdeBBXX6u8kMuA5PV/5W1uYqV0y github.com/selectel/craas-go v0.3.0/go.mod h1:9RAUn9PdMITP4I3GAade6v2hjB2j3lo3J2dDlG5SLYE= github.com/selectel/dbaas-go v0.9.0 h1:IAmiyxkRtfLZg1JUdIhcsE5jpdBvsZibPCqyhB+yV30= github.com/selectel/dbaas-go v0.9.0/go.mod h1:8D945oFzpx94v08zIb4s1bRTPCdPoNVnBu4umMYFJrQ= -github.com/selectel/domains-go v0.5.0 h1:RCrWY/9KHVtfdA+X8M+DDzsjILxFChhY70HnJEu1Y2U= -github.com/selectel/domains-go v0.5.0/go.mod h1:AhXhwyMSTkpEWFiBLUvzFP76W+WN+ZblwmjLJLt7y58= +github.com/selectel/domains-go v1.0.1 h1:Dau3uVlAXA3iFpeUQq2ld/aOlc8bzwdAXdVPGMwCD7Q= +github.com/selectel/domains-go v1.0.1/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA= +github.com/selectel/domains-go v1.0.2 h1:Si6iGaMnTFJxwiJVI50DOdZnwcxc87kqaWrVQYW0a4U= +github.com/selectel/domains-go v1.0.2/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA= github.com/selectel/go-selvpcclient/v3 v3.1.1 h1:C1q2LqqosiapoLpnGITGmysg0YCSQYDo2Gh69CioevM= github.com/selectel/go-selvpcclient/v3 v3.1.1/go.mod h1:NM7IXhh1IzqZ88DOw1Qc5Ez3tULLViXo95l5+rKPuyQ= -github.com/selectel/domains-go v1.0.0 h1:F3itzB+wdPAg9j6l+mVJFANC6hyShqBa9VykYfV+row= -github.com/selectel/domains-go v1.0.0/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA= github.com/selectel/mks-go v0.12.0 h1:nLWHK8BXkhFlXvjFqf7WRrdAfvmrOhQzDSLx7BGa6aM= github.com/selectel/mks-go v0.12.0/go.mod h1:FcFqF3WvZIhztyAt1+ZySKf0zWmCEvg9e2gRwxVyQOw= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= diff --git a/selectel/data_source_selectel_domains_rrset_v2.go b/selectel/data_source_selectel_domains_rrset_v2.go index 55d9d818..1d5e6a80 100644 --- a/selectel/data_source_selectel_domains_rrset_v2.go +++ b/selectel/data_source_selectel_domains_rrset_v2.go @@ -23,14 +23,18 @@ func dataSourceDomainsRrsetV2() *schema.Resource { Type: schema.TypeString, Required: true, }, - "zone_id": { + "type": { Type: schema.TypeString, Required: true, }, - "type": { + "zone_id": { Type: schema.TypeString, Required: true, }, + "project_id": { + Type: schema.TypeString, + Optional: true, + }, "comment": { Type: schema.TypeString, Computed: true, @@ -64,7 +68,7 @@ func dataSourceDomainsRrsetV2() *schema.Resource { } func dataSourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) } diff --git a/selectel/data_source_selectel_domains_zone_v2.go b/selectel/data_source_selectel_domains_zone_v2.go index 57cddcbd..5d6edf5f 100644 --- a/selectel/data_source_selectel_domains_zone_v2.go +++ b/selectel/data_source_selectel_domains_zone_v2.go @@ -22,6 +22,11 @@ func dataSourceDomainsZoneV2() *schema.Resource { Type: schema.TypeString, Required: true, }, + "project_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, "comment": { Type: schema.TypeString, Computed: true, @@ -46,10 +51,6 @@ func dataSourceDomainsZoneV2() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "project_id": { - Type: schema.TypeString, - Computed: true, - }, "disabled": { Type: schema.TypeBool, Computed: true, @@ -59,7 +60,7 @@ func dataSourceDomainsZoneV2() *schema.Resource { } func dataSourceDomainsZoneV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) } diff --git a/selectel/data_source_selectel_domains_zone_v2_test.go b/selectel/data_source_selectel_domains_zone_v2_test.go index 17ea2595..dcc672b9 100644 --- a/selectel/data_source_selectel_domains_zone_v2_test.go +++ b/selectel/data_source_selectel_domains_zone_v2_test.go @@ -42,9 +42,7 @@ func testAccDomainsZoneV2Exists(name string) resource.TestCheckFunc { if zoneID == "" { return errors.New("zone ID not set in tf state") } - - meta := testAccProvider.Meta() - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2ClientTest(rs, testAccProvider) if err != nil { return err } diff --git a/selectel/domains_v2.go b/selectel/domains_v2.go index b0525759..c61446e8 100644 --- a/selectel/domains_v2.go +++ b/selectel/domains_v2.go @@ -8,18 +8,19 @@ import ( "regexp" "strconv" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" domainsV2 "github.com/selectel/domains-go/pkg/v2" ) var ErrProjectIDNotSetupForDNSV2 = errors.New("env variable SEL_PROJECT_ID or variable project_id must be set for the dns v2") -func getDomainsV2Client(meta interface{}) (domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], error) { +func getDomainsV2Client(d *schema.ResourceData, meta interface{}) (domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], error) { config := meta.(*Config) - if config.ProjectID == "" { - return nil, ErrProjectIDNotSetupForDNSV2 + projectID, err := getProjectIDFromResourceOrConfig(d, config) + if err != nil { + return nil, fmt.Errorf("can't get projectID for domains v2: %w", err) } - - selvpcClient, err := config.GetSelVPCClientWithProjectScope(config.ProjectID) + selvpcClient, err := config.GetSelVPCClientWithProjectScope(projectID) if err != nil { return nil, fmt.Errorf("can't get selvpc client for domains v2: %w", err) } @@ -35,6 +36,18 @@ func getDomainsV2Client(meta interface{}) (domainsV2.DNSClient[domainsV2.Zone, d return domainsClient, nil } +func getProjectIDFromResourceOrConfig(d *schema.ResourceData, config *Config) (string, error) { + projectID := config.ProjectID + if v, ok := d.GetOk("project_id"); ok { + projectID = v.(string) + } + if projectID == "" { + return "", ErrProjectIDNotSetupForDNSV2 + } + + return projectID, nil +} + func getZoneByName(ctx context.Context, client domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], zoneName string) (*domainsV2.Zone, error) { optsForSearchZone := map[string]string{ "filter": zoneName, diff --git a/selectel/domains_v2_test.go b/selectel/domains_v2_test.go index 73a1565d..8c45d656 100644 --- a/selectel/domains_v2_test.go +++ b/selectel/domains_v2_test.go @@ -2,14 +2,43 @@ package selectel import ( "context" + "fmt" + "net/http" "strconv" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" domainsV2 "github.com/selectel/domains-go/pkg/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) +func getDomainsV2ClientTest(rs *terraform.ResourceState, testAccProvider *schema.Provider) (domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], error) { + config := testAccProvider.Meta().(*Config) + projectID := config.ProjectID + if id, ok := rs.Primary.Attributes["project_id"]; ok { + projectID = id + } + if projectID == "" { + return nil, ErrProjectIDNotSetupForDNSV2 + } + selvpcClient, err := config.GetSelVPCClientWithProjectScope(projectID) + if err != nil { + return nil, fmt.Errorf("can't get selvpc client for domains v2: %w", err) + } + + httpClient := &http.Client{} + userAgent := "terraform-provider-selectel" + defaultApiURL := "https://api.selectel.ru/domains/v2" + hdrs := http.Header{} + hdrs.Add("X-Auth-Token", selvpcClient.GetXAuthToken()) + hdrs.Add("User-Agent", userAgent) + domainsClient := domainsV2.NewClient(defaultApiURL, httpClient, hdrs) + + return domainsClient, nil +} + type mockedDNSv2Client struct { mock.Mock domainsV2.Client @@ -55,7 +84,7 @@ func TestGetZoneByName_whenNeededZoneInResponseWithOffset(t *testing.T) { NextOffset: nextOffset, Items: []*domainsV2.Zone{ { - UUID: incorrectIDForSearch, + ID: incorrectIDForSearch, Name: incorrectNameForSearch, }, }, @@ -66,7 +95,7 @@ func TestGetZoneByName_whenNeededZoneInResponseWithOffset(t *testing.T) { NextOffset: 0, Items: []*domainsV2.Zone{ { - UUID: correctIDForSearch, + ID: correctIDForSearch, Name: nameForSearch, }, }, @@ -78,7 +107,7 @@ func TestGetZoneByName_whenNeededZoneInResponseWithOffset(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, zone) - assert.Equal(t, correctIDForSearch, zone.UUID) + assert.Equal(t, correctIDForSearch, zone.ID) assert.Equal(t, nameForSearch, zone.Name) } @@ -109,7 +138,7 @@ func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T NextOffset: nextOffset, Items: []*domainsV2.RRSet{ { - UUID: incorrectIDForSearch, + ID: incorrectIDForSearch, Name: incorrectNameForSearch, Type: domainsV2.RecordType(rrsetTypeForSearch), }, @@ -121,7 +150,7 @@ func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T NextOffset: 0, Items: []*domainsV2.RRSet{ { - UUID: correctIDForSearch, + ID: correctIDForSearch, Name: rrsetNameForSearch, Type: domainsV2.RecordType(rrsetTypeForSearch), }, @@ -134,7 +163,26 @@ func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T assert.NoError(t, err) assert.NotNil(t, rrset) - assert.Equal(t, correctIDForSearch, rrset.UUID) + assert.Equal(t, correctIDForSearch, rrset.ID) assert.Equal(t, rrsetNameForSearch, rrset.Name) assert.Equal(t, rrsetTypeForSearch, string(rrset.Type)) } + +func TestGetProjectIDFromResourceOrConfig_getProjectIDFromConfig(t *testing.T) { + expectedProjectID := "2673627" + resource := &schema.ResourceData{} + config := &Config{ + ProjectID: expectedProjectID, + } + projectID, err := getProjectIDFromResourceOrConfig(resource, config) + assert.Nil(t, err) + assert.Equal(t, expectedProjectID, projectID) +} + +func TestGetProjectIDFromResourceOrConfig_getProjectIDError(t *testing.T) { + resource := &schema.ResourceData{} + config := &Config{} + projectID, err := getProjectIDFromResourceOrConfig(resource, config) + assert.Empty(t, projectID) + assert.Equal(t, ErrProjectIDNotSetupForDNSV2, err) +} diff --git a/selectel/resource_selectel_domains_rrset_v2.go b/selectel/resource_selectel_domains_rrset_v2.go index c06d903f..b705e703 100644 --- a/selectel/resource_selectel_domains_rrset_v2.go +++ b/selectel/resource_selectel_domains_rrset_v2.go @@ -34,9 +34,13 @@ func resourceDomainsRrsetV2() *schema.Resource { Type: schema.TypeString, Required: true, }, + "project_id": { + Type: schema.TypeString, + Optional: true, + }, "comment": { Type: schema.TypeString, - Computed: true, + Optional: true, }, "managed_by": { Type: schema.TypeString, @@ -72,7 +76,7 @@ func resourceDomainsRrsetV2Create(ctx context.Context, d *schema.ResourceData, m selMutexKV.Lock(zoneID) defer selMutexKV.Unlock(zoneID) - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) } @@ -80,12 +84,12 @@ func resourceDomainsRrsetV2Create(ctx context.Context, d *schema.ResourceData, m recordType := domainsV2.RecordType(d.Get("type").(string)) recordsSet := d.Get("records").(*schema.Set) records := generateRecordsFromSet(recordsSet) - createOpts := &domainsV2.RRSet{ - Name: d.Get("name").(string), - Type: recordType, - TTL: d.Get("ttl").(int), - ZoneUUID: zoneID, - Records: records, + createOpts := domainsV2.RRSet{ + Name: d.Get("name").(string), + Type: recordType, + TTL: d.Get("ttl").(int), + ZoneID: zoneID, + Records: records, } if comment := d.Get("comment"); comment != nil { @@ -95,7 +99,7 @@ func resourceDomainsRrsetV2Create(ctx context.Context, d *schema.ResourceData, m createOpts.ManagedBy = managedBy.(string) } - rrset, err := client.CreateRRSet(ctx, zoneID, createOpts) + rrset, err := client.CreateRRSet(ctx, zoneID, &createOpts) if err != nil { return diag.FromErr(errCreatingObject(objectRrset, err)) } @@ -109,7 +113,7 @@ func resourceDomainsRrsetV2Create(ctx context.Context, d *schema.ResourceData, m } func resourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) } @@ -135,7 +139,7 @@ func resourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, met } func resourceDomainsRrsetV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return nil, err } @@ -156,7 +160,7 @@ func resourceDomainsRrsetV2ImportState(ctx context.Context, d *schema.ResourceDa return nil, err } - rrset, err := getRrsetByNameAndType(ctx, client, zone.UUID, rrsetName, rrsetType) + rrset, err := getRrsetByNameAndType(ctx, client, zone.ID, rrsetName, rrsetType) if err != nil { return nil, err } @@ -176,7 +180,7 @@ func resourceDomainsRrsetV2Update(ctx context.Context, d *schema.ResourceData, m selMutexKV.Lock(zoneID) defer selMutexKV.Unlock(zoneID) - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(errUpdatingObject(objectRrset, rrsetID, err)) } @@ -185,16 +189,18 @@ func resourceDomainsRrsetV2Update(ctx context.Context, d *schema.ResourceData, m recordsSet := d.Get("records").(*schema.Set) records := generateRecordsFromSet(recordsSet) - updateOpts := &domainsV2.RRSet{ + updateOpts := domainsV2.RRSet{ Name: d.Get("name").(string), Type: domainsV2.RecordType(d.Get("type").(string)), TTL: d.Get("ttl").(int), - ZoneUUID: zoneID, - Comment: d.Get("comment").(string), + ZoneID: zoneID, ManagedBy: d.Get("managed_by").(string), Records: records, } - err = client.UpdateRRSet(ctx, zoneID, rrsetID, updateOpts) + if comment, ok := d.GetOk("comment"); ok { + updateOpts.Comment = comment.(string) + } + err = client.UpdateRRSet(ctx, zoneID, rrsetID, &updateOpts) if err != nil { return diag.FromErr(errUpdatingObject(objectRrset, rrsetID, err)) } @@ -209,7 +215,7 @@ func resourceDomainsRrsetV2Delete(ctx context.Context, d *schema.ResourceData, m selMutexKV.Lock(zoneID) defer selMutexKV.Unlock(zoneID) - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(errDeletingObject(objectRrset, rrsetID, err)) } @@ -225,13 +231,13 @@ func resourceDomainsRrsetV2Delete(ctx context.Context, d *schema.ResourceData, m } func setRrsetToResourceData(d *schema.ResourceData, rrset *domainsV2.RRSet) error { - d.SetId(rrset.UUID) + 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.ZoneUUID) + d.Set("zone_id", rrset.ZoneID) d.Set("records", generateSetFromRecords(rrset.Records)) return nil diff --git a/selectel/resource_selectel_domains_rrset_v2_test.go b/selectel/resource_selectel_domains_rrset_v2_test.go index 6c102f0d..746a336e 100644 --- a/selectel/resource_selectel_domains_rrset_v2_test.go +++ b/selectel/resource_selectel_domains_rrset_v2_test.go @@ -71,12 +71,6 @@ func testAccDomainsRrsetV2Basic(resourceRrsetName, rrsetName, rrsetType, rrsetCo } func testAccCheckDomainsV2RrsetDestroy(s *terraform.State) error { - meta := testAccProvider.Meta() - client, err := getDomainsV2Client(meta) - if err != nil { - return err - } - ctx := context.Background() for _, rs := range s.RootModule().Resources { @@ -87,7 +81,10 @@ func testAccCheckDomainsV2RrsetDestroy(s *terraform.State) error { zoneID := rs.Primary.Attributes["zone_id"] rrsetID := rs.Primary.ID - + client, err := getDomainsV2ClientTest(rs, testAccProvider) + if err != nil { + return err + } _, err = client.GetRRSet(ctx, zoneID, rrsetID) if err == nil { return errors.New("rrset still exists") diff --git a/selectel/resource_selectel_domains_zone_v2.go b/selectel/resource_selectel_domains_zone_v2.go index 6cd156fb..a29d2c83 100644 --- a/selectel/resource_selectel_domains_zone_v2.go +++ b/selectel/resource_selectel_domains_zone_v2.go @@ -3,6 +3,7 @@ package selectel import ( "context" "log" + "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -24,10 +25,15 @@ func resourceDomainsZoneV2() *schema.Resource { Type: schema.TypeString, Required: true, }, - "comment": { + "project_id": { Type: schema.TypeString, + Optional: true, Computed: true, }, + "comment": { + Type: schema.TypeString, + Optional: true, + }, "created_at": { Type: schema.TypeString, Computed: true, @@ -48,35 +54,50 @@ func resourceDomainsZoneV2() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "project_id": { - Type: schema.TypeString, - Computed: true, - }, "disabled": { Type: schema.TypeBool, - Computed: true, + Optional: true, + Default: false, }, }, } } func resourceDomainsZoneV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) } zoneName := d.Get("name").(string) - createOpts := &domainsV2.Zone{ + createOpts := domainsV2.Zone{ Name: zoneName, } log.Println(msgCreate(objectZone, zoneName)) - zone, err := client.CreateZone(ctx, createOpts) + zone, err := client.CreateZone(ctx, &createOpts) if err != nil { return diag.FromErr(errCreatingObject(objectZone, err)) } + // Update comment after creating + // because set comment in creating request not supporting + if v, ok := d.GetOk("comment"); ok { + comment := v.(string) + err = client.UpdateZoneComment(ctx, zone.ID, comment) + if err != nil { + return diag.FromErr(errUpdatingObject(objectZone, zone.ID, err)) + } + } + // Update disabled after creating + // because set disabled in creating request not supporting + if v, ok := d.GetOk("disabled"); ok { + disabled := v.(bool) + err = client.UpdateZoneState(ctx, zone.ID, disabled) + if err != nil { + return diag.FromErr(errUpdatingObject(objectZone, zone.ID, err)) + } + } err = setZoneToResourceData(d, zone) if err != nil { @@ -87,7 +108,7 @@ func resourceDomainsZoneV2Create(ctx context.Context, d *schema.ResourceData, me } func resourceDomainsZoneV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) } @@ -109,7 +130,7 @@ func resourceDomainsZoneV2Read(ctx context.Context, d *schema.ResourceData, meta } func resourceDomainsZoneV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return nil, err } @@ -134,14 +155,16 @@ func resourceDomainsZoneV2ImportState(ctx context.Context, d *schema.ResourceDat func resourceDomainsZoneV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { zoneID := d.Id() - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(errUpdatingObject(objectZone, zoneID, err)) } if d.HasChange("comment") { - comment := d.Get("comment").(string) - + comment := "" + if v, ok := d.GetOk("comment"); ok { + comment = v.(string) + } log.Println(msgUpdate(objectZone, zoneID, comment)) err = client.UpdateZoneComment(ctx, zoneID, comment) @@ -151,8 +174,10 @@ func resourceDomainsZoneV2Update(ctx context.Context, d *schema.ResourceData, me } if d.HasChange("disabled") { - disabled := d.Get("disabled").(bool) - + disabled := false + if v, ok := d.GetOk("disabled"); ok { + disabled = v.(bool) + } log.Println(msgUpdate(objectZone, zoneID, disabled)) err = client.UpdateZoneState(ctx, zoneID, disabled) @@ -165,7 +190,7 @@ func resourceDomainsZoneV2Update(ctx context.Context, d *schema.ResourceData, me } func resourceDomainsZoneV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(meta) + client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) } @@ -183,7 +208,7 @@ func resourceDomainsZoneV2Delete(ctx context.Context, d *schema.ResourceData, me } func setZoneToResourceData(d *schema.ResourceData, zone *domainsV2.Zone) error { - d.SetId(zone.UUID) + d.SetId(zone.ID) d.Set("name", zone.Name) d.Set("comment", zone.Comment) d.Set("created_at", zone.CreatedAt.Format(time.RFC3339)) @@ -191,7 +216,7 @@ func setZoneToResourceData(d *schema.ResourceData, zone *domainsV2.Zone) error { 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", zone.ProjectID) + d.Set("project_id", strings.ReplaceAll(zone.ProjectID, "-", "")) d.Set("disabled", zone.Disabled) return nil diff --git a/selectel/resource_selectel_domains_zone_v2_test.go b/selectel/resource_selectel_domains_zone_v2_test.go index 6019bae0..d6fbeccd 100644 --- a/selectel/resource_selectel_domains_zone_v2_test.go +++ b/selectel/resource_selectel_domains_zone_v2_test.go @@ -38,12 +38,6 @@ func testAccDomainsZoneV2Basic(resourceName, zoneName string) string { } func testAccCheckDomainsV2ZoneDestroy(s *terraform.State) error { - meta := testAccProvider.Meta() - client, err := getDomainsV2Client(meta) - if err != nil { - return err - } - ctx := context.Background() for _, rs := range s.RootModule().Resources { @@ -52,7 +46,10 @@ func testAccCheckDomainsV2ZoneDestroy(s *terraform.State) error { } zoneID := rs.Primary.ID - + client, err := getDomainsV2ClientTest(rs, testAccProvider) + if err != nil { + return err + } _, err = client.GetZone(ctx, zoneID, nil) if err == nil { return errors.New("domain still exists") From 66291709448f80e9cdbf3d82df19b599f92bc550 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Fri, 26 Jan 2024 15:51:34 +0300 Subject: [PATCH 06/16] Remove "computed: true" from project_id in datasource domains_zone_v2. --- selectel/data_source_selectel_domains_zone_v2.go | 1 - 1 file changed, 1 deletion(-) diff --git a/selectel/data_source_selectel_domains_zone_v2.go b/selectel/data_source_selectel_domains_zone_v2.go index 5d6edf5f..b7bc7287 100644 --- a/selectel/data_source_selectel_domains_zone_v2.go +++ b/selectel/data_source_selectel_domains_zone_v2.go @@ -25,7 +25,6 @@ func dataSourceDomainsZoneV2() *schema.Resource { "project_id": { Type: schema.TypeString, Optional: true, - Computed: true, }, "comment": { Type: schema.TypeString, From 08378f28f83bb663f847db60e5dbddd1488a87f4 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Thu, 1 Feb 2024 16:48:47 +0300 Subject: [PATCH 07/16] Added docs. Added ForceNew for not editable fields. --- selectel/domains_v2.go | 58 +++++ selectel/provider.go | 6 +- .../resource_selectel_domains_rrset_v2.go | 45 +--- selectel/resource_selectel_domains_zone_v2.go | 19 +- .../docs/d/domains_domain_v1.html.markdown | 4 +- website/docs/d/domains_rrset_v2.html.markdown | 64 +++++ website/docs/d/domains_zone_v2.html.markdown | 54 ++++ .../docs/r/domains_domain_v1.html.markdown | 4 +- .../docs/r/domains_record_v1.html.markdown | 4 +- website/docs/r/domains_rrset_v2.html.markdown | 237 ++++++++++++++++++ website/docs/r/domains_zone_v2.html.markdown | 84 +++++++ website/selectel.erb | 12 + 12 files changed, 527 insertions(+), 64 deletions(-) create mode 100644 website/docs/d/domains_rrset_v2.html.markdown create mode 100644 website/docs/d/domains_zone_v2.html.markdown create mode 100644 website/docs/r/domains_rrset_v2.html.markdown create mode 100644 website/docs/r/domains_zone_v2.html.markdown 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 + From 59a8313e6e6ee62b43d2089aaa289e0e48bbe513 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Mon, 5 Feb 2024 14:46:53 +0300 Subject: [PATCH 08/16] Remove deprecated marks. DNSv1 is legacy. --- selectel/provider.go | 6 +++--- website/docs/d/domains_domain_v1.html.markdown | 2 +- website/docs/r/domains_domain_v1.html.markdown | 2 +- website/docs/r/domains_record_v1.html.markdown | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/selectel/provider.go b/selectel/provider.go index 4ad8912d..c1f5dfcd 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(), // DEPRECATED + "selectel_domains_domain_v1": dataSourceDomainsDomainV1(), "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(), // DEPRECATED - "selectel_domains_record_v1": resourceDomainsRecordV1(), // DEPRECATED + "selectel_domains_domain_v1": resourceDomainsDomainV1(), + "selectel_domains_record_v1": resourceDomainsRecordV1(), "selectel_domains_zone_v2": resourceDomainsZoneV2(), "selectel_domains_rrset_v2": resourceDomainsRrsetV2(), "selectel_dbaas_datastore_v1": resourceDBaaSDatastoreV1(), // DEPRECATED diff --git a/website/docs/d/domains_domain_v1.html.markdown b/website/docs/d/domains_domain_v1.html.markdown index 19adbebb..5b9934de 100644 --- a/website/docs/d/domains_domain_v1.html.markdown +++ b/website/docs/d/domains_domain_v1.html.markdown @@ -8,7 +8,7 @@ description: |- # selectel\_domains\_domain_v1 -~> **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. +~> **Note:** This is legacy 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/). diff --git a/website/docs/r/domains_domain_v1.html.markdown b/website/docs/r/domains_domain_v1.html.markdown index f01c961a..c7ee80dc 100644 --- a/website/docs/r/domains_domain_v1.html.markdown +++ b/website/docs/r/domains_domain_v1.html.markdown @@ -8,7 +8,7 @@ description: |- # selectel\_domains\_domain\_v1 -~> **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. +~> **Note:** This is legacy 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/). diff --git a/website/docs/r/domains_record_v1.html.markdown b/website/docs/r/domains_record_v1.html.markdown index 9ce0d811..bbf822bd 100644 --- a/website/docs/r/domains_record_v1.html.markdown +++ b/website/docs/r/domains_record_v1.html.markdown @@ -8,7 +8,7 @@ description: |- # selectel\_domains\_record\_v1 -~> **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. +~> **Note:** This is legacy 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/). From 3a905d75115f36f4ff8a8a8dc57304ca90cb9f17 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Tue, 6 Feb 2024 21:59:16 +0300 Subject: [PATCH 09/16] Fix linter. Resolve go.mod conflicts. Rename rrset into two styles: rrset and RRSet --- go.mod | 8 +-- go.sum | 20 +++--- .../data_source_selectel_domains_rrset_v2.go | 20 +++--- ...a_source_selectel_domains_rrset_v2_test.go | 36 +++++----- .../data_source_selectel_domains_zone_v2.go | 2 +- ...ta_source_selectel_domains_zone_v2_test.go | 10 +-- selectel/domains_v2.go | 49 +++++-------- selectel/domains_v2_test.go | 34 ++------- .../import_selectel_domains_rrset_v2_test.go | 37 +++++----- .../import_selectel_domains_zone_v2_test.go | 8 ++- selectel/provider.go | 6 +- selectel/provider_test.go | 7 -- .../resource_selectel_domains_rrset_v2.go | 71 +++++++++---------- ...resource_selectel_domains_rrset_v2_test.go | 39 +++++----- selectel/resource_selectel_domains_zone_v2.go | 10 ++- .../resource_selectel_domains_zone_v2_test.go | 17 +++-- website/docs/d/domains_rrset_v2.html.markdown | 20 +++--- website/docs/d/domains_zone_v2.html.markdown | 2 +- website/docs/r/domains_rrset_v2.html.markdown | 30 ++++---- website/docs/r/domains_zone_v2.html.markdown | 2 +- 20 files changed, 203 insertions(+), 225 deletions(-) diff --git a/go.mod b/go.mod index 2b7aca5f..59282a64 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.6.6 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/selectel/craas-go v0.3.0 - github.com/selectel/dbaas-go v0.9.0 + github.com/selectel/dbaas-go v0.10.0 github.com/selectel/domains-go v1.0.2 github.com/selectel/go-selvpcclient/v3 v3.1.1 github.com/selectel/mks-go v0.12.0 @@ -56,10 +56,10 @@ require ( github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect github.com/vmihailenco/tagparser v0.1.1 // indirect github.com/zclconf/go-cty v1.12.1 // indirect - golang.org/x/crypto v0.14.0 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/grpc v1.56.3 // indirect diff --git a/go.sum b/go.sum index 0a488940..10a05b27 100644 --- a/go.sum +++ b/go.sum @@ -151,10 +151,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/selectel/craas-go v0.3.0 h1:tXiw3LNN+ZVV0wZdeBBXX6u8kMuA5PV/5W1uYqV0yXg= github.com/selectel/craas-go v0.3.0/go.mod h1:9RAUn9PdMITP4I3GAade6v2hjB2j3lo3J2dDlG5SLYE= -github.com/selectel/dbaas-go v0.9.0 h1:IAmiyxkRtfLZg1JUdIhcsE5jpdBvsZibPCqyhB+yV30= -github.com/selectel/dbaas-go v0.9.0/go.mod h1:8D945oFzpx94v08zIb4s1bRTPCdPoNVnBu4umMYFJrQ= -github.com/selectel/domains-go v1.0.1 h1:Dau3uVlAXA3iFpeUQq2ld/aOlc8bzwdAXdVPGMwCD7Q= -github.com/selectel/domains-go v1.0.1/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA= +github.com/selectel/dbaas-go v0.10.0 h1:iY2Q7PY9ICoWBDtni+6oWGR2uAWodER0K2zchNLIOl4= +github.com/selectel/dbaas-go v0.10.0/go.mod h1:uyPhqmcvdmKBt9yWhogoSQgWkcZ9QgVlbgaERdSdAfk= github.com/selectel/domains-go v1.0.2 h1:Si6iGaMnTFJxwiJVI50DOdZnwcxc87kqaWrVQYW0a4U= github.com/selectel/domains-go v1.0.2/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA= github.com/selectel/go-selvpcclient/v3 v3.1.1 h1:C1q2LqqosiapoLpnGITGmysg0YCSQYDo2Gh69CioevM= @@ -199,8 +197,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -233,17 +231,17 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= diff --git a/selectel/data_source_selectel_domains_rrset_v2.go b/selectel/data_source_selectel_domains_rrset_v2.go index 1d5e6a80..f0fb24b5 100644 --- a/selectel/data_source_selectel_domains_rrset_v2.go +++ b/selectel/data_source_selectel_domains_rrset_v2.go @@ -11,13 +11,13 @@ import ( ) var ( - ErrRrsetNotFound = errors.New("rrset not found") - ErrFoundMultipleRRsets = errors.New("found multiple rrsets") + ErrRRSetNotFound = errors.New("rrset not found") + ErrFoundMultipleRRSets = errors.New("found multiple rrsets") ) -func dataSourceDomainsRrsetV2() *schema.Resource { +func dataSourceDomainsRRSetV2() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceDomainsRrsetV2Read, + ReadContext: dataSourceDomainsRRSetV2Read, Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -33,7 +33,7 @@ func dataSourceDomainsRrsetV2() *schema.Resource { }, "project_id": { Type: schema.TypeString, - Optional: true, + Required: true, }, "comment": { Type: schema.TypeString, @@ -67,7 +67,7 @@ func dataSourceDomainsRrsetV2() *schema.Resource { } } -func dataSourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceDomainsRRSetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) @@ -77,15 +77,15 @@ func dataSourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, m zoneID := d.Get("zone_id").(string) rrsetType := d.Get("type").(string) - zoneIDWithRrsetNameAndType := fmt.Sprintf("zone_id: %s, rrset_name: %s, rrset_type: %s", zoneID, rrsetName, rrsetType) - log.Println(msgGet(objectRrset, zoneIDWithRrsetNameAndType)) + zoneIDWithRRSetNameAndType := fmt.Sprintf("zone_id: %s, rrset_name: %s, rrset_type: %s", zoneID, rrsetName, rrsetType) + log.Println(msgGet(objectRRSet, zoneIDWithRRSetNameAndType)) - rrset, err := getRrsetByNameAndType(ctx, client, zoneID, rrsetName, rrsetType) + rrset, err := getRRSetByNameAndType(ctx, client, zoneID, rrsetName, rrsetType) if err != nil { return diag.FromErr(err) } - err = setRrsetToResourceData(d, rrset) + err = setRRSetToResourceData(d, rrset) if err != nil { return diag.FromErr(err) } diff --git a/selectel/data_source_selectel_domains_rrset_v2_test.go b/selectel/data_source_selectel_domains_rrset_v2_test.go index 88cc216c..b941935c 100644 --- a/selectel/data_source_selectel_domains_rrset_v2_test.go +++ b/selectel/data_source_selectel_domains_rrset_v2_test.go @@ -11,34 +11,35 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) -const resourceRrsetName = "rrset_tf_acc_test_1" +const resourceRRSetName = "rrset_tf_acc_test_1" -func TestAccDomainsRrsetV2DataSourceBasic(t *testing.T) { +func TestAccDomainsRRSetV2DataSourceBasic(t *testing.T) { + testProjectName := acctest.RandomWithPrefix("tf-acc") testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) - testRrsetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) - testRrsetType := domainsV2.TXT - testRrsetTTL := 60 - testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) - dataSourceRrrsetName := fmt.Sprintf("data.selectel_domains_rrset_v2.%[1]s", resourceRrsetName) + testRRSetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) + testRRSetType := domainsV2.TXT + testRRSetTTL := 60 + testRRSetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) + dataSourceRRSetName := fmt.Sprintf("data.selectel_domains_rrset_v2.%[1]s", resourceRRSetName) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + PreCheck: func() { testAccSelectelPreCheck(t) }, ProviderFactories: testAccProviders, - CheckDestroy: testAccCheckDomainsV2RrsetDestroy, + CheckDestroy: testAccCheckDomainsV2RRSetDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsRrsetV2DataSourceBasic(resourceRrsetName, testRrsetName, string(testRrsetType), testRrrsetContent, testRrsetTTL, resourceZoneName, testZoneName), + Config: testAccDomainsRRSetV2DataSourceBasic(testProjectName, resourceRRSetName, testRRSetName, string(testRRSetType), testRRSetContent, testRRSetTTL, resourceZoneName, testZoneName), Check: resource.ComposeTestCheckFunc( - testAccDomainsRrsetV2ID(dataSourceRrrsetName), - resource.TestCheckResourceAttr(dataSourceRrrsetName, "name", testRrsetName), - resource.TestCheckResourceAttr(dataSourceRrrsetName, "type", string(testRrsetType)), - resource.TestCheckResourceAttrSet(dataSourceRrrsetName, "zone_id"), + testAccDomainsRRSetV2ID(dataSourceRRSetName), + resource.TestCheckResourceAttr(dataSourceRRSetName, "name", testRRSetName), + resource.TestCheckResourceAttr(dataSourceRRSetName, "type", string(testRRSetType)), + resource.TestCheckResourceAttrSet(dataSourceRRSetName, "zone_id"), ), }, }, }) } -func testAccDomainsRrsetV2ID(name string) resource.TestCheckFunc { +func testAccDomainsRRSetV2ID(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -53,7 +54,7 @@ func testAccDomainsRrsetV2ID(name string) resource.TestCheckFunc { } } -func testAccDomainsRrsetV2DataSourceBasic(resourceRrsetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { +func testAccDomainsRRSetV2DataSourceBasic(projectName, resourceRRSetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { return fmt.Sprintf(` %[1]s @@ -63,6 +64,7 @@ func testAccDomainsRrsetV2DataSourceBasic(resourceRrsetName, rrsetName, rrsetTyp name = selectel_domains_rrset_v2.%[3]s.name type = selectel_domains_rrset_v2.%[3]s.type zone_id = selectel_domains_zone_v2.%[4]s.id + project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}" } -`, testAccDomainsZoneV2Basic(resourceZoneName, zoneName), testAccDomainsRrsetV2Basic(resourceRrsetName, rrsetName, rrsetType, rrsetContent, ttl, resourceZoneName), resourceRrsetName, resourceZoneName) +`, testAccDomainsZoneV2Basic(projectName, resourceZoneName, zoneName), testAccDomainsRRSetV2Basic(resourceRRSetName, rrsetName, rrsetType, rrsetContent, ttl, resourceZoneName), resourceRRSetName, resourceZoneName) } diff --git a/selectel/data_source_selectel_domains_zone_v2.go b/selectel/data_source_selectel_domains_zone_v2.go index b7bc7287..3b28962f 100644 --- a/selectel/data_source_selectel_domains_zone_v2.go +++ b/selectel/data_source_selectel_domains_zone_v2.go @@ -24,7 +24,7 @@ func dataSourceDomainsZoneV2() *schema.Resource { }, "project_id": { Type: schema.TypeString, - Optional: true, + Required: true, }, "comment": { Type: schema.TypeString, diff --git a/selectel/data_source_selectel_domains_zone_v2_test.go b/selectel/data_source_selectel_domains_zone_v2_test.go index dcc672b9..c0dbe4cf 100644 --- a/selectel/data_source_selectel_domains_zone_v2_test.go +++ b/selectel/data_source_selectel_domains_zone_v2_test.go @@ -14,14 +14,15 @@ import ( const resourceZoneName = "zone_tf_acc_test_1" func TestAccDomainsZoneV2DataSourceBasic(t *testing.T) { + testProjectName := acctest.RandomWithPrefix("tf-acc") testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + PreCheck: func() { testAccSelectelPreCheck(t) }, ProviderFactories: testAccProviders, CheckDestroy: testAccCheckDomainsV2ZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsZoneV2DataSourceBasic(resourceZoneName, testZoneName), + Config: testAccDomainsZoneV2DataSourceBasic(testProjectName, resourceZoneName, testZoneName), Check: resource.ComposeTestCheckFunc( testAccDomainsZoneV2Exists(fmt.Sprintf("data.selectel_domains_zone_v2.%[1]s", resourceZoneName)), resource.TestCheckResourceAttr(fmt.Sprintf("data.selectel_domains_zone_v2.%[1]s", resourceZoneName), "name", testZoneName), @@ -56,12 +57,13 @@ func testAccDomainsZoneV2Exists(name string) resource.TestCheckFunc { } } -func testAccDomainsZoneV2DataSourceBasic(resourceName, zoneName string) string { +func testAccDomainsZoneV2DataSourceBasic(projectName, resourceName, zoneName string) string { return fmt.Sprintf(` %[1]s data "selectel_domains_zone_v2" %[2]q { name = selectel_domains_zone_v2.%[2]s.name + project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}" } -`, testAccDomainsZoneV2Basic(resourceName, zoneName), resourceName, zoneName) +`, testAccDomainsZoneV2Basic(projectName, resourceName, zoneName), resourceName, zoneName) } diff --git a/selectel/domains_v2.go b/selectel/domains_v2.go index a16a37be..062055c8 100644 --- a/selectel/domains_v2.go +++ b/selectel/domains_v2.go @@ -18,10 +18,7 @@ var ErrProjectIDNotSetupForDNSV2 = errors.New("env variable SEL_PROJECT_ID or va func getDomainsV2Client(d *schema.ResourceData, meta interface{}) (domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], error) { config := meta.(*Config) - projectID, err := getProjectIDFromResourceOrConfig(d, config) - if err != nil { - return nil, fmt.Errorf("can't get projectID for domains v2: %w", err) - } + projectID := d.Get("project_id").(string) selvpcClient, err := config.GetSelVPCClientWithProjectScope(projectID) if err != nil { return nil, fmt.Errorf("can't get selvpc client for domains v2: %w", err) @@ -38,18 +35,6 @@ func getDomainsV2Client(d *schema.ResourceData, meta interface{}) (domainsV2.DNS return domainsClient, nil } -func getProjectIDFromResourceOrConfig(d *schema.ResourceData, config *Config) (string, error) { - projectID := config.ProjectID - if v, ok := d.GetOk("project_id"); ok { - projectID = v.(string) - } - if projectID == "" { - return "", ErrProjectIDNotSetupForDNSV2 - } - - return projectID, nil -} - func getZoneByName(ctx context.Context, client domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], zoneName string) (*domainsV2.Zone, error) { optsForSearchZone := map[string]string{ "filter": zoneName, @@ -81,8 +66,8 @@ func getZoneByName(ctx context.Context, client domainsV2.DNSClient[domainsV2.Zon return nil, errGettingObject(objectZone, zoneName, ErrZoneNotFound) } -func getRrsetByNameAndType(ctx context.Context, client domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], zoneID, rrsetName, rrsetType string) (*domainsV2.RRSet, error) { - optsForSearchRrset := map[string]string{ +func getRRSetByNameAndType(ctx context.Context, client domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], zoneID, rrsetName, rrsetType string) (*domainsV2.RRSet, error) { + optsForSearchRRSet := map[string]string{ "name": rrsetName, "rrset_types": rrsetType, "limit": "1000", @@ -91,26 +76,26 @@ func getRrsetByNameAndType(ctx context.Context, client domainsV2.DNSClient[domai r, err := regexp.Compile(fmt.Sprintf("^%s.?", rrsetName)) if err != nil { - return nil, errGettingObject(objectRrset, rrsetName, err) + return nil, errGettingObject(objectRRSet, rrsetName, err) } for { - rrsets, err := client.ListRRSets(ctx, zoneID, &optsForSearchRrset) + rrsets, err := client.ListRRSets(ctx, zoneID, &optsForSearchRRSet) if err != nil { - return nil, errGettingObject(objectRrset, rrsetName, err) + return nil, errGettingObject(objectRRSet, rrsetName, err) } for _, rrset := range rrsets.GetItems() { if r.MatchString(rrset.Name) && string(rrset.Type) == rrsetType { return rrset, nil } } - optsForSearchRrset["offset"] = strconv.Itoa(rrsets.GetNextOffset()) + optsForSearchRRSet["offset"] = strconv.Itoa(rrsets.GetNextOffset()) if rrsets.GetNextOffset() == 0 { break } } - return nil, errGettingObject(objectRrset, fmt.Sprintf("Name: %s. Type: %s.", rrsetName, rrsetType), ErrRrsetNotFound) + return nil, errGettingObject(objectRRSet, fmt.Sprintf("Name: %s. Type: %s.", rrsetName, rrsetType), ErrRRSetNotFound) } func setZoneToResourceData(d *schema.ResourceData, zone *domainsV2.Zone) error { @@ -128,7 +113,7 @@ func setZoneToResourceData(d *schema.ResourceData, zone *domainsV2.Zone) error { return nil } -func setRrsetToResourceData(d *schema.ResourceData, rrset *domainsV2.RRSet) error { +func setRRSetToResourceData(d *schema.ResourceData, rrset *domainsV2.RRSet) error { d.SetId(rrset.ID) d.Set("name", rrset.Name) d.Set("comment", rrset.Comment) @@ -141,7 +126,7 @@ func setRrsetToResourceData(d *schema.ResourceData, rrset *domainsV2.RRSet) erro return nil } -// generateSetFromRecords - generate terraform TypeList from records in rrset. +// generateSetFromRecords - generate terraform TypeList from records in RRSet. func generateSetFromRecords(records []domainsV2.RecordItem) []interface{} { recordsAsList := []interface{}{} for _, record := range records { @@ -154,16 +139,18 @@ func generateSetFromRecords(records []domainsV2.RecordItem) []interface{} { return recordsAsList } -// generateRecordsFromSet - generate records for Rrset from terraform TypeList. +// 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), - }) + record, isOk := recordItem.(map[string]interface{}) + if !isOk { + continue } + records = append(records, domainsV2.RecordItem{ + Content: record["content"].(string), + Disabled: record["disabled"].(bool), + }) } return records diff --git a/selectel/domains_v2_test.go b/selectel/domains_v2_test.go index 8c45d656..bcdffc42 100644 --- a/selectel/domains_v2_test.go +++ b/selectel/domains_v2_test.go @@ -16,11 +16,8 @@ import ( func getDomainsV2ClientTest(rs *terraform.ResourceState, testAccProvider *schema.Provider) (domainsV2.DNSClient[domainsV2.Zone, domainsV2.RRSet], error) { config := testAccProvider.Meta().(*Config) - projectID := config.ProjectID - if id, ok := rs.Primary.Attributes["project_id"]; ok { - projectID = id - } - if projectID == "" { + projectID, ok := rs.Primary.Attributes["project_id"] + if !ok { return nil, ErrProjectIDNotSetupForDNSV2 } selvpcClient, err := config.GetSelVPCClientWithProjectScope(projectID) @@ -30,11 +27,11 @@ func getDomainsV2ClientTest(rs *terraform.ResourceState, testAccProvider *schema httpClient := &http.Client{} userAgent := "terraform-provider-selectel" - defaultApiURL := "https://api.selectel.ru/domains/v2" + defaultAPIURL := "https://api.selectel.ru/domains/v2" hdrs := http.Header{} hdrs.Add("X-Auth-Token", selvpcClient.GetXAuthToken()) hdrs.Add("User-Agent", userAgent) - domainsClient := domainsV2.NewClient(defaultApiURL, httpClient, hdrs) + domainsClient := domainsV2.NewClient(defaultAPIURL, httpClient, hdrs) return domainsClient, nil } @@ -111,7 +108,7 @@ func TestGetZoneByName_whenNeededZoneInResponseWithOffset(t *testing.T) { assert.Equal(t, nameForSearch, zone.Name) } -func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T) { +func TestGetRRSetByNameAndType_whenNeededRRSetInResponseWithOffset(t *testing.T) { rrsetNameForSearch := "test.xyz." rrsetTypeForSearch := "A" correctIDForSearch := "mocked-uuid-2" @@ -158,7 +155,7 @@ func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T }) mDNSClient.On("ListRRSets", ctx, mockedZoneID, opts2).Return(rrsetsWithoutNextOffset, nil) - rrset, err := getRrsetByNameAndType(ctx, mDNSClient, mockedZoneID, rrsetNameForSearch, rrsetTypeForSearch) + rrset, err := getRRSetByNameAndType(ctx, mDNSClient, mockedZoneID, rrsetNameForSearch, rrsetTypeForSearch) assert.NoError(t, err) @@ -167,22 +164,3 @@ func TestGetRrsetByNameAndType_whenNeededRrrsetInResponseWithOffset(t *testing.T assert.Equal(t, rrsetNameForSearch, rrset.Name) assert.Equal(t, rrsetTypeForSearch, string(rrset.Type)) } - -func TestGetProjectIDFromResourceOrConfig_getProjectIDFromConfig(t *testing.T) { - expectedProjectID := "2673627" - resource := &schema.ResourceData{} - config := &Config{ - ProjectID: expectedProjectID, - } - projectID, err := getProjectIDFromResourceOrConfig(resource, config) - assert.Nil(t, err) - assert.Equal(t, expectedProjectID, projectID) -} - -func TestGetProjectIDFromResourceOrConfig_getProjectIDError(t *testing.T) { - resource := &schema.ResourceData{} - config := &Config{} - projectID, err := getProjectIDFromResourceOrConfig(resource, config) - assert.Empty(t, projectID) - assert.Equal(t, ErrProjectIDNotSetupForDNSV2, err) -} diff --git a/selectel/import_selectel_domains_rrset_v2_test.go b/selectel/import_selectel_domains_rrset_v2_test.go index 1dd92f01..e911bb6f 100644 --- a/selectel/import_selectel_domains_rrset_v2_test.go +++ b/selectel/import_selectel_domains_rrset_v2_test.go @@ -10,26 +10,29 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) -func TestAccDomainsRrsetV2ImportBasic(t *testing.T) { +func TestAccDomainsRRSetV2ImportBasic(t *testing.T) { + projectName := acctest.RandomWithPrefix("tf-acc") testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) - testRrsetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) - testRrsetType := domainsV2.TXT - testRrsetTTL := 60 - testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) - fullResourceName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRrsetName) + testRRSetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) + testRRSetType := domainsV2.TXT + testRRSetTTL := 60 + testRRSetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) + fullResourceName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRRSetName) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + PreCheck: func() { testAccSelectelPreCheck(t) }, ProviderFactories: testAccProviders, - CheckDestroy: testAccCheckDomainsV2ZoneDestroy, + CheckDestroy: testAccCheckVPCV2ProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsRrsetV2WithZoneBasic( - resourceRrsetName, testRrsetName, string(testRrsetType), testRrrsetContent, testRrsetTTL, + Config: testAccDomainsRRSetV2WithZoneBasic( + projectName, + resourceRRSetName, testRRSetName, string(testRRSetType), testRRSetContent, testRRSetTTL, resourceZoneName, testZoneName, ), + Check: testAccCheckSelectelImportEnv(fullResourceName), }, { - ImportStateIdFunc: getTestRrsetIDForImport, + ImportStateIdFunc: getTestRRSetIDForImport, ResourceName: fullResourceName, ImportState: true, ImportStateVerify: true, @@ -38,21 +41,21 @@ func TestAccDomainsRrsetV2ImportBasic(t *testing.T) { }) } -func getTestRrsetIDForImport(s *terraform.State) (string, error) { +func getTestRRSetIDForImport(s *terraform.State) (string, error) { resourceZoneFullName := "selectel_domains_zone_v2.zone_tf_acc_test_1" - resourceRrsetFullName := "selectel_domains_rrset_v2.rrset_tf_acc_test_1" + resourceRRSetFullName := "selectel_domains_rrset_v2.rrset_tf_acc_test_1" resourceZone, ok := s.RootModule().Resources[resourceZoneFullName] if !ok { return "", fmt.Errorf("Not found zone: %s", resourceZoneFullName) } - resourceRrset, ok := s.RootModule().Resources[resourceRrsetFullName] + resourceRRSet, ok := s.RootModule().Resources[resourceRRSetFullName] if !ok { - return "", fmt.Errorf("Not found rrset: %s", resourceRrsetFullName) + return "", fmt.Errorf("Not found rrset: %s", resourceRRSetFullName) } return fmt.Sprintf("%s/%s/%s", resourceZone.Primary.Attributes["name"], - resourceRrset.Primary.Attributes["name"], - resourceRrset.Primary.Attributes["type"], + resourceRRSet.Primary.Attributes["name"], + resourceRRSet.Primary.Attributes["type"], ), nil } diff --git a/selectel/import_selectel_domains_zone_v2_test.go b/selectel/import_selectel_domains_zone_v2_test.go index 84e934d7..2d52a90e 100644 --- a/selectel/import_selectel_domains_zone_v2_test.go +++ b/selectel/import_selectel_domains_zone_v2_test.go @@ -10,15 +10,17 @@ import ( ) func TestAccDomainsZoneV2ImportBasic(t *testing.T) { + projectName := acctest.RandomWithPrefix("tf-acc") fullResourceName := fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceZoneName) testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + PreCheck: func() { testAccSelectelPreCheck(t) }, ProviderFactories: testAccProviders, - CheckDestroy: testAccCheckDomainsV2ZoneDestroy, + CheckDestroy: testAccCheckVPCV2ProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsZoneV2Basic(resourceZoneName, testZoneName), + Config: testAccDomainsZoneV2Basic(projectName, resourceZoneName, testZoneName), + Check: testAccCheckSelectelImportEnv(fullResourceName), }, { ResourceName: fullResourceName, diff --git a/selectel/provider.go b/selectel/provider.go index c1f5dfcd..9cf8c269 100644 --- a/selectel/provider.go +++ b/selectel/provider.go @@ -25,7 +25,7 @@ const ( objectDomain = "domain" objectRecord = "record" objectZone = "zone" - objectRrset = "rrset" + objectRRSet = "rrset" objectDatastore = "datastore" objectDatabase = "database" objectGrant = "grant" @@ -101,7 +101,7 @@ func Provider() *schema.Provider { DataSourcesMap: map[string]*schema.Resource{ "selectel_domains_domain_v1": dataSourceDomainsDomainV1(), "selectel_domains_zone_v2": dataSourceDomainsZoneV2(), - "selectel_domains_rrset_v2": dataSourceDomainsRrsetV2(), + "selectel_domains_rrset_v2": dataSourceDomainsRRSetV2(), "selectel_dbaas_datastore_type_v1": dataSourceDBaaSDatastoreTypeV1(), "selectel_dbaas_available_extension_v1": dataSourceDBaaSAvailableExtensionV1(), "selectel_dbaas_flavor_v1": dataSourceDBaaSFlavorV1(), @@ -128,7 +128,7 @@ func Provider() *schema.Provider { "selectel_domains_domain_v1": resourceDomainsDomainV1(), "selectel_domains_record_v1": resourceDomainsRecordV1(), "selectel_domains_zone_v2": resourceDomainsZoneV2(), - "selectel_domains_rrset_v2": resourceDomainsRrsetV2(), + "selectel_domains_rrset_v2": resourceDomainsRRSetV2(), "selectel_dbaas_datastore_v1": resourceDBaaSDatastoreV1(), // DEPRECATED "selectel_dbaas_postgresql_datastore_v1": resourceDBaaSPostgreSQLDatastoreV1(), "selectel_dbaas_mysql_datastore_v1": resourceDBaaSMySQLDatastoreV1(), diff --git a/selectel/provider_test.go b/selectel/provider_test.go index 63ba8d82..f01b9d2a 100644 --- a/selectel/provider_test.go +++ b/selectel/provider_test.go @@ -45,13 +45,6 @@ func testAccSelectelPreCheck(t *testing.T) { } } -func testAccSelectelPreCheckWithProjectID(t *testing.T) { - testAccSelectelPreCheck(t) - if v := os.Getenv("SEL_PROJECT_ID"); v == "" { - t.Fatal("SEL_PROJECT_ID must be set for acceptance tests") - } -} - func testAccCheckSelectelImportEnv(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] diff --git a/selectel/resource_selectel_domains_rrset_v2.go b/selectel/resource_selectel_domains_rrset_v2.go index b2762819..488644d8 100644 --- a/selectel/resource_selectel_domains_rrset_v2.go +++ b/selectel/resource_selectel_domains_rrset_v2.go @@ -12,14 +12,14 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) -func resourceDomainsRrsetV2() *schema.Resource { +func resourceDomainsRRSetV2() *schema.Resource { return &schema.Resource{ - CreateContext: resourceDomainsRrsetV2Create, - ReadContext: resourceDomainsRrsetV2Read, - UpdateContext: resourceDomainsRrsetV2Update, - DeleteContext: resourceDomainsRrsetV2Delete, + CreateContext: resourceDomainsRRSetV2Create, + ReadContext: resourceDomainsRRSetV2Read, + UpdateContext: resourceDomainsRRSetV2Update, + DeleteContext: resourceDomainsRRSetV2Delete, Importer: &schema.ResourceImporter{ - StateContext: resourceDomainsRrsetV2ImportState, + StateContext: resourceDomainsRRSetV2ImportState, }, Schema: map[string]*schema.Schema{ "name": { @@ -39,7 +39,7 @@ func resourceDomainsRrsetV2() *schema.Resource { }, "project_id": { Type: schema.TypeString, - Optional: true, + Required: true, ForceNew: true, }, "comment": { @@ -75,10 +75,8 @@ func resourceDomainsRrsetV2() *schema.Resource { } } -func resourceDomainsRrsetV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceDomainsRRSetV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { zoneID := d.Get("zone_id").(string) - selMutexKV.Lock(zoneID) - defer selMutexKV.Unlock(zoneID) client, err := getDomainsV2Client(d, meta) if err != nil { @@ -105,18 +103,18 @@ func resourceDomainsRrsetV2Create(ctx context.Context, d *schema.ResourceData, m rrset, err := client.CreateRRSet(ctx, zoneID, &createOpts) if err != nil { - return diag.FromErr(errCreatingObject(objectRrset, err)) + return diag.FromErr(errCreatingObject(objectRRSet, err)) } - err = setRrsetToResourceData(d, rrset) + err = setRRSetToResourceData(d, rrset) if err != nil { - return diag.FromErr(errCreatingObject(objectRrset, err)) + return diag.FromErr(errCreatingObject(objectRRSet, err)) } return nil } -func resourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceDomainsRRSetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := getDomainsV2Client(d, meta) if err != nil { return diag.FromErr(err) @@ -124,25 +122,31 @@ func resourceDomainsRrsetV2Read(ctx context.Context, d *schema.ResourceData, met rrsetID := d.Id() zoneID := d.Get("zone_id").(string) - zoneIDWithRrsetID := fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID) + zoneIDWithRRSetID := fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID) - log.Print(msgGet(objectRrset, zoneIDWithRrsetID)) + log.Print(msgGet(objectRRSet, zoneIDWithRRSetID)) rrset, err := client.GetRRSet(ctx, zoneID, rrsetID) if err != nil { d.SetId("") - return diag.FromErr(errGettingObject(objectRrset, zoneIDWithRrsetID, err)) + return diag.FromErr(errGettingObject(objectRRSet, zoneIDWithRRSetID, err)) } - err = setRrsetToResourceData(d, rrset) + err = setRRSetToResourceData(d, rrset) if err != nil { - return diag.FromErr(errGettingObject(objectRrset, zoneIDWithRrsetID, err)) + return diag.FromErr(errGettingObject(objectRRSet, zoneIDWithRRSetID, err)) } return nil } -func resourceDomainsRrsetV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceDomainsRRSetV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if config.ProjectID == "" { + return nil, errors.New("SEL_PROJECT_ID must be set for the resource import") + } + d.Set("project_id", config.ProjectID) + client, err := getDomainsV2Client(d, meta) if err != nil { return nil, err @@ -157,19 +161,19 @@ func resourceDomainsRrsetV2ImportState(ctx context.Context, d *schema.ResourceDa rrsetName := parts[1] rrsetType := parts[2] - log.Print(msgImport(objectRrset, fmt.Sprintf("%s/%s/%s", zoneName, rrsetName, rrsetType))) + log.Print(msgImport(objectRRSet, fmt.Sprintf("%s/%s/%s", zoneName, rrsetName, rrsetType))) zone, err := getZoneByName(ctx, client, zoneName) if err != nil { return nil, err } - rrset, err := getRrsetByNameAndType(ctx, client, zone.ID, rrsetName, rrsetType) + rrset, err := getRRSetByNameAndType(ctx, client, zone.ID, rrsetName, rrsetType) if err != nil { return nil, err } - err = setRrsetToResourceData(d, rrset) + err = setRRSetToResourceData(d, rrset) if err != nil { return nil, err } @@ -177,16 +181,13 @@ func resourceDomainsRrsetV2ImportState(ctx context.Context, d *schema.ResourceDa return []*schema.ResourceData{d}, nil } -func resourceDomainsRrsetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceDomainsRRSetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { rrsetID := d.Id() zoneID := d.Get("zone_id").(string) - selMutexKV.Lock(zoneID) - defer selMutexKV.Unlock(zoneID) - client, err := getDomainsV2Client(d, meta) if err != nil { - return diag.FromErr(errUpdatingObject(objectRrset, rrsetID, err)) + return diag.FromErr(errUpdatingObject(objectRRSet, rrsetID, err)) } if d.HasChanges("ttl", "comment", "records") { @@ -206,29 +207,27 @@ func resourceDomainsRrsetV2Update(ctx context.Context, d *schema.ResourceData, m } err = client.UpdateRRSet(ctx, zoneID, rrsetID, &updateOpts) if err != nil { - return diag.FromErr(errUpdatingObject(objectRrset, rrsetID, err)) + return diag.FromErr(errUpdatingObject(objectRRSet, rrsetID, err)) } } - return resourceDomainsRrsetV2Read(ctx, d, meta) + return resourceDomainsRRSetV2Read(ctx, d, meta) } -func resourceDomainsRrsetV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceDomainsRRSetV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { zoneID := d.Get("zone_id").(string) rrsetID := d.Id() - selMutexKV.Lock(zoneID) - defer selMutexKV.Unlock(zoneID) client, err := getDomainsV2Client(d, meta) if err != nil { - return diag.FromErr(errDeletingObject(objectRrset, rrsetID, err)) + return diag.FromErr(errDeletingObject(objectRRSet, rrsetID, err)) } - log.Print(msgDelete(objectRrset, fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID))) + log.Print(msgDelete(objectRRSet, fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID))) err = client.DeleteRRSet(ctx, zoneID, rrsetID) if err != nil { - return diag.FromErr(errDeletingObject(objectRrset, rrsetID, err)) + return diag.FromErr(errDeletingObject(objectRRSet, rrsetID, err)) } return nil diff --git a/selectel/resource_selectel_domains_rrset_v2_test.go b/selectel/resource_selectel_domains_rrset_v2_test.go index 746a336e..3c14c292 100644 --- a/selectel/resource_selectel_domains_rrset_v2_test.go +++ b/selectel/resource_selectel_domains_rrset_v2_test.go @@ -13,34 +13,35 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) -func TestAccDomainsRrsetV2Basic(t *testing.T) { +func TestAccDomainsRRSetV2Basic(t *testing.T) { + projectName := acctest.RandomWithPrefix("tf-acc") testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) - testRrsetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) - testRrsetType := domainsV2.TXT - testRrsetTTL := 60 - testRrrsetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) + testRRSetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) + testRRSetType := domainsV2.TXT + testRRSetTTL := 60 + testRRSetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) resourceZoneName := "zone_tf_acc_test_1" - resourceRrsetName := "rrset_tf_acc_test_1" - dataSourceRrrsetName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRrsetName) + resourceRRSetName := "rrset_tf_acc_test_1" + dataSourceRRSetName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRRSetName) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + PreCheck: func() { testAccSelectelPreCheck(t) }, ProviderFactories: testAccProviders, CheckDestroy: testAccCheckDomainsV2ZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsRrsetV2WithZoneBasic(resourceRrsetName, testRrsetName, string(testRrsetType), testRrrsetContent, testRrsetTTL, resourceZoneName, testZoneName), + Config: testAccDomainsRRSetV2WithZoneBasic(projectName, resourceRRSetName, testRRSetName, string(testRRSetType), testRRSetContent, testRRSetTTL, resourceZoneName, testZoneName), Check: resource.ComposeTestCheckFunc( - testAccDomainsRrsetV2ID(dataSourceRrrsetName), - resource.TestCheckResourceAttr(dataSourceRrrsetName, "name", testRrsetName), - resource.TestCheckResourceAttr(dataSourceRrrsetName, "type", string(testRrsetType)), - resource.TestCheckResourceAttrSet(dataSourceRrrsetName, "zone_id"), + testAccDomainsRRSetV2ID(dataSourceRRSetName), + resource.TestCheckResourceAttr(dataSourceRRSetName, "name", testRRSetName), + resource.TestCheckResourceAttr(dataSourceRRSetName, "type", string(testRRSetType)), + resource.TestCheckResourceAttrSet(dataSourceRRSetName, "zone_id"), ), }, }, }) } -func testAccDomainsRrsetV2WithZoneBasic(resourceRrsetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { +func testAccDomainsRRSetV2WithZoneBasic(projectName, resourceRRSetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { return fmt.Sprintf(` %[7]s @@ -49,28 +50,30 @@ func testAccDomainsRrsetV2WithZoneBasic(resourceRrsetName, rrsetName, rrsetType, type = %[3]q ttl = %[4]d zone_id = selectel_domains_zone_v2.%[6]s.id + project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}" records { content = %[5]q disabled = false } - }`, resourceRrsetName, rrsetName, rrsetType, ttl, rrsetContent, resourceZoneName, testAccDomainsZoneV2Basic(resourceZoneName, zoneName)) + }`, resourceRRSetName, rrsetName, rrsetType, ttl, rrsetContent, resourceZoneName, testAccDomainsZoneV2Basic(projectName, resourceZoneName, zoneName)) } -func testAccDomainsRrsetV2Basic(resourceRrsetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName string) string { +func testAccDomainsRRSetV2Basic(resourceRRSetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName string) string { return fmt.Sprintf(` resource "selectel_domains_rrset_v2" %[1]q { name = %[2]q type = %[3]q ttl = %[4]d zone_id = selectel_domains_zone_v2.%[5]s.id + project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}" records { content = %[6]q disabled = false } - }`, resourceRrsetName, rrsetName, rrsetType, ttl, resourceZoneName, rrsetContent) + }`, resourceRRSetName, rrsetName, rrsetType, ttl, resourceZoneName, rrsetContent) } -func testAccCheckDomainsV2RrsetDestroy(s *terraform.State) error { +func testAccCheckDomainsV2RRSetDestroy(s *terraform.State) error { ctx := context.Background() for _, rs := range s.RootModule().Resources { diff --git a/selectel/resource_selectel_domains_zone_v2.go b/selectel/resource_selectel_domains_zone_v2.go index 1473208b..4246111b 100644 --- a/selectel/resource_selectel_domains_zone_v2.go +++ b/selectel/resource_selectel_domains_zone_v2.go @@ -2,6 +2,7 @@ package selectel import ( "context" + "errors" "log" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -26,8 +27,7 @@ func resourceDomainsZoneV2() *schema.Resource { }, "project_id": { Type: schema.TypeString, - Optional: true, - Computed: true, + Required: true, ForceNew: true, }, "comment": { @@ -130,6 +130,12 @@ func resourceDomainsZoneV2Read(ctx context.Context, d *schema.ResourceData, meta } func resourceDomainsZoneV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if config.ProjectID == "" { + return nil, errors.New("SEL_PROJECT_ID must be set for the resource import") + } + d.Set("project_id", config.ProjectID) + client, err := getDomainsV2Client(d, meta) if err != nil { return nil, err diff --git a/selectel/resource_selectel_domains_zone_v2_test.go b/selectel/resource_selectel_domains_zone_v2_test.go index d6fbeccd..e451629e 100644 --- a/selectel/resource_selectel_domains_zone_v2_test.go +++ b/selectel/resource_selectel_domains_zone_v2_test.go @@ -12,15 +12,16 @@ import ( ) func TestAccDomainsZoneV2Basic(t *testing.T) { + projectName := acctest.RandomWithPrefix("tf-acc") testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) resourceZoneName := "zone_tf_acc_test_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, + PreCheck: func() { testAccSelectelPreCheck(t) }, ProviderFactories: testAccProviders, CheckDestroy: testAccCheckDomainsV2ZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsZoneV2Basic(resourceZoneName, testZoneName), + Config: testAccDomainsZoneV2Basic(projectName, resourceZoneName, testZoneName), Check: resource.ComposeTestCheckFunc( testAccDomainsZoneV2Exists(fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceZoneName)), resource.TestCheckResourceAttr(fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceZoneName), "name", testZoneName), @@ -30,11 +31,15 @@ func TestAccDomainsZoneV2Basic(t *testing.T) { }) } -func testAccDomainsZoneV2Basic(resourceName, zoneName string) string { +func testAccDomainsZoneV2Basic(projectName, resourceName, zoneName string) string { return fmt.Sprintf(` - resource "selectel_domains_zone_v2" %[1]q { - name = %[2]q - }`, resourceName, zoneName) + resource "selectel_vpc_project_v2" "project_tf_acc_test_1" { + name = %[1]q + } + resource "selectel_domains_zone_v2" %[2]q { + name = %[3]q + project_id = selectel_vpc_project_v2.project_tf_acc_test_1.id + }`, projectName, resourceName, zoneName) } func testAccCheckDomainsV2ZoneDestroy(s *terraform.State) error { diff --git a/website/docs/d/domains_rrset_v2.html.markdown b/website/docs/d/domains_rrset_v2.html.markdown index ee46a559..2828114e 100644 --- a/website/docs/d/domains_rrset_v2.html.markdown +++ b/website/docs/d/domains_rrset_v2.html.markdown @@ -3,12 +3,12 @@ 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. + 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/). +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 @@ -33,29 +33,29 @@ data "selectel_domains_rrset_v2" "rrset_1" { ## Argument Reference -* `name` - (Required) Rrset name. +* `name` - (Required) RRSet name. -* `type` - (Required) Rrset type. +* `type` - (Required) RRSet type. * `zone_id` - (Required) Zone ID. -* `project_id` - (Optional) Selectel project ID. +* `project_id` - (Required) Selectel project ID. ## Attributes Reference -* `name` - Rrset name. +* `name` - RRSet name. -* `type` - Rrset type. +* `type` - RRSet type. * `zone_id` - Zone ID. * `project_id` - Selectel project ID. -* `ttl` - Rrset TTL. +* `ttl` - RRSet TTL. -* `comment` - Comment for rrset. +* `comment` - Comment for RRSet. -* `managed_by` - Rrset owner. +* `managed_by` - RRSet owner. * `records` - Set of records: diff --git a/website/docs/d/domains_zone_v2.html.markdown b/website/docs/d/domains_zone_v2.html.markdown index f2f63d4b..97b03f61 100644 --- a/website/docs/d/domains_zone_v2.html.markdown +++ b/website/docs/d/domains_zone_v2.html.markdown @@ -31,7 +31,7 @@ data "selectel_domains_zone_v2" "zone_1" { * `name` - (Required) Zone name. -* `project_id` - (Optional) Selectel project ID. +* `project_id` - (Required) Selectel project ID. ## Attributes Reference diff --git a/website/docs/r/domains_rrset_v2.html.markdown b/website/docs/r/domains_rrset_v2.html.markdown index 71d7edf5..46d8ae4e 100644 --- a/website/docs/r/domains_rrset_v2.html.markdown +++ b/website/docs/r/domains_rrset_v2.html.markdown @@ -3,12 +3,12 @@ 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. + 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/). +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 @@ -170,11 +170,11 @@ resource "selectel_domains_rrset_v2" "caa_rrset_1" { * `zone_id` - (Required) Zone ID. -* `name` - (Required) Name of the zone rrset. The name format depends on the rrset type, see the examples above. +* `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. +* `type` - (Required) Type of the RRSet. -* `ttl` - (Required) Time-to-live for the rrset in seconds. The available range is from 60 to 604800. +* `ttl` - (Required) Time-to-live for the RRSet in seconds. The available range is from 60 to 604800. * `records` - (Required) Set of records: @@ -182,19 +182,19 @@ resource "selectel_domains_rrset_v2" "caa_rrset_1" { * `disabled` - (Optional, default: false) Shows if record available or not. -* `project_id` - (Optional) Selectel project ID. +* `project_id` - (Required) Selectel project ID. -* `comment` - (Optional) Comment for rrset. +* `comment` - (Optional) Comment for RRSet. ## Attributes Reference * `zone_id` - Zone ID. -* `name` - Name of the rrset. +* `name` - Name of the RRSet. -* `type` - Type of the rrset. +* `type` - Type of the RRSet. -* `ttl` - Time-to-live for the rrset in seconds. +* `ttl` - Time-to-live for the RRSet in seconds. * `records` - Set of records: @@ -204,13 +204,13 @@ resource "selectel_domains_rrset_v2" "caa_rrset_1" { * `project_id` - Selectel project ID. -* `comment` - Comment for rrset. +* `comment` - Comment for RRSet. -* `managed_by` - Rrset owner. +* `managed_by` - RRSet owner. ## Import -You can import a rrset: +You can import a RRSet: ```shell export OS_DOMAIN_NAME= @@ -232,6 +232,6 @@ where: * `` — Zone name. -* `` — Rrset name. +* `` — RRSet name. -* `` — Type of rrset. +* `` — Type of RRSet. diff --git a/website/docs/r/domains_zone_v2.html.markdown b/website/docs/r/domains_zone_v2.html.markdown index 23fc28ce..50d74a65 100644 --- a/website/docs/r/domains_zone_v2.html.markdown +++ b/website/docs/r/domains_zone_v2.html.markdown @@ -31,7 +31,7 @@ resource "selectel_domains_zone_v2" "zone_1" { * `name` - (Required) Zone name. Changing this creates a new zone name. -* `project_id` - (Optional) Selectel project id. Scope for creating zone. +* `project_id` - (Required) Selectel project id. Scope for creating zone. * `comment` - (Optional) Comment for zone. From 42c5c5c3712e9022235322ddbdc29ce62435849f Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Tue, 6 Feb 2024 23:14:29 +0300 Subject: [PATCH 10/16] Fix acceptance tests for import domains_v2 resources --- .../import_selectel_domains_rrset_v2_test.go | 28 +++++++++++++++---- .../import_selectel_domains_zone_v2_test.go | 18 ++++++++---- selectel/provider_test.go | 7 +++++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/selectel/import_selectel_domains_rrset_v2_test.go b/selectel/import_selectel_domains_rrset_v2_test.go index e911bb6f..ae7aecf8 100644 --- a/selectel/import_selectel_domains_rrset_v2_test.go +++ b/selectel/import_selectel_domains_rrset_v2_test.go @@ -2,6 +2,7 @@ package selectel import ( "fmt" + "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -11,7 +12,7 @@ import ( ) func TestAccDomainsRRSetV2ImportBasic(t *testing.T) { - projectName := acctest.RandomWithPrefix("tf-acc") + projectID := os.Getenv("SEL_PROJECT_ID") testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) testRRSetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) testRRSetType := domainsV2.TXT @@ -19,17 +20,16 @@ func TestAccDomainsRRSetV2ImportBasic(t *testing.T) { testRRSetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) fullResourceName := fmt.Sprintf("selectel_domains_rrset_v2.%[1]s", resourceRRSetName) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheck(t) }, + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, ProviderFactories: testAccProviders, - CheckDestroy: testAccCheckVPCV2ProjectDestroy, + CheckDestroy: testAccCheckDomainsV2RRSetDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsRRSetV2WithZoneBasic( - projectName, + Config: testAccDomainsRRSetV2WithZoneWithoutProjectBasic( + projectID, resourceRRSetName, testRRSetName, string(testRRSetType), testRRSetContent, testRRSetTTL, resourceZoneName, testZoneName, ), - Check: testAccCheckSelectelImportEnv(fullResourceName), }, { ImportStateIdFunc: getTestRRSetIDForImport, @@ -59,3 +59,19 @@ func getTestRRSetIDForImport(s *terraform.State) (string, error) { resourceRRSet.Primary.Attributes["type"], ), nil } + +func testAccDomainsRRSetV2WithZoneWithoutProjectBasic(projectID, resourceRRSetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { + return fmt.Sprintf(` + %[8]s + resource "selectel_domains_rrset_v2" %[1]q { + name = %[2]q + project_id = %[7]q + type = %[3]q + ttl = %[4]d + zone_id = selectel_domains_zone_v2.%[6]s.id + records { + content = %[5]q + disabled = false + } + }`, resourceRRSetName, rrsetName, rrsetType, ttl, rrsetContent, resourceZoneName, projectID, testAccDomainsZoneV2WithoutProjectBasic(projectID, resourceZoneName, zoneName)) +} diff --git a/selectel/import_selectel_domains_zone_v2_test.go b/selectel/import_selectel_domains_zone_v2_test.go index 2d52a90e..1ee1695d 100644 --- a/selectel/import_selectel_domains_zone_v2_test.go +++ b/selectel/import_selectel_domains_zone_v2_test.go @@ -2,6 +2,7 @@ package selectel import ( "fmt" + "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -10,17 +11,16 @@ import ( ) func TestAccDomainsZoneV2ImportBasic(t *testing.T) { - projectName := acctest.RandomWithPrefix("tf-acc") + projectID := os.Getenv("SEL_PROJECT_ID") fullResourceName := fmt.Sprintf("selectel_domains_zone_v2.%[1]s", resourceZoneName) testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheck(t) }, + PreCheck: func() { testAccSelectelPreCheckWithProjectID(t) }, ProviderFactories: testAccProviders, - CheckDestroy: testAccCheckVPCV2ProjectDestroy, + CheckDestroy: testAccCheckDomainsV2ZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDomainsZoneV2Basic(projectName, resourceZoneName, testZoneName), - Check: testAccCheckSelectelImportEnv(fullResourceName), + Config: testAccDomainsZoneV2WithoutProjectBasic(projectID, resourceZoneName, testZoneName), }, { ResourceName: fullResourceName, @@ -41,3 +41,11 @@ func getTestZoneIDForImport(s *terraform.State) (string, error) { return resourceZone.Primary.Attributes["name"], nil } + +func testAccDomainsZoneV2WithoutProjectBasic(projectID, resourceName, zoneName string) string { + return fmt.Sprintf(` + resource "selectel_domains_zone_v2" %[2]q { + name = %[3]q + project_id = %[1]q + }`, projectID, resourceName, zoneName) +} diff --git a/selectel/provider_test.go b/selectel/provider_test.go index f01b9d2a..63ba8d82 100644 --- a/selectel/provider_test.go +++ b/selectel/provider_test.go @@ -45,6 +45,13 @@ func testAccSelectelPreCheck(t *testing.T) { } } +func testAccSelectelPreCheckWithProjectID(t *testing.T) { + testAccSelectelPreCheck(t) + if v := os.Getenv("SEL_PROJECT_ID"); v == "" { + t.Fatal("SEL_PROJECT_ID must be set for acceptance tests") + } +} + func testAccCheckSelectelImportEnv(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] From 34e655db5d6b30f5f1b43d9684670ea31228aa79 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Fri, 9 Feb 2024 11:36:50 +0300 Subject: [PATCH 11/16] Update examples in docs. project_id required --- website/docs/d/domains_rrset_v2.html.markdown | 10 ---------- website/docs/d/domains_zone_v2.html.markdown | 8 -------- website/docs/r/domains_rrset_v2.html.markdown | 10 ++++++++++ website/docs/r/domains_zone_v2.html.markdown | 8 -------- 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/website/docs/d/domains_rrset_v2.html.markdown b/website/docs/d/domains_rrset_v2.html.markdown index 2828114e..6088de88 100644 --- a/website/docs/d/domains_rrset_v2.html.markdown +++ b/website/docs/d/domains_rrset_v2.html.markdown @@ -12,16 +12,6 @@ Provides a RRSet info in DNS Hosting. For more information about RRSet in DNS Ho ## 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." diff --git a/website/docs/d/domains_zone_v2.html.markdown b/website/docs/d/domains_zone_v2.html.markdown index 97b03f61..2781e376 100644 --- a/website/docs/d/domains_zone_v2.html.markdown +++ b/website/docs/d/domains_zone_v2.html.markdown @@ -12,14 +12,6 @@ Provides a zone info in DNS Hosting (API v2). For more information about zones i ## 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." diff --git a/website/docs/r/domains_rrset_v2.html.markdown b/website/docs/r/domains_rrset_v2.html.markdown index 46d8ae4e..edca1cb5 100644 --- a/website/docs/r/domains_rrset_v2.html.markdown +++ b/website/docs/r/domains_rrset_v2.html.markdown @@ -20,6 +20,7 @@ resource "selectel_domains_rrset_v2" "a_rrset_1" { name = "a.example.com." type = "A" ttl = 60 + ptoject_id = "project_id" records { content = "127.0.0.1" } @@ -39,6 +40,7 @@ resource "selectel_domains_rrset_v2" "aaaa_rrset_1" { name = "aaaa.example.com." type = "AAAA" ttl = 60 + ptoject_id = "project_id" records { content = "2400:cb00:2049:1::a29f:1804" } @@ -54,6 +56,7 @@ resource "selectel_domains_rrset_v2" "txt_rrset_1" { name = "txt.example.com." type = "TXT" ttl = 60 + ptoject_id = "project_id" records { content = "\"hello, world!\"" } @@ -68,6 +71,7 @@ resource "selectel_domains_rrset_v2" "cname_rrset_1" { name = "cname.example.com." type = "CNAME" ttl = 60 + ptoject_id = "project_id" records { content = "origin.com." } @@ -82,6 +86,7 @@ resource "selectel_domains_rrset_v2" "ns_rrset_1" { name = "example.com." type = "NS" ttl = 86400 + ptoject_id = "project_id" records { content = "ns5.selectel.org" } @@ -98,6 +103,7 @@ resource "selectel_domains_rrset_v2" "mx_rrset_1" { name = "mx.example.com." type = "MX" ttl = 60 + ptoject_id = "project_id" records { content = "10 mail.example.org." } @@ -114,6 +120,7 @@ resource "selectel_domains_rrset_v2" "srv_rrset_1" { name = "_sip._tcp.example.com." type = "SRV" ttl = 120 + ptoject_id = "project_id" records { content = "10 20 30 mail.example.org." } @@ -130,6 +137,7 @@ resource "selectel_domains_rrset_v2" "sshfp_rrset_1" { name = "sshfp.example.com." type = "SSHFP" ttl = 60 + ptoject_id = "project_id" records { content = "1 1 7491973e5f8b39d5327cd4e08bc81b05f7710b49" } @@ -144,6 +152,7 @@ resource "selectel_domains_rrset_v2" "alias_rrset_1" { name = "example1.com." type = "ALIAS" ttl = 60 + ptoject_id = "project_id" records { content = "example2.com." } @@ -160,6 +169,7 @@ resource "selectel_domains_rrset_v2" "caa_rrset_1" { name = "example.com." type = "CAA" ttl = 60 + ptoject_id = "project_id" records { content = "128 issue \"letsencrypt.com.\"" } diff --git a/website/docs/r/domains_zone_v2.html.markdown b/website/docs/r/domains_zone_v2.html.markdown index 50d74a65..3293e073 100644 --- a/website/docs/r/domains_zone_v2.html.markdown +++ b/website/docs/r/domains_zone_v2.html.markdown @@ -12,14 +12,6 @@ Creates and manages a zone in DNS Hosting using public API v2. For more informat ## 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." From 5f3bd5eeef8d655290f5c1dba2228f7c61ece196 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Tue, 13 Feb 2024 14:42:33 +0300 Subject: [PATCH 12/16] Added comments in import functions for domains_v2 resources. Used d.Id() instead of creating new variable with name resourceID. --- .../resource_selectel_domains_rrset_v2.go | 24 ++++++++--------- selectel/resource_selectel_domains_zone_v2.go | 26 +++++++++---------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/selectel/resource_selectel_domains_rrset_v2.go b/selectel/resource_selectel_domains_rrset_v2.go index 488644d8..4f625c1f 100644 --- a/selectel/resource_selectel_domains_rrset_v2.go +++ b/selectel/resource_selectel_domains_rrset_v2.go @@ -120,13 +120,12 @@ func resourceDomainsRRSetV2Read(ctx context.Context, d *schema.ResourceData, met return diag.FromErr(err) } - rrsetID := d.Id() zoneID := d.Get("zone_id").(string) - zoneIDWithRRSetID := fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID) + zoneIDWithRRSetID := fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, d.Id()) log.Print(msgGet(objectRRSet, zoneIDWithRRSetID)) - rrset, err := client.GetRRSet(ctx, zoneID, rrsetID) + rrset, err := client.GetRRSet(ctx, zoneID, d.Id()) if err != nil { d.SetId("") return diag.FromErr(errGettingObject(objectRRSet, zoneIDWithRRSetID, err)) @@ -151,7 +150,8 @@ func resourceDomainsRRSetV2ImportState(ctx context.Context, d *schema.ResourceDa if err != nil { return nil, err } - + // concat zone_name,rrset_name,rrset_type with symbol "/" instead of rrset id for importing rrset. + // example: terraform import domains_rrset_v2. // parts := strings.Split(d.Id(), "/") if len(parts) != 3 { return nil, errors.New("id must include three parts: zone_name/rrset_name/rrset_type") @@ -182,12 +182,11 @@ func resourceDomainsRRSetV2ImportState(ctx context.Context, d *schema.ResourceDa } func resourceDomainsRRSetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - rrsetID := d.Id() zoneID := d.Get("zone_id").(string) client, err := getDomainsV2Client(d, meta) if err != nil { - return diag.FromErr(errUpdatingObject(objectRRSet, rrsetID, err)) + return diag.FromErr(errUpdatingObject(objectRRSet, d.Id(), err)) } if d.HasChanges("ttl", "comment", "records") { @@ -205,9 +204,9 @@ func resourceDomainsRRSetV2Update(ctx context.Context, d *schema.ResourceData, m if comment, ok := d.GetOk("comment"); ok { updateOpts.Comment = comment.(string) } - err = client.UpdateRRSet(ctx, zoneID, rrsetID, &updateOpts) + err = client.UpdateRRSet(ctx, zoneID, d.Id(), &updateOpts) if err != nil { - return diag.FromErr(errUpdatingObject(objectRRSet, rrsetID, err)) + return diag.FromErr(errUpdatingObject(objectRRSet, d.Id(), err)) } } @@ -216,18 +215,17 @@ func resourceDomainsRRSetV2Update(ctx context.Context, d *schema.ResourceData, m func resourceDomainsRRSetV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { zoneID := d.Get("zone_id").(string) - rrsetID := d.Id() client, err := getDomainsV2Client(d, meta) if err != nil { - return diag.FromErr(errDeletingObject(objectRRSet, rrsetID, err)) + return diag.FromErr(errDeletingObject(objectRRSet, d.Id(), err)) } - log.Print(msgDelete(objectRRSet, fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, rrsetID))) + log.Print(msgDelete(objectRRSet, fmt.Sprintf("zone_id: %s, rrset_id: %s", zoneID, d.Id()))) - err = client.DeleteRRSet(ctx, zoneID, rrsetID) + err = client.DeleteRRSet(ctx, zoneID, d.Id()) if err != nil { - return diag.FromErr(errDeletingObject(objectRRSet, rrsetID, err)) + return diag.FromErr(errDeletingObject(objectRRSet, d.Id(), err)) } return nil diff --git a/selectel/resource_selectel_domains_zone_v2.go b/selectel/resource_selectel_domains_zone_v2.go index 4246111b..3c2393a3 100644 --- a/selectel/resource_selectel_domains_zone_v2.go +++ b/selectel/resource_selectel_domains_zone_v2.go @@ -141,6 +141,8 @@ func resourceDomainsZoneV2ImportState(ctx context.Context, d *schema.ResourceDat return nil, err } + // use zone name instead of zone id for importing zone. + // example: terraform import domains_zone_v2. zoneName := d.Id() log.Println(msgImport(objectZone, zoneName)) @@ -159,11 +161,9 @@ func resourceDomainsZoneV2ImportState(ctx context.Context, d *schema.ResourceDat } func resourceDomainsZoneV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - zoneID := d.Id() - client, err := getDomainsV2Client(d, meta) if err != nil { - return diag.FromErr(errUpdatingObject(objectZone, zoneID, err)) + return diag.FromErr(errUpdatingObject(objectZone, d.Id(), err)) } if d.HasChange("comment") { @@ -171,11 +171,11 @@ func resourceDomainsZoneV2Update(ctx context.Context, d *schema.ResourceData, me if v, ok := d.GetOk("comment"); ok { comment = v.(string) } - log.Println(msgUpdate(objectZone, zoneID, comment)) + log.Println(msgUpdate(objectZone, d.Id(), comment)) - err = client.UpdateZoneComment(ctx, zoneID, comment) + err = client.UpdateZoneComment(ctx, d.Id(), comment) if err != nil { - return diag.FromErr(errUpdatingObject(objectZone, zoneID, err)) + return diag.FromErr(errUpdatingObject(objectZone, d.Id(), err)) } } @@ -184,11 +184,11 @@ func resourceDomainsZoneV2Update(ctx context.Context, d *schema.ResourceData, me if v, ok := d.GetOk("disabled"); ok { disabled = v.(bool) } - log.Println(msgUpdate(objectZone, zoneID, disabled)) + log.Println(msgUpdate(objectZone, d.Id(), disabled)) - err = client.UpdateZoneState(ctx, zoneID, disabled) + err = client.UpdateZoneState(ctx, d.Id(), disabled) if err != nil { - return diag.FromErr(errUpdatingObject(objectZone, zoneID, err)) + return diag.FromErr(errUpdatingObject(objectZone, d.Id(), err)) } } @@ -201,13 +201,11 @@ func resourceDomainsZoneV2Delete(ctx context.Context, d *schema.ResourceData, me return diag.FromErr(err) } - zoneID := d.Id() - - log.Println(msgDelete(objectZone, zoneID)) + log.Println(msgDelete(objectZone, d.Id())) - err = client.DeleteZone(ctx, zoneID) + err = client.DeleteZone(ctx, d.Id()) if err != nil { - return diag.FromErr(errDeletingObject(objectZone, zoneID, err)) + return diag.FromErr(errDeletingObject(objectZone, d.Id(), err)) } return nil From 5fa55d50ebd8cc2e4ef344390314760da2b05567 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Thu, 22 Feb 2024 02:17:04 +0300 Subject: [PATCH 13/16] Fix docs for domains --- .../docs/d/domains_domain_v1.html.markdown | 6 +- website/docs/d/domains_rrset_v2.html.markdown | 36 ++- website/docs/d/domains_zone_v2.html.markdown | 28 +-- .../docs/r/domains_domain_v1.html.markdown | 5 +- .../docs/r/domains_record_v1.html.markdown | 19 +- website/docs/r/domains_rrset_v2.html.markdown | 213 ++++++++---------- website/docs/r/domains_zone_v2.html.markdown | 42 ++-- 7 files changed, 153 insertions(+), 196 deletions(-) diff --git a/website/docs/d/domains_domain_v1.html.markdown b/website/docs/d/domains_domain_v1.html.markdown index 5b9934de..773c9c25 100644 --- a/website/docs/d/domains_domain_v1.html.markdown +++ b/website/docs/d/domains_domain_v1.html.markdown @@ -3,14 +3,14 @@ layout: "selectel" page_title: "Selectel: selectel_domains_domain_v1" sidebar_current: "docs-selectel-datasource-domains-domain-v1" description: |- - Provides an ID of a domain in Selectel DNS Hosting. + Provides an ID of a domain in Selectel DNS Hosting (legacy). --- # selectel\_domains\_domain_v1 -~> **Note:** This is legacy 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. +**WARNING**: This data source is applicable to DNS Hosting (legacy). We do not support and develop DNS Hosting (legacy), but domains and records created in DNS Hosting (legacy) continue to work until further notice. We recommend to transfer your data to DNS Hosting (actual). For more infomation about DNS Hosting (actual), see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/about-dns/). -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/). +Provides an ID of a domain in DNS Hosting (legacy). 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 index 6088de88..8fd46283 100644 --- a/website/docs/d/domains_rrset_v2.html.markdown +++ b/website/docs/d/domains_rrset_v2.html.markdown @@ -3,21 +3,21 @@ 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. + Provides information about an RRSet in Selectel DNS Hosting (actual). --- # 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/). +Provides information about an RRSet in DNS Hosting (actual). For more information about RRSets, 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" - ptoject_id = "project_id" + name = "example.com." + type = "A" + zone_id = selectel_domains_zone_v2.zone_1.id + project_id = selectel_vpc_project_v2.project_1.id } ``` @@ -25,30 +25,22 @@ data "selectel_domains_rrset_v2" "rrset_1" { * `name` - (Required) RRSet name. -* `type` - (Required) RRSet type. +* `type` - (Required) RRSet type. Available types are `A`, `AAAA`, `TXT`, `CNAME`, `NS`, `MX`, `SRV`, `SSHFP`, `ALIAS`, `CAA`. -* `zone_id` - (Required) Zone ID. +* `zone_id` - (Required) (Required) Unique identifier of the zone. Retrieved from the [selectel_domains_zone_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_zone_v2) resource. -* `project_id` - (Required) Selectel project ID. +* `project_id` - (Required) Unique identifier of the associated Cloud Platform project. Retrieved from the [selectel_vpc_project_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/vpc_project_v2) resource. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). ## Attributes Reference -* `name` - RRSet name. +* `ttl` - RRSet time-to-live in seconds. -* `type` - RRSet type. - -* `zone_id` - Zone ID. - -* `project_id` - Selectel project ID. - -* `ttl` - RRSet TTL. - -* `comment` - Comment for RRSet. +* `comment` - Comment for the RRSet. * `managed_by` - RRSet owner. -* `records` - Set of records: +* `records` - List of records in the RRSet. - * `content` - Value for record. + * `content` - Record value. - * `disabled` - Shows if record available or not. + * `disabled` - Shows if the record is enabled or disabled. diff --git a/website/docs/d/domains_zone_v2.html.markdown b/website/docs/d/domains_zone_v2.html.markdown index 2781e376..076fa545 100644 --- a/website/docs/d/domains_zone_v2.html.markdown +++ b/website/docs/d/domains_zone_v2.html.markdown @@ -3,19 +3,19 @@ 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. + Provides information about a zone in Selectel DNS Hosting (actual). --- # 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/). +Provides information about a zone in Selectel DNS Hosting (actual). For more information about zones, 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." - project_id = "project_id" + name = "example.com." + project_id = selectel_vpc_project_v2.project_1.id } ``` @@ -23,24 +23,20 @@ data "selectel_domains_zone_v2" "zone_1" { * `name` - (Required) Zone name. -* `project_id` - (Required) Selectel project ID. +* `project_id` - (Required) Unique identifier of the associated Cloud Platform project. Retrieved from the [selectel_vpc_project_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/vpc_project_v2) resource. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). ## Attributes Reference - -* `name` - Zone name. -* `project_id` - Selectel project id. +* `comment` - Comment for the zone. -* `comment` - Comment for zone. +* `created_at` - Time when the zone was created in RFC 3339 timestamp format. -* `created_at` - Timestamp when zone was created. +* `updated_at` - Time when the zone was updated in RFC 3339 timestamp format. -* `updated_at` - Timestamp when zone was updated. +* `delegation_checked_at` - Time when DNS Hosting checked if the zone was delegated to Selectel NS servers in RFC 3339 timestamp format. -* `delegation_checked_at` - Timestamp of last delegation status check. +* `last_check_status` - Zone status retrieved during the last delegation check. -* `last_check_status` - Shows if zone delegated to selectel NS servers or not. +* `last_delegated_at` - Equals to the `delegation_check_at` argument value when the `last_check_status` is `true`. -* `last_delegated_at` - Timestamp of last delegation status check when zone was delegated to selectel NS server. - -* `disabled` - Shows if zone available or not. +* `disabled` - Shows if the zone is enabled or disabled. diff --git a/website/docs/r/domains_domain_v1.html.markdown b/website/docs/r/domains_domain_v1.html.markdown index c7ee80dc..0f680ccd 100644 --- a/website/docs/r/domains_domain_v1.html.markdown +++ b/website/docs/r/domains_domain_v1.html.markdown @@ -8,9 +8,10 @@ description: |- # selectel\_domains\_domain\_v1 -~> **Note:** This is legacy 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. +**WARNING**: This resource is applicable to DNS Hosting (legacy). We do not support and develop DNS Hosting (legacy), but domains and records created in DNS Hosting (legacy) continue to work until further notice. We recommend to transfer your data to DNS Hosting (actual). For more infomation about DNS Hosting (actual), see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/about-dns/). +To create zones for your domain records in DNS Hosting (actual) use the [selectel_domains_zone_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/selectel_domains_zone_v2) resource. -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/). +Creates and manages a domain in DNS Hosting (legacy) 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 bbf822bd..63eebb0b 100644 --- a/website/docs/r/domains_record_v1.html.markdown +++ b/website/docs/r/domains_record_v1.html.markdown @@ -8,9 +8,10 @@ description: |- # selectel\_domains\_record\_v1 -~> **Note:** This is legacy 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. +**WARNING**: This resource is applicable to DNS Hosting (legacy). We do not support and develop DNS Hosting (legacy), but domains and records created in DNS Hosting (legacy) continue to work until further notice. We recommend to transfer your data to DNS Hosting (actual). For more infomation about DNS Hosting (actual), see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/about-dns/). +To create records in DNS Hosting (actual) use the [selectel_domains_rrset_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/selectel_domains_rrset_v2) resource. -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/). +Creates and manages a record in DNS Hosting (legacy) using public API v1. For more information about records, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/records/). ## Example usage @@ -19,7 +20,7 @@ Creates and manages a record in DNS Hosting using public API v1. For more inform ```hcl resource "selectel_domains_record_v1" "a_record_1" { domain_id = selectel_domains_domain_v1.domain_1.id - name = "a.example.com" + name = "example.com" type = "A" content = "127.0.0.1" ttl = 60 @@ -31,7 +32,7 @@ resource "selectel_domains_record_v1" "a_record_1" { ```hcl resource "selectel_domains_record_v1" "aaaa_record_1" { domain_id = selectel_domains_domain_v1.domain_1.id - name = "aaaa.example.com" + name = "example.com" type = "AAAA" content = "2400:cb00:2049:1::a29f:1804" ttl = 60 @@ -43,7 +44,7 @@ resource "selectel_domains_record_v1" "aaaa_record_1" { ```hcl resource "selectel_domains_record_v1" "txt_record_1" { domain_id = selectel_domains_domain_v1.domain_1.id - name = "txt.example.com" + name = "example.com" type = "TXT" content = "hello, world!" ttl = 60 @@ -55,7 +56,7 @@ resource "selectel_domains_record_v1" "txt_record_1" { ```hcl resource "selectel_domains_record_v1" "cname_record_1" { domain_id = selectel_domains_domain_v1.domain_1.id - name = "cname.example.com" + name = "example.com" type = "CNAME" content = "origin.com" ttl = 60 @@ -79,7 +80,7 @@ resource "selectel_domains_record_v1" "ns_record_1" { ```hcl resource "selectel_domains_record_v1" "mx_record_1" { domain_id = selectel_domains_domain_v1.domain_1.id - name = "mx.example.com" + name = "example.com" type = "MX" content = "mail.example.org" ttl = 60 @@ -92,12 +93,12 @@ resource "selectel_domains_record_v1" "mx_record_1" { ```hcl resource "selectel_domains_record_v1" "srv_record_1" { domain_id = selectel_domains_domain_v1.domain_1.id - name = "srv.example.com" + name = "example.com" type = "SRV" ttl = 120 priority = 10 weight = 20 - target = "backupbox.example.com" + target = "example.com" port = 100 } ``` diff --git a/website/docs/r/domains_rrset_v2.html.markdown b/website/docs/r/domains_rrset_v2.html.markdown index edca1cb5..c41cab2b 100644 --- a/website/docs/r/domains_rrset_v2.html.markdown +++ b/website/docs/r/domains_rrset_v2.html.markdown @@ -3,12 +3,12 @@ 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. + Creates and manages an RRSet in Selectel DNS Hosting (actual) 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/). +Creates and manages an RRSet in DNS Hosting (actual) using public API v2. For more information about RRSets, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/records/). ## Example usage @@ -16,50 +16,47 @@ Creates and manages a RRSet in DNS Hosting using public API v2. For more informa ```hcl resource "selectel_domains_rrset_v2" "a_rrset_1" { - zone_id = "zone_id" - name = "a.example.com." - type = "A" - ttl = 60 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." + type = "A" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id records { - content = "127.0.0.1" - } - records { - content = "127.0.0.2" - disabled = true + content = "127.0.0.1" + # The content value is "" } } - ``` ### AAAA RRSet ```hcl resource "selectel_domains_rrset_v2" "aaaa_rrset_1" { - zone_id = "zone_id" - name = "aaaa.example.com." - type = "AAAA" - ttl = 60 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." + type = "AAAA" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id records { content = "2400:cb00:2049:1::a29f:1804" - } + # The content value is "" + } } - ``` ### TXT RRSet ```hcl resource "selectel_domains_rrset_v2" "txt_rrset_1" { - zone_id = "zone_id" - name = "txt.example.com." - type = "TXT" - ttl = 60 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." + type = "TXT" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id records { - content = "\"hello, world!\"" - } + content = "\"hello, world!\"" + # The content value is "" + } } ``` @@ -67,79 +64,62 @@ resource "selectel_domains_rrset_v2" "txt_rrset_1" { ```hcl resource "selectel_domains_rrset_v2" "cname_rrset_1" { - zone_id = "zone_id" - name = "cname.example.com." - type = "CNAME" - ttl = 60 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." + type = "CNAME" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id 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 - ptoject_id = "project_id" - records { - content = "ns5.selectel.org" + # The content value is "" } } ``` ### 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 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." + type = "MX" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id records { content = "10 mail.example.org." + # The content value is " " } } ``` ### 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 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "_sip._tcp.example.com." + type = "SRV" + ttl = 120 + project_id = selectel_vpc_project_v2.project_1.id records { - content = "10 20 30 mail.example.org." + content = "10 20 30 example.org." + # The content value is " " } } ``` ### 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." + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." type = "SSHFP" - ttl = 60 - ptoject_id = "project_id" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id records { - content = "1 1 7491973e5f8b39d5327cd4e08bc81b05f7710b49" + content = "1 1 7491973e5f8b39d5327cd4e08bc81b05f7710b49" + # The content value is " " } } ``` @@ -148,85 +128,82 @@ resource "selectel_domains_rrset_v2" "sshfp_rrset_1" { ```hcl resource "selectel_domains_rrset_v2" "alias_rrset_1" { - zone_id = "zone_id" - name = "example1.com." - type = "ALIAS" - ttl = 60 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." + type = "ALIAS" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id records { - content = "example2.com." + content = "origin.com." + # The content value is "" } } ``` ### 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 - ptoject_id = "project_id" + zone_id = selectel_domains_zone_v2.zone_1.id + name = "example.com." + type = "CAA" + ttl = 60 + project_id = selectel_vpc_project_v2.project_1.id records { content = "128 issue \"letsencrypt.com.\"" + # The content value is " " } } ``` ## Argument Reference -* `zone_id` - (Required) Zone ID. +* `zone_id` - (Required) Unique identifier of the zone. Changing this creates a new RRSet. Retrieved from the [selectel_domains_zone_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_zone_v2) resource. -* `name` - (Required) Name of the zone RRSet. The name format depends on the RRSet type, see the examples above. +* `name` - (Required) RRSet name. Changing this creates a new RRSet. The value must be the same as the zone name. If `type` is `SRV`, the name must also include service and protocol, see the [example usage for SRV RRSet](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_rrset_v2#srv-rrset). Changing this creates a new RRSet. -* `type` - (Required) Type of the RRSet. +* `type` - (Required) RRSet type. Changing this creates a new RRSet. Available types are `A`, `AAAA`, `TXT`, `CNAME`, `MX`, `SRV`, `SSHFP`, `ALIAS`, `CAA`. -* `ttl` - (Required) Time-to-live for the RRSet in seconds. The available range is from 60 to 604800. +* `ttl` - (Required) RRSet time-to-live in seconds. The available range is from 60 to 604800. -* `records` - (Required) Set of records: +* `records` - (Required) List of records in the RRSet. - * `content` - (Required) Value for record. - - * `disabled` - (Optional, default: false) Shows if record available or not. - -* `project_id` - (Required) Selectel project ID. - -* `comment` - (Optional) Comment for RRSet. + * `content` - (Required) Record value. The value depends on the RRSet type. + - `` — IPv4-address. Applicable only to A RRSets. + - `` — IPv6-address. Applicable only to AAAA RRSets. + - `` — Any text wrapped in `\"`. Applicable only to TXT RRSets. + - `` — Canonical name of the host providing the service with a dot at the end. Applicable only to CNAME, ALIAS, and SRV RRSets. + - `` — Canonical name of the NS server. Applicable only to NS RRSets. + - `` — Priority of the records preferences. Applicable only to MX and SRV RRSets. Lower value means more preferred. + - `` — Name of the mailserver with a dot at the end. Applicable only to MX RRSets. + - `` — Weight for the records with the same priority. Higher value means more preferred. Applicable only to SRV RRSets. + - `` — TCP or UDP port of the host of the service. Applicable only to SRV RRSets. + - `` — Algorithm of the public key. Applicable only to SSHFP RRSets. Available values are `1` for RSA, `2` for DSA, `3` for ECDSA, `4` for Ed25519. + - `` — Algorithm used to hash the public key. Applicable only to SSHFP RRSets. Available values are `1` for SHA-1, `2` for SHA-256. + - `` — Hexadecimal representation of the hash result, as text. Applicable only to SSHFP RRSets. + - `` — Critical value that has a specific meaning per RFC. Applicable only to CAA RRSets. The available range is from 0 to 128. + - `` — Identifier of the property represented by the record. Applicable only to CAA RRSets. Available values are `issue`, `issuewild`, `iodef`, `auth`, `path`, `policy`. + - `` — Value associated with the tag wrapped in `\"`. Applicable only to CAA RRSets. + + * `disabled` - (Optional) Enables or disables the record. Boolean flag, the default value is false. + +* `project_id` - (Required) Unique identifier of the associated Cloud Platform project. Changing this creates a new RRSet. Retrieved from the [selectel_vpc_project_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/vpc_project_v2) resource. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). + +* `comment` - (Optional) Comment to add to the 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: +You can import an RRSet: ```shell export OS_DOMAIN_NAME= export OS_USERNAME= export OS_PASSWORD= -export SEL_PROJECT_ID= +export SEL_PROJECT_ID= terraform import selectel_domains_rrset_v2.rrset_1 // ``` @@ -238,10 +215,10 @@ where: * `` — Password of the service user. -* `` — Selectel project ID. +* `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/craas/about/projects/). -* `` — Zone name. +* `` — Zone name, for example, example.com. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. -* `` — RRSet name. +* `` — RRSet name, for example, example.com.. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS** → the zone page. The RRSet name is in the **Group name** column. -* `` — Type of RRSet. +* `` — RRSet type. To get the type, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS** → the zone page. The RRSet type is in the **Type** column. diff --git a/website/docs/r/domains_zone_v2.html.markdown b/website/docs/r/domains_zone_v2.html.markdown index 3293e073..9987518b 100644 --- a/website/docs/r/domains_zone_v2.html.markdown +++ b/website/docs/r/domains_zone_v2.html.markdown @@ -3,53 +3,43 @@ 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. + Creates and manages a zone in Selectel DNS Hosting (actual) 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/). +Creates and manages a zone in DNS Hosting (actual) 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." - project_id = "project_id" + name = "example.com." + project_id = selectel_vpc_project_v2.project_1.id } ``` ## Argument Reference -* `name` - (Required) Zone name. Changing this creates a new zone name. +* `name` - (Required) Zone name. Changing this creates a new zone. -* `project_id` - (Required) Selectel project id. Scope for creating zone. +* `project_id` - (Required) Unique identifier of the associated Cloud Platform project. Retrieved from the [selectel_vpc_project_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/vpc_project_v2) resource. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). -* `comment` - (Optional) Comment for zone. +* `comment` - (Optional) Comment to add to the zone. -* `disabled` - (Optional) Set zone available or not. +* `disabled` - (Optional) Enables or disables the zone. Boolean flag, the default value is false. ## Attributes Reference -* `id` - Unique identifier of the zone. +* `created_at` - Time when the zone was created in RFC 3339 timestamp format. -* `name` - Zone name. +* `updated_at` - Time when the zone was updated in RFC 3339 timestamp format. -* `project_id` - Selectel project id. +* `delegation_checked_at` - Time when DNS Hosting checked if the zone was delegated to Selectel NS servers in RFC 3339 timestamp format. -* `comment` - Comment for zone. +* `last_check_status` - Zone status retrieved during the last delegation check. -* `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. +* `last_delegated_at` - Equals to the `delegation_check_at` argument value when the `last_check_status` is `true`. ## Import @@ -59,7 +49,7 @@ You can import a zone: export OS_DOMAIN_NAME= export OS_USERNAME= export OS_PASSWORD= -export SEL_PROJECT_ID= +export SEL_PROJECT_ID= terraform import selectel_domains_zone_v2.zone_1 ``` @@ -71,6 +61,6 @@ where: * `` — Password of the service user. -* `` — Selectel project ID. +* `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/craas/about/projects/). -* `` — Zone name. +* `` — Zone name, for example, example.com. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. From b113a5a73b83b0ff22bc03ea919b3a8d339611bd Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Thu, 22 Feb 2024 15:15:34 +0300 Subject: [PATCH 14/16] Fix docs in domains --- website/docs/d/domains_domain_v1.html.markdown | 2 +- website/docs/d/domains_rrset_v2.html.markdown | 2 +- website/docs/r/domains_rrset_v2.html.markdown | 6 +++--- website/docs/r/domains_zone_v2.html.markdown | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/website/docs/d/domains_domain_v1.html.markdown b/website/docs/d/domains_domain_v1.html.markdown index 773c9c25..1819b9aa 100644 --- a/website/docs/d/domains_domain_v1.html.markdown +++ b/website/docs/d/domains_domain_v1.html.markdown @@ -10,7 +10,7 @@ description: |- **WARNING**: This data source is applicable to DNS Hosting (legacy). We do not support and develop DNS Hosting (legacy), but domains and records created in DNS Hosting (legacy) continue to work until further notice. We recommend to transfer your data to DNS Hosting (actual). For more infomation about DNS Hosting (actual), see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/about-dns/). -Provides an ID of a domain in DNS Hosting (legacy). For more information about domains in DNS Hosting, see the [official Selectel documentation](https://docs.selectel.ru/networks-services/dns/zones/). +Provides an ID of a domain in DNS Hosting (legacy). ## Example Usage diff --git a/website/docs/d/domains_rrset_v2.html.markdown b/website/docs/d/domains_rrset_v2.html.markdown index 8fd46283..ad7e4b0a 100644 --- a/website/docs/d/domains_rrset_v2.html.markdown +++ b/website/docs/d/domains_rrset_v2.html.markdown @@ -27,7 +27,7 @@ data "selectel_domains_rrset_v2" "rrset_1" { * `type` - (Required) RRSet type. Available types are `A`, `AAAA`, `TXT`, `CNAME`, `NS`, `MX`, `SRV`, `SSHFP`, `ALIAS`, `CAA`. -* `zone_id` - (Required) (Required) Unique identifier of the zone. Retrieved from the [selectel_domains_zone_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_zone_v2) resource. +* `zone_id` - (Required) Unique identifier of the zone. Retrieved from the [selectel_domains_zone_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_zone_v2) resource. * `project_id` - (Required) Unique identifier of the associated Cloud Platform project. Retrieved from the [selectel_vpc_project_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/vpc_project_v2) resource. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). diff --git a/website/docs/r/domains_rrset_v2.html.markdown b/website/docs/r/domains_rrset_v2.html.markdown index c41cab2b..be00781a 100644 --- a/website/docs/r/domains_rrset_v2.html.markdown +++ b/website/docs/r/domains_rrset_v2.html.markdown @@ -160,7 +160,7 @@ resource "selectel_domains_rrset_v2" "caa_rrset_1" { * `zone_id` - (Required) Unique identifier of the zone. Changing this creates a new RRSet. Retrieved from the [selectel_domains_zone_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_zone_v2) resource. -* `name` - (Required) RRSet name. Changing this creates a new RRSet. The value must be the same as the zone name. If `type` is `SRV`, the name must also include service and protocol, see the [example usage for SRV RRSet](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_rrset_v2#srv-rrset). Changing this creates a new RRSet. +* `name` - (Required) RRSet name. Changing this creates a new RRSet. The value must be the same as the zone name. If `type` is `SRV`, the name must also include service and protocol, see the [example usage for SRV RRSet](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_rrset_v2#srv-rrset). * `type` - (Required) RRSet type. Changing this creates a new RRSet. Available types are `A`, `AAAA`, `TXT`, `CNAME`, `MX`, `SRV`, `SSHFP`, `ALIAS`, `CAA`. @@ -217,8 +217,8 @@ where: * `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/craas/about/projects/). -* `` — Zone name, for example, example.com. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. +* `` — Zone name, for example, `example.com.`. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. -* `` — RRSet name, for example, example.com.. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS** → the zone page. The RRSet name is in the **Group name** column. +* `` — RRSet name, for example, `example.com.`. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS** → the zone page. The RRSet name is in the **Group name** column. * `` — RRSet type. To get the type, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS** → the zone page. The RRSet type is in the **Type** column. diff --git a/website/docs/r/domains_zone_v2.html.markdown b/website/docs/r/domains_zone_v2.html.markdown index 9987518b..239d2296 100644 --- a/website/docs/r/domains_zone_v2.html.markdown +++ b/website/docs/r/domains_zone_v2.html.markdown @@ -63,4 +63,4 @@ where: * `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/craas/about/projects/). -* `` — Zone name, for example, example.com. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. +* `` — Zone name, for example, `example.com.`. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. From dd21ccfe0d87f41dd018dbbb9466ede9e920bf7e Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Thu, 22 Feb 2024 16:38:46 +0300 Subject: [PATCH 15/16] Fix docs for domains --- website/docs/d/domains_zone_v2.html.markdown | 6 +++--- website/docs/r/domains_zone_v2.html.markdown | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/website/docs/d/domains_zone_v2.html.markdown b/website/docs/d/domains_zone_v2.html.markdown index 076fa545..003954f4 100644 --- a/website/docs/d/domains_zone_v2.html.markdown +++ b/website/docs/d/domains_zone_v2.html.markdown @@ -29,11 +29,11 @@ data "selectel_domains_zone_v2" "zone_1" { * `comment` - Comment for the zone. -* `created_at` - Time when the zone was created in RFC 3339 timestamp format. +* `created_at` - Time when the zone was created in the RFC 3339 timestamp format. -* `updated_at` - Time when the zone was updated in RFC 3339 timestamp format. +* `updated_at` - Time when the zone was updated in the RFC 3339 timestamp format. -* `delegation_checked_at` - Time when DNS Hosting checked if the zone was delegated to Selectel NS servers in RFC 3339 timestamp format. +* `delegation_checked_at` - Time when DNS Hosting checked if the zone was delegated to Selectel NS servers in the RFC 3339 timestamp format. * `last_check_status` - Zone status retrieved during the last delegation check. diff --git a/website/docs/r/domains_zone_v2.html.markdown b/website/docs/r/domains_zone_v2.html.markdown index 239d2296..6b44dc20 100644 --- a/website/docs/r/domains_zone_v2.html.markdown +++ b/website/docs/r/domains_zone_v2.html.markdown @@ -31,11 +31,11 @@ resource "selectel_domains_zone_v2" "zone_1" { ## Attributes Reference -* `created_at` - Time when the zone was created in RFC 3339 timestamp format. +* `created_at` - Time when the zone was created in the RFC 3339 timestamp format. -* `updated_at` - Time when the zone was updated in RFC 3339 timestamp format. +* `updated_at` - Time when the zone was updated in the RFC 3339 timestamp format. -* `delegation_checked_at` - Time when DNS Hosting checked if the zone was delegated to Selectel NS servers in RFC 3339 timestamp format. +* `delegation_checked_at` - Time when DNS Hosting checked if the zone was delegated to Selectel NS servers in the RFC 3339 timestamp format. * `last_check_status` - Zone status retrieved during the last delegation check. From 6ccebf5995e4d5729129f7c85470a9debbf729a8 Mon Sep 17 00:00:00 2001 From: Dmitrii Chudinov Date: Mon, 26 Feb 2024 11:30:04 +0300 Subject: [PATCH 16/16] Remove domains_v2 datasources with docs --- .../data_source_selectel_domains_rrset_v2.go | 94 ------------------- ...a_source_selectel_domains_rrset_v2_test.go | 70 -------------- .../data_source_selectel_domains_zone_v2.go | 82 ---------------- ...ta_source_selectel_domains_zone_v2_test.go | 69 -------------- selectel/provider.go | 2 - .../resource_selectel_domains_rrset_v2.go | 2 + ...resource_selectel_domains_rrset_v2_test.go | 32 ++++--- selectel/resource_selectel_domains_zone_v2.go | 2 + .../resource_selectel_domains_zone_v2_test.go | 27 ++++++ website/docs/d/domains_rrset_v2.html.markdown | 46 --------- website/docs/d/domains_zone_v2.html.markdown | 42 --------- website/docs/r/domains_rrset_v2.html.markdown | 2 +- website/docs/r/domains_zone_v2.html.markdown | 2 +- website/selectel.erb | 6 -- 14 files changed, 50 insertions(+), 428 deletions(-) delete mode 100644 selectel/data_source_selectel_domains_rrset_v2.go delete mode 100644 selectel/data_source_selectel_domains_rrset_v2_test.go delete mode 100644 selectel/data_source_selectel_domains_zone_v2.go delete mode 100644 selectel/data_source_selectel_domains_zone_v2_test.go delete mode 100644 website/docs/d/domains_rrset_v2.html.markdown delete mode 100644 website/docs/d/domains_zone_v2.html.markdown diff --git a/selectel/data_source_selectel_domains_rrset_v2.go b/selectel/data_source_selectel_domains_rrset_v2.go deleted file mode 100644 index f0fb24b5..00000000 --- a/selectel/data_source_selectel_domains_rrset_v2.go +++ /dev/null @@ -1,94 +0,0 @@ -package selectel - -import ( - "context" - "errors" - "fmt" - "log" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -var ( - ErrRRSetNotFound = errors.New("rrset not found") - ErrFoundMultipleRRSets = errors.New("found multiple rrsets") -) - -func dataSourceDomainsRRSetV2() *schema.Resource { - return &schema.Resource{ - ReadContext: dataSourceDomainsRRSetV2Read, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - "type": { - Type: schema.TypeString, - Required: true, - }, - "zone_id": { - Type: schema.TypeString, - Required: true, - }, - "project_id": { - Type: schema.TypeString, - Required: true, - }, - "comment": { - Type: schema.TypeString, - Computed: true, - }, - "managed_by": { - Type: schema.TypeString, - Computed: true, - }, - "ttl": { - Type: schema.TypeInt, - Computed: true, - }, - "records": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "content": { - Type: schema.TypeString, - Computed: true, - }, - "disabled": { - Type: schema.TypeBool, - Computed: true, - }, - }, - }, - }, - }, - } -} - -func dataSourceDomainsRRSetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(d, meta) - if err != nil { - return diag.FromErr(err) - } - - rrsetName := d.Get("name").(string) - zoneID := d.Get("zone_id").(string) - rrsetType := d.Get("type").(string) - - zoneIDWithRRSetNameAndType := fmt.Sprintf("zone_id: %s, rrset_name: %s, rrset_type: %s", zoneID, rrsetName, rrsetType) - log.Println(msgGet(objectRRSet, zoneIDWithRRSetNameAndType)) - - rrset, err := getRRSetByNameAndType(ctx, client, zoneID, rrsetName, rrsetType) - if err != nil { - return diag.FromErr(err) - } - - err = setRRSetToResourceData(d, rrset) - if err != nil { - return diag.FromErr(err) - } - - return nil -} diff --git a/selectel/data_source_selectel_domains_rrset_v2_test.go b/selectel/data_source_selectel_domains_rrset_v2_test.go deleted file mode 100644 index b941935c..00000000 --- a/selectel/data_source_selectel_domains_rrset_v2_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package selectel - -import ( - "errors" - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - domainsV2 "github.com/selectel/domains-go/pkg/v2" -) - -const resourceRRSetName = "rrset_tf_acc_test_1" - -func TestAccDomainsRRSetV2DataSourceBasic(t *testing.T) { - testProjectName := acctest.RandomWithPrefix("tf-acc") - testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) - testRRSetName := fmt.Sprintf("%[1]s.%[2]s", acctest.RandomWithPrefix("tf-acc"), testZoneName) - testRRSetType := domainsV2.TXT - testRRSetTTL := 60 - testRRSetContent := fmt.Sprintf("\"%[1]s\"", acctest.RandString(16)) - dataSourceRRSetName := fmt.Sprintf("data.selectel_domains_rrset_v2.%[1]s", resourceRRSetName) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheck(t) }, - ProviderFactories: testAccProviders, - CheckDestroy: testAccCheckDomainsV2RRSetDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDomainsRRSetV2DataSourceBasic(testProjectName, resourceRRSetName, testRRSetName, string(testRRSetType), testRRSetContent, testRRSetTTL, resourceZoneName, testZoneName), - Check: resource.ComposeTestCheckFunc( - testAccDomainsRRSetV2ID(dataSourceRRSetName), - resource.TestCheckResourceAttr(dataSourceRRSetName, "name", testRRSetName), - resource.TestCheckResourceAttr(dataSourceRRSetName, "type", string(testRRSetType)), - resource.TestCheckResourceAttrSet(dataSourceRRSetName, "zone_id"), - ), - }, - }, - }) -} - -func testAccDomainsRRSetV2ID(name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - if !ok { - return fmt.Errorf("can't find rrset: %s", name) - } - - if rs.Primary.ID == "" { - return errors.New("rrset data source ID not set") - } - - return nil - } -} - -func testAccDomainsRRSetV2DataSourceBasic(projectName, resourceRRSetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName, zoneName string) string { - return fmt.Sprintf(` - %[1]s - - %[2]s - - data "selectel_domains_rrset_v2" %[3]q { - name = selectel_domains_rrset_v2.%[3]s.name - type = selectel_domains_rrset_v2.%[3]s.type - zone_id = selectel_domains_zone_v2.%[4]s.id - project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}" - } -`, testAccDomainsZoneV2Basic(projectName, resourceZoneName, zoneName), testAccDomainsRRSetV2Basic(resourceRRSetName, rrsetName, rrsetType, rrsetContent, ttl, resourceZoneName), resourceRRSetName, resourceZoneName) -} diff --git a/selectel/data_source_selectel_domains_zone_v2.go b/selectel/data_source_selectel_domains_zone_v2.go deleted file mode 100644 index 3b28962f..00000000 --- a/selectel/data_source_selectel_domains_zone_v2.go +++ /dev/null @@ -1,82 +0,0 @@ -package selectel - -import ( - "context" - "errors" - "log" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -var ( - ErrZoneNotFound = errors.New("zone not found") - ErrFoundMultipleZones = errors.New("found multiple zones") -) - -func dataSourceDomainsZoneV2() *schema.Resource { - return &schema.Resource{ - ReadContext: dataSourceDomainsZoneV2Read, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - "project_id": { - Type: schema.TypeString, - Required: true, - }, - "comment": { - Type: schema.TypeString, - Computed: true, - }, - "created_at": { - Type: schema.TypeString, - Computed: true, - }, - "updated_at": { - Type: schema.TypeString, - Computed: true, - }, - "delegation_checked_at": { - Type: schema.TypeString, - Computed: true, - }, - "last_check_status": { - Type: schema.TypeBool, - Computed: true, - }, - "last_delegated_at": { - Type: schema.TypeString, - Computed: true, - }, - "disabled": { - Type: schema.TypeBool, - Computed: true, - }, - }, - } -} - -func dataSourceDomainsZoneV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - client, err := getDomainsV2Client(d, meta) - if err != nil { - return diag.FromErr(err) - } - - zoneName := d.Get("name").(string) - - log.Println(msgGet(objectZone, zoneName)) - - zone, err := getZoneByName(ctx, client, zoneName) - if err != nil { - return diag.FromErr(err) - } - - err = setZoneToResourceData(d, zone) - if err != nil { - return diag.FromErr(errGettingObject(objectZone, zoneName, err)) - } - - return nil -} diff --git a/selectel/data_source_selectel_domains_zone_v2_test.go b/selectel/data_source_selectel_domains_zone_v2_test.go deleted file mode 100644 index c0dbe4cf..00000000 --- a/selectel/data_source_selectel_domains_zone_v2_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package selectel - -import ( - "context" - "errors" - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -const resourceZoneName = "zone_tf_acc_test_1" - -func TestAccDomainsZoneV2DataSourceBasic(t *testing.T) { - testProjectName := acctest.RandomWithPrefix("tf-acc") - testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccSelectelPreCheck(t) }, - ProviderFactories: testAccProviders, - CheckDestroy: testAccCheckDomainsV2ZoneDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDomainsZoneV2DataSourceBasic(testProjectName, resourceZoneName, testZoneName), - Check: resource.ComposeTestCheckFunc( - testAccDomainsZoneV2Exists(fmt.Sprintf("data.selectel_domains_zone_v2.%[1]s", resourceZoneName)), - resource.TestCheckResourceAttr(fmt.Sprintf("data.selectel_domains_zone_v2.%[1]s", resourceZoneName), "name", testZoneName), - ), - }, - }, - }) -} - -func testAccDomainsZoneV2Exists(name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - if !ok { - return fmt.Errorf("can't find zone: %s", name) - } - - zoneID := rs.Primary.ID - if zoneID == "" { - return errors.New("zone ID not set in tf state") - } - client, err := getDomainsV2ClientTest(rs, testAccProvider) - if err != nil { - return err - } - ctx := context.Background() - _, err = client.GetZone(ctx, zoneID, nil) - if err != nil { - return errors.New("zone in api not found") - } - - return nil - } -} - -func testAccDomainsZoneV2DataSourceBasic(projectName, resourceName, zoneName string) string { - return fmt.Sprintf(` - %[1]s - - data "selectel_domains_zone_v2" %[2]q { - name = selectel_domains_zone_v2.%[2]s.name - project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}" - } -`, testAccDomainsZoneV2Basic(projectName, resourceName, zoneName), resourceName, zoneName) -} diff --git a/selectel/provider.go b/selectel/provider.go index 6c7ed126..b6d424d9 100644 --- a/selectel/provider.go +++ b/selectel/provider.go @@ -102,8 +102,6 @@ func Provider() *schema.Provider { }, DataSourcesMap: map[string]*schema.Resource{ "selectel_domains_domain_v1": dataSourceDomainsDomainV1(), - "selectel_domains_zone_v2": dataSourceDomainsZoneV2(), - "selectel_domains_rrset_v2": dataSourceDomainsRRSetV2(), "selectel_dbaas_datastore_type_v1": dataSourceDBaaSDatastoreTypeV1(), "selectel_dbaas_available_extension_v1": dataSourceDBaaSAvailableExtensionV1(), "selectel_dbaas_flavor_v1": dataSourceDBaaSFlavorV1(), diff --git a/selectel/resource_selectel_domains_rrset_v2.go b/selectel/resource_selectel_domains_rrset_v2.go index 4f625c1f..f4f442e5 100644 --- a/selectel/resource_selectel_domains_rrset_v2.go +++ b/selectel/resource_selectel_domains_rrset_v2.go @@ -12,6 +12,8 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) +var ErrRRSetNotFound = errors.New("rrset not found") + func resourceDomainsRRSetV2() *schema.Resource { return &schema.Resource{ CreateContext: resourceDomainsRRSetV2Create, diff --git a/selectel/resource_selectel_domains_rrset_v2_test.go b/selectel/resource_selectel_domains_rrset_v2_test.go index 3c14c292..282ce2e0 100644 --- a/selectel/resource_selectel_domains_rrset_v2_test.go +++ b/selectel/resource_selectel_domains_rrset_v2_test.go @@ -13,6 +13,8 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) +const resourceRRSetName = "rrset_tf_acc_test_1" + func TestAccDomainsRRSetV2Basic(t *testing.T) { projectName := acctest.RandomWithPrefix("tf-acc") testZoneName := fmt.Sprintf("%s.ru.", acctest.RandomWithPrefix("tf-acc")) @@ -58,21 +60,6 @@ func testAccDomainsRRSetV2WithZoneBasic(projectName, resourceRRSetName, rrsetNam }`, resourceRRSetName, rrsetName, rrsetType, ttl, rrsetContent, resourceZoneName, testAccDomainsZoneV2Basic(projectName, resourceZoneName, zoneName)) } -func testAccDomainsRRSetV2Basic(resourceRRSetName, rrsetName, rrsetType, rrsetContent string, ttl int, resourceZoneName string) string { - return fmt.Sprintf(` - resource "selectel_domains_rrset_v2" %[1]q { - name = %[2]q - type = %[3]q - ttl = %[4]d - zone_id = selectel_domains_zone_v2.%[5]s.id - project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}" - records { - content = %[6]q - disabled = false - } - }`, resourceRRSetName, rrsetName, rrsetType, ttl, resourceZoneName, rrsetContent) -} - func testAccCheckDomainsV2RRSetDestroy(s *terraform.State) error { ctx := context.Background() @@ -96,3 +83,18 @@ func testAccCheckDomainsV2RRSetDestroy(s *terraform.State) error { return nil } + +func testAccDomainsRRSetV2ID(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("can't find rrset: %s", name) + } + + if rs.Primary.ID == "" { + return errors.New("rrset data source ID not set") + } + + return nil + } +} diff --git a/selectel/resource_selectel_domains_zone_v2.go b/selectel/resource_selectel_domains_zone_v2.go index 3c2393a3..b0a9590d 100644 --- a/selectel/resource_selectel_domains_zone_v2.go +++ b/selectel/resource_selectel_domains_zone_v2.go @@ -10,6 +10,8 @@ import ( domainsV2 "github.com/selectel/domains-go/pkg/v2" ) +var ErrZoneNotFound = errors.New("zone not found") + func resourceDomainsZoneV2() *schema.Resource { return &schema.Resource{ CreateContext: resourceDomainsZoneV2Create, diff --git a/selectel/resource_selectel_domains_zone_v2_test.go b/selectel/resource_selectel_domains_zone_v2_test.go index e451629e..a98722a3 100644 --- a/selectel/resource_selectel_domains_zone_v2_test.go +++ b/selectel/resource_selectel_domains_zone_v2_test.go @@ -11,6 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) +const resourceZoneName = "zone_tf_acc_test_1" + func TestAccDomainsZoneV2Basic(t *testing.T) { projectName := acctest.RandomWithPrefix("tf-acc") testZoneName := fmt.Sprintf("%s.xyz.", acctest.RandomWithPrefix("tf-acc")) @@ -63,3 +65,28 @@ func testAccCheckDomainsV2ZoneDestroy(s *terraform.State) error { return nil } + +func testAccDomainsZoneV2Exists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("can't find zone: %s", name) + } + + zoneID := rs.Primary.ID + if zoneID == "" { + return errors.New("zone ID not set in tf state") + } + client, err := getDomainsV2ClientTest(rs, testAccProvider) + if err != nil { + return err + } + ctx := context.Background() + _, err = client.GetZone(ctx, zoneID, nil) + if err != nil { + return errors.New("zone in api not found") + } + + return nil + } +} diff --git a/website/docs/d/domains_rrset_v2.html.markdown b/website/docs/d/domains_rrset_v2.html.markdown deleted file mode 100644 index ad7e4b0a..00000000 --- a/website/docs/d/domains_rrset_v2.html.markdown +++ /dev/null @@ -1,46 +0,0 @@ ---- -layout: "selectel" -page_title: "Selectel: selectel_domains_rrset_v2" -sidebar_current: "docs-selectel-datasource-domains-rrset-v2" -description: |- - Provides information about an RRSet in Selectel DNS Hosting (actual). ---- - -# selectel\_domains\_rrset_v2 - -Provides information about an RRSet in DNS Hosting (actual). For more information about RRSets, 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 = selectel_domains_zone_v2.zone_1.id - project_id = selectel_vpc_project_v2.project_1.id -} -``` - -## Argument Reference - -* `name` - (Required) RRSet name. - -* `type` - (Required) RRSet type. Available types are `A`, `AAAA`, `TXT`, `CNAME`, `NS`, `MX`, `SRV`, `SSHFP`, `ALIAS`, `CAA`. - -* `zone_id` - (Required) Unique identifier of the zone. Retrieved from the [selectel_domains_zone_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/domains_zone_v2) resource. - -* `project_id` - (Required) Unique identifier of the associated Cloud Platform project. Retrieved from the [selectel_vpc_project_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/vpc_project_v2) resource. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). - -## Attributes Reference - -* `ttl` - RRSet time-to-live in seconds. - -* `comment` - Comment for the RRSet. - -* `managed_by` - RRSet owner. - -* `records` - List of records in the RRSet. - - * `content` - Record value. - - * `disabled` - Shows if the record is enabled or disabled. diff --git a/website/docs/d/domains_zone_v2.html.markdown b/website/docs/d/domains_zone_v2.html.markdown deleted file mode 100644 index 003954f4..00000000 --- a/website/docs/d/domains_zone_v2.html.markdown +++ /dev/null @@ -1,42 +0,0 @@ ---- -layout: "selectel" -page_title: "Selectel: selectel_domains_zone_v2" -sidebar_current: "docs-selectel-datasource-domains-zone-v2" -description: |- - Provides information about a zone in Selectel DNS Hosting (actual). ---- - -# selectel\_domains\_zone_v2 - -Provides information about a zone in Selectel DNS Hosting (actual). For more information about zones, 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." - project_id = selectel_vpc_project_v2.project_1.id -} -``` - -## Argument Reference - -* `name` - (Required) Zone name. - -* `project_id` - (Required) Unique identifier of the associated Cloud Platform project. Retrieved from the [selectel_vpc_project_v2](https://registry.terraform.io/providers/selectel/selectel/latest/docs/resources/vpc_project_v2) resource. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). - -## Attributes Reference - -* `comment` - Comment for the zone. - -* `created_at` - Time when the zone was created in the RFC 3339 timestamp format. - -* `updated_at` - Time when the zone was updated in the RFC 3339 timestamp format. - -* `delegation_checked_at` - Time when DNS Hosting checked if the zone was delegated to Selectel NS servers in the RFC 3339 timestamp format. - -* `last_check_status` - Zone status retrieved during the last delegation check. - -* `last_delegated_at` - Equals to the `delegation_check_at` argument value when the `last_check_status` is `true`. - -* `disabled` - Shows if the zone is enabled or disabled. diff --git a/website/docs/r/domains_rrset_v2.html.markdown b/website/docs/r/domains_rrset_v2.html.markdown index be00781a..ed2d9732 100644 --- a/website/docs/r/domains_rrset_v2.html.markdown +++ b/website/docs/r/domains_rrset_v2.html.markdown @@ -215,7 +215,7 @@ where: * `` — Password of the service user. -* `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/craas/about/projects/). +* `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). * `` — Zone name, for example, `example.com.`. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. diff --git a/website/docs/r/domains_zone_v2.html.markdown b/website/docs/r/domains_zone_v2.html.markdown index 6b44dc20..47c300cd 100644 --- a/website/docs/r/domains_zone_v2.html.markdown +++ b/website/docs/r/domains_zone_v2.html.markdown @@ -61,6 +61,6 @@ where: * `` — Password of the service user. -* `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/craas/about/projects/). +* `` — Unique identifier of the associated Cloud Platform project. To get the project ID, in the [Control panel](https://my.selectel.ru/vpc/), go to Cloud Platform ⟶ project name ⟶ copy the ID of the required project. Learn more about [Cloud Platform projects](https://docs.selectel.ru/cloud/servers/about/projects/). * `` — Zone name, for example, `example.com.`. To get the name, in the [Control panel](https://my.selectel.ru/dns/), go to **DNS**. The zone name is in the **Zone** column. diff --git a/website/selectel.erb b/website/selectel.erb index 640d52a6..017f188a 100644 --- a/website/selectel.erb +++ b/website/selectel.erb @@ -16,12 +16,6 @@ > selectel_domains_domain_v1 - > - selectel_domains_zone_v2 - - > - selectel_domains_rrset_v2 - > selectel_dbaas_datastore_type_v1