diff --git a/go.mod b/go.mod index 1126db2df7..04887653f9 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.0 github.com/hashicorp/terraform v0.12.0 - github.com/huaweicloud/golangsdk v0.0.0-20190821064240-70d88a1c0686 + github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19 github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a github.com/mitchellh/go-homedir v1.0.0 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect diff --git a/go.sum b/go.sum index 703617af5d..e2e3d2ae1e 100644 --- a/go.sum +++ b/go.sum @@ -192,8 +192,8 @@ github.com/hashicorp/vault v0.10.4/go.mod h1:KfSyffbKxoVyspOdlaGVjIuwLobi07qD1bA github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huaweicloud/golangsdk v0.0.0-20190821064240-70d88a1c0686 h1:hNz6V0LLPFPp+IcrMb9+tu6gZ2VC3IkphjgjQ1AFyOA= -github.com/huaweicloud/golangsdk v0.0.0-20190821064240-70d88a1c0686/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= +github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19 h1:FUlribrcVGqGR4irupy34lbps5BPTJMurJ+kt/zxDmM= +github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY= diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index df49d1075c..50428ce8e5 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -239,6 +239,7 @@ func Provider() terraform.ResourceProvider { "huaweicloud_compute_floatingip_v2": resourceComputeFloatingIPV2(), "huaweicloud_compute_floatingip_associate_v2": resourceComputeFloatingIPAssociateV2(), "huaweicloud_compute_volume_attach_v2": resourceComputeVolumeAttachV2(), + "huaweicloud_dns_ptrrecord_v2": resourceDNSPtrRecordV2(), "huaweicloud_dns_recordset_v2": resourceDNSRecordSetV2(), "huaweicloud_dns_zone_v2": resourceDNSZoneV2(), "huaweicloud_dcs_instance_v1": resourceDcsInstanceV1(), diff --git a/huaweicloud/resource_huaweicloud_dns_ptrrecord_v2.go b/huaweicloud/resource_huaweicloud_dns_ptrrecord_v2.go new file mode 100644 index 0000000000..4303efe04b --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dns_ptrrecord_v2.go @@ -0,0 +1,264 @@ +package huaweicloud + +import ( + "fmt" + "log" + "strings" + "time" + + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceDNSPtrRecordV2() *schema.Resource { + return &schema.Resource{ + Create: resourceDNSPtrRecordV2Create, + Read: resourceDNSPtrRecordV2Read, + Update: resourceDNSPtrRecordV2Update, + Delete: resourceDNSPtrRecordV2Delete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: false, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: false, + }, + "floatingip_id": { + Type: schema.TypeString, + Required: true, + ForceNew: false, + }, + "ttl": { + Type: schema.TypeInt, + Optional: true, + ForceNew: false, + ValidateFunc: resourceValidateTTL, + }, + "tags": { + Type: schema.TypeMap, + Optional: true, + ForceNew: false, + ValidateFunc: validateECSTagValue, + }, + "address": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceDNSPtrRecordV2Create(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + region := GetRegion(d, config) + dnsClient, err := config.dnsV2Client(region) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud DNS client: %s", err) + } + + tagmap := d.Get("tags").(map[string]interface{}) + taglist := []ptrrecords.Tag{} + for k, v := range tagmap { + tag := ptrrecords.Tag{ + Key: k, + Value: v.(string), + } + taglist = append(taglist, tag) + } + + createOpts := ptrrecords.CreateOpts{ + PtrName: d.Get("name").(string), + Description: d.Get("description").(string), + TTL: d.Get("ttl").(int), + Tags: taglist, + } + + log.Printf("[DEBUG] Create Options: %#v", createOpts) + fip_id := d.Get("floatingip_id").(string) + n, err := ptrrecords.Create(dnsClient, region, fip_id, createOpts).Extract() + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud DNS PTR record: %s", err) + } + + log.Printf("[DEBUG] Waiting for DNS PTR record (%s) to become available", n.ID) + stateConf := &resource.StateChangeConf{ + Target: []string{"ACTIVE"}, + Pending: []string{"PENDING_CREATE"}, + Refresh: waitForDNSPtrRecord(dnsClient, n.ID), + Timeout: d.Timeout(schema.TimeoutCreate), + Delay: 5 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + + if err != nil { + return fmt.Errorf( + "Error waiting for PTR record (%s) to become ACTIVE for creation: %s", + n.ID, err) + } + d.SetId(n.ID) + + log.Printf("[DEBUG] Created HuaweiCloud DNS PTR record %s: %#v", n.ID, n) + return resourceDNSPtrRecordV2Read(d, meta) +} + +func resourceDNSPtrRecordV2Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dnsClient, err := config.dnsV2Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud DNS client: %s", err) + } + + n, err := ptrrecords.Get(dnsClient, d.Id()).Extract() + if err != nil { + return CheckDeleted(d, err, "ptr_record") + } + + log.Printf("[DEBUG] Retrieved PTR record %s: %#v", d.Id(), n) + + // Obtain relevant info from parsing the ID + fipID, err := parseDNSV2PtrRecordID(d.Id()) + if err != nil { + return err + } + + d.Set("name", n.PtrName) + d.Set("description", n.Description) + d.Set("floatingip_id", fipID) + d.Set("ttl", n.TTL) + d.Set("address", n.Address) + + return nil +} + +func resourceDNSPtrRecordV2Update(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + region := GetRegion(d, config) + dnsClient, err := config.dnsV2Client(region) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud DNS client: %s", err) + } + + tagmap := d.Get("tags").(map[string]interface{}) + taglist := []ptrrecords.Tag{} + for k, v := range tagmap { + tag := ptrrecords.Tag{ + Key: k, + Value: v.(string), + } + taglist = append(taglist, tag) + } + + createOpts := ptrrecords.CreateOpts{ + PtrName: d.Get("name").(string), + Description: d.Get("description").(string), + TTL: d.Get("ttl").(int), + Tags: taglist, + } + + log.Printf("[DEBUG] Update Options: %#v", createOpts) + fip_id := d.Get("floatingip_id").(string) + n, err := ptrrecords.Create(dnsClient, region, fip_id, createOpts).Extract() + if err != nil { + return fmt.Errorf("Error updating HuaweiCloud DNS PTR record: %s", err) + } + + log.Printf("[DEBUG] Waiting for DNS PTR record (%s) to become available", n.ID) + stateConf := &resource.StateChangeConf{ + Target: []string{"ACTIVE"}, + Pending: []string{"PENDING_CREATE"}, + Refresh: waitForDNSPtrRecord(dnsClient, n.ID), + Timeout: d.Timeout(schema.TimeoutCreate), + Delay: 5 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + + if err != nil { + return fmt.Errorf( + "Error waiting for PTR record (%s) to become ACTIVE for update: %s", + n.ID, err) + } + + log.Printf("[DEBUG] Updated HuaweiCloud DNS PTR record %s: %#v", n.ID, n) + return resourceDNSPtrRecordV2Read(d, meta) + +} + +func resourceDNSPtrRecordV2Delete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dnsClient, err := config.dnsV2Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud DNS client: %s", err) + } + + err = ptrrecords.Delete(dnsClient, d.Id()).ExtractErr() + if err != nil { + return fmt.Errorf("Error deleting HuaweiCloud DNS PTR record: %s", err) + } + + log.Printf("[DEBUG] Waiting for DNS PTR record (%s) to be deleted", d.Id()) + stateConf := &resource.StateChangeConf{ + Target: []string{"DELETED"}, + Pending: []string{"ACTIVE", "PENDING_DELETE", "ERROR"}, + Refresh: waitForDNSPtrRecord(dnsClient, d.Id()), + Timeout: d.Timeout(schema.TimeoutDelete), + Delay: 5 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + if err != nil { + return fmt.Errorf( + "Error waiting for PTR record (%s) to become DELETED for deletion: %s", + d.Id(), err) + } + + d.SetId("") + return nil +} + +func waitForDNSPtrRecord(dnsClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + ptrrecord, err := ptrrecords.Get(dnsClient, id).Extract() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + return ptrrecord, "DELETED", nil + } + + return nil, "", err + } + + log.Printf("[DEBUG] HuaweiCloud DNS PTR record (%s) current status: %s", ptrrecord.ID, ptrrecord.Status) + return ptrrecord, ptrrecord.Status, nil + } +} + +func parseDNSV2PtrRecordID(id string) (string, error) { + idParts := strings.Split(id, ":") + if len(idParts) != 2 { + return "", fmt.Errorf("Unable to determine DNS PTR record ID from raw ID: %s", id) + } + + fipID := idParts[1] + return fipID, nil +} diff --git a/huaweicloud/resource_huaweicloud_dns_ptrrecord_v2_test.go b/huaweicloud/resource_huaweicloud_dns_ptrrecord_v2_test.go new file mode 100644 index 0000000000..cdfb982da2 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dns_ptrrecord_v2_test.go @@ -0,0 +1,129 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + + "github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords" +) + +func randomPtrName() string { + return fmt.Sprintf("acpttest-%s.com.", acctest.RandString(5)) +} + +func TestAccDNSV2PtrRecord_basic(t *testing.T) { + var ptrrecord ptrrecords.Ptr + ptrName := randomPtrName() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckDNS(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDNSV2PtrRecordDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDNSV2PtrRecord_basic(ptrName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDNSV2PtrRecordExists("huaweicloud_dns_ptrrecord_v2.ptr_1", &ptrrecord), + resource.TestCheckResourceAttr( + "huaweicloud_dns_ptrrecord_v2.ptr_1", "description", "a ptr record"), + ), + }, + { + Config: testAccDNSV2PtrRecord_update(ptrName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDNSV2PtrRecordExists("huaweicloud_dns_ptrrecord_v2.ptr_1", &ptrrecord), + resource.TestCheckResourceAttr( + "huaweicloud_dns_ptrrecord_v2.ptr_1", "description", "ptr record updated"), + ), + }, + }, + }) +} + +func testAccCheckDNSV2PtrRecordDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + dnsClient, err := config.dnsV2Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud DNS client: %s", err) + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "huaweicloud_dns_ptrrecord_v2" { + continue + } + + _, err = ptrrecords.Get(dnsClient, rs.Primary.ID).Extract() + if err == nil { + return fmt.Errorf("Ptr record still exists") + } + } + + return nil +} + +func testAccCheckDNSV2PtrRecordExists(n string, ptrrecord *ptrrecords.Ptr) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No ID is set") + } + + config := testAccProvider.Meta().(*Config) + dnsClient, err := config.dnsV2Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud DNS client: %s", err) + } + + found, err := ptrrecords.Get(dnsClient, rs.Primary.ID).Extract() + if err != nil { + return err + } + + if found.ID != rs.Primary.ID { + return fmt.Errorf("Ptr record not found") + } + + *ptrrecord = *found + + return nil + } +} + +func testAccDNSV2PtrRecord_basic(ptrName string) string { + return fmt.Sprintf(` + resource "huaweicloud_networking_floatingip_v2" "fip_1" { + } + + resource "huaweicloud_dns_ptrrecord_v2" "ptr_1" { + name = "%s" + description = "a ptr record" + floatingip_id = "${huaweicloud_networking_floatingip_v2.fip_1.id}" + ttl = 6000 + } + `, ptrName) +} + +func testAccDNSV2PtrRecord_update(ptrName string) string { + return fmt.Sprintf(` + resource "huaweicloud_networking_floatingip_v2" "fip_1" { + } + + resource "huaweicloud_dns_ptrrecord_v2" "ptr_1" { + name = "%s" + description = "ptr record updated" + floatingip_id = "${huaweicloud_networking_floatingip_v2.fip_1.id}" + ttl = 6000 + tags = { + foo = "bar" + } + } + `, ptrName) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go index 44218cdf15..4246f564a7 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go @@ -332,9 +332,10 @@ func v3AKSKAuth(client *golangsdk.ProviderClient, endpoint string, options golan if options.DomainID == "" && options.Domain != "" { id, err := getDomainID(options.Domain, v3Client) if err != nil { - return err + options.DomainID = "" + } else { + options.DomainID = id } - options.DomainID = id } client.ProjectID = options.ProjectId diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/requests.go new file mode 100644 index 0000000000..41e8f773e4 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/requests.go @@ -0,0 +1,78 @@ +package ptrrecords + +import ( + "github.com/huaweicloud/golangsdk" +) + +// Get returns information about a ptr, given its ID. +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) + return +} + +// CreateOptsBuilder allows extensions to add additional attributes to the +// Create request. +type CreateOptsBuilder interface { + ToPtrCreateMap() (map[string]interface{}, error) +} + +// CreateOpts specifies the attributes used to create a ptr. +type CreateOpts struct { + // Name of the ptr. + PtrName string `json:"ptrdname" required:"true"` + + // Description of the ptr. + Description string `json:"description,omitempty"` + + // TTL is the time to live of the ptr. + TTL int `json:"-"` + + // Tags of the ptr. + Tags []Tag `json:"tags,omitempty"` +} + +// Tag is a structure of key value pair. +type Tag struct { + //tag key + Key string `json:"key" required:"true"` + //tag value + Value string `json:"value" required:"true"` +} + +// ToPtrCreateMap formats an CreateOpts structure into a request body. +func (opts CreateOpts) ToPtrCreateMap() (map[string]interface{}, error) { + b, err := golangsdk.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + if opts.TTL > 0 { + b["ttl"] = opts.TTL + } + + return b, nil +} + +// Create implements a ptr create/update request. +func Create(client *golangsdk.ServiceClient, region string, fip_id string, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPtrCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Patch(baseURL(client, region, fip_id), &b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} + +// Delete implements a ptr delete request. +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + b := map[string]string{ + "ptrname": "null", + } + _, r.Err = client.Patch(resourceURL(client, id), &b, nil, &golangsdk.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/results.go new file mode 100644 index 0000000000..1cdc805c31 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/results.go @@ -0,0 +1,56 @@ +package ptrrecords + +import ( + "github.com/huaweicloud/golangsdk" +) + +type commonResult struct { + golangsdk.Result +} + +// Extract interprets a GetResult, CreateResult as a Ptr. +// An error is returned if the original call or the extraction failed. +func (r commonResult) Extract() (*Ptr, error) { + var s *Ptr + err := r.ExtractInto(&s) + return s, err +} + +// CreateResult is the result of a Create request. Call its Extract method +// to interpret the result as a Ptr. +type CreateResult struct { + commonResult +} + +// GetResult is the result of a Get request. Call its Extract method +// to interpret the result as a Ptr. +type GetResult struct { + commonResult +} + +// DeleteResult is the result of a Delete request. Call its ExtractErr method +// to determine if the request succeeded or failed. +type DeleteResult struct { + golangsdk.ErrResult +} + +// Ptr represents a ptr record. +type Ptr struct { + // ID uniquely identifies this ptr amongst all other ptr records. + ID string `json:"id"` + + // Name for this ptr. + PtrName string `json:"ptrdname"` + + // Description for this ptr. + Description string `json:"description"` + + // TTL is the Time to Live for the ptr. + TTL int `json:"ttl"` + + // Address of the floating ip. + Address string `json:"address"` + + // Status of the PTR. + Status string `json:"status"` +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/urls.go new file mode 100644 index 0000000000..c0b8135259 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords/urls.go @@ -0,0 +1,11 @@ +package ptrrecords + +import "github.com/huaweicloud/golangsdk" + +func baseURL(c *golangsdk.ServiceClient, region string, floatingip_id string) string { + return c.ServiceURL("reverse/floatingips", region+":"+floatingip_id) +} + +func resourceURL(c *golangsdk.ServiceClient, id string) string { + return c.ServiceURL("reverse/floatingips", id) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 16128a09df..8903d66348 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -178,7 +178,7 @@ github.com/hashicorp/terraform/svchost/auth github.com/hashicorp/terraform-config-inspect/tfconfig # github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb github.com/hashicorp/yamux -# github.com/huaweicloud/golangsdk v0.0.0-20190821064240-70d88a1c0686 +# github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19 github.com/huaweicloud/golangsdk github.com/huaweicloud/golangsdk/openstack github.com/huaweicloud/golangsdk/openstack/antiddos/v1/antiddos @@ -218,6 +218,7 @@ github.com/huaweicloud/golangsdk/openstack/dms/v1/instances github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows github.com/huaweicloud/golangsdk/openstack/dms/v1/products github.com/huaweicloud/golangsdk/openstack/dms/v1/queues +github.com/huaweicloud/golangsdk/openstack/dns/v2/ptrrecords github.com/huaweicloud/golangsdk/openstack/dns/v2/recordsets github.com/huaweicloud/golangsdk/openstack/dns/v2/zones github.com/huaweicloud/golangsdk/openstack/ecs/v1/auto_recovery diff --git a/website/docs/r/dns_ptrrecord_v2.html.markdown b/website/docs/r/dns_ptrrecord_v2.html.markdown new file mode 100644 index 0000000000..c678aef73d --- /dev/null +++ b/website/docs/r/dns_ptrrecord_v2.html.markdown @@ -0,0 +1,62 @@ +--- +layout: "huaweicloud" +page_title: "HuaweiCloud: huaweicloud_dns_ptrrecord_v2" +sidebar_current: "docs-huaweicloud-resource-dns-ptrrecord-v2" +description: |- + Manages a DNS PTR record in the HuaweiCloud DNS Service +--- + +# huaweicloud\_dns\_ptrrecord_v2 + +Manages a DNS PTR record in the HuaweiCloud DNS Service. + +## Example Usage + +```hcl +resource "huaweicloud_networking_floatingip_v2" "fip_1" { +} + +resource "huaweicloud_dns_ptrrecord_v2" "ptr_1" { + name = "ptr.example.com." + description = "An example PTR record" + floatingip_id = "${huaweicloud_networking_floatingip_v2.fip_1.id}" + ttl = 3000 + tags = { + foo = "bar" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Domain name of the PTR record. A domain name is case insensitive. + Uppercase letters will also be converted into lowercase letters. + +* `description` - (Optional) Description of the PTR record. + +* `floatingip_id` - (Required) The ID of the FloatingIP/EIP. + +* `ttl` - (Optional) The time to live (TTL) of the record set (in seconds). The value + range is 300–2147483647. The default value is 300. + +* `tags` - (Optional) Tags key/value pairs to associate with the PTR record. + +## Attributes Reference + +The following attributes are exported: + +* `name` - See Argument Reference above. +* `description` - See Argument Reference above. +* `floatingip_id` - See Argument Reference above. +* `ttl` - See Argument Reference above. +* `tags` - See Argument Reference above. +* `address` - The address of the FloatingIP/EIP. + +## Import + +PTR records can be imported using region and floatingip/eip ID :, e.g. + +``` +$ terraform import huaweicloud_dns_ptrrecord_v2.ptr_1 cn-north-1:d90ce693-5ccf-4136-a0ed-152ce412b6b9