diff --git a/huaweicloud/config.go b/huaweicloud/config.go index 51b6c9b6a11..2f8d93331d1 100644 --- a/huaweicloud/config.go +++ b/huaweicloud/config.go @@ -438,3 +438,10 @@ func (c *Config) autoscalingV1Client(region string) (*golangsdk.ServiceClient, e Availability: c.getHwEndpointType(), }) } + +func (c *Config) dmsV1Client(region string) (*golangsdk.ServiceClient, error) { + return huaweisdk.NewDMSServiceV1(c.HwClient, golangsdk.EndpointOpts{ + Region: c.determineRegion(region), + Availability: c.getHwEndpointType(), + }) +} diff --git a/huaweicloud/data_source_huaweicloud_dms_az_v1.go b/huaweicloud/data_source_huaweicloud_dms_az_v1.go new file mode 100644 index 00000000000..60ab5ab1a8c --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_dms_az_v1.go @@ -0,0 +1,82 @@ +package huaweicloud + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones" +) + +func dataSourceDmsAZV1() *schema.Resource { + return &schema.Resource{ + Read: dataSourceDmsAZV1Read, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "code": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "port": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + } +} + +func dataSourceDmsAZV1Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud kms key client: %s", err) + } + + v, err := availablezones.Get(dmsV1Client).Extract() + if err != nil { + return err + } + + log.Printf("[DEBUG] Dms az : %+v", v) + var filteredAZs []availablezones.AvailableZone + if v.RegionID == GetRegion(d, config){ + AZs := v.AvailableZones + for _, newAZ := range AZs{ + if newAZ.ResourceAvailability != "true" { + continue + } + + name := d.Get("name").(string) + if name != "" && newAZ.Name != name { + continue + } + + port := d.Get("port").(string) + if port != "" && newAZ.Port != port { + continue + } + filteredAZs = append(filteredAZs, newAZ) + } + } + + if len(filteredAZs) < 1 { + return fmt.Errorf("Not found any available zones") + } + + az := filteredAZs[0] + log.Printf("[DEBUG] Dms az : %+v", az) + + d.SetId(az.ID) + d.Set("code", az.Code) + d.Set("name", az.Name) + d.Set("port", az.Port) + + return nil +} diff --git a/huaweicloud/data_source_huaweicloud_dms_az_v1_test.go b/huaweicloud/data_source_huaweicloud_dms_az_v1_test.go new file mode 100644 index 00000000000..4f5a54bdf20 --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_dms_az_v1_test.go @@ -0,0 +1,53 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccDmsAZV1DataSource_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsAZV1DataSource_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsAZV1DataSourceID("data.huaweicloud_dms_az_v1.az1"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_az_v1.az1", "name", "可用区1"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_az_v1.az1", "port", "8002"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_az_v1.az1", "code", "cn-north-1a"), + ), + }, + }, + }) +} + +func testAccCheckDmsAZV1DataSourceID(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Can't find Dms az data source: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("Dms az data source ID not set") + } + + return nil + } +} + +var testAccDmsAZV1DataSource_basic = fmt.Sprintf(` +data "huaweicloud_dms_az_v1" "az1" { +name = "可用区1" +port = "8002" +code = "cn-north-1a" +} +`) diff --git a/huaweicloud/data_source_huaweicloud_dms_maintainwindow_v1.go b/huaweicloud/data_source_huaweicloud_dms_maintainwindow_v1.go new file mode 100644 index 00000000000..c4984926eb5 --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_dms_maintainwindow_v1.go @@ -0,0 +1,88 @@ +package huaweicloud + +import ( + "fmt" + "log" + "strconv" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows" +) + +func dataSourceDmsMaintainWindowV1() *schema.Resource { + return &schema.Resource{ + Read: dataSourceDmsMaintainWindowV1Read, + + Schema: map[string]*schema.Schema{ + "seq": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "begin": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "end": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "default": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + }, + } +} + +func dataSourceDmsMaintainWindowV1Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud kms key client: %s", err) + } + + v, err := maintainwindows.Get(dmsV1Client).Extract() + if err != nil { + return err + } + + maintainWindows := v.MaintainWindows + var filteredMVs []maintainwindows.MaintainWindow + for _, mv := range maintainWindows { + seq := d.Get("seq").(int) + if seq != 0 && mv.ID != seq { + continue + } + + begin := d.Get("begin").(string) + if begin != "" && mv.Begin != begin { + continue + } + end := d.Get("end").(string) + if end != "" && mv.End != end { + continue + } + + df := d.Get("default").(bool) + if mv.Default != df { + continue + } + filteredMVs = append(filteredMVs, mv) + } + if len(filteredMVs) < 1 { + return fmt.Errorf("Your query returned no results. Please change your filters and try again.") + } + mw := filteredMVs[0] + d.SetId(strconv.Itoa(mw.ID)) + d.Set("begin", mw.Begin) + d.Set("end", mw.End) + d.Set("default", mw.Default) + log.Printf("[DEBUG] Dms MaintainWindow : %+v", mw) + + + return nil +} diff --git a/huaweicloud/data_source_huaweicloud_dms_maintainwindow_v1_test.go b/huaweicloud/data_source_huaweicloud_dms_maintainwindow_v1_test.go new file mode 100644 index 00000000000..9dd1e1ad6bb --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_dms_maintainwindow_v1_test.go @@ -0,0 +1,49 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccDmsMaintainWindowV1DataSource_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsMaintainWindowV1DataSource_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsMaintainWindowV1DataSourceID("data.huaweicloud_dms_maintainwindow_v1.maintainwindow1"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_maintainwindow_v1.maintainwindow1", "seq", "1"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_maintainwindow_v1.maintainwindow1", "begin", "22"), + ), + }, + }, + }) +} + +func testAccCheckDmsMaintainWindowV1DataSourceID(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Can't find Dms maintainwindow data source: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("Dms maintainwindow data source ID not set") + } + + return nil + } +} + +var testAccDmsMaintainWindowV1DataSource_basic = fmt.Sprintf(` +data "huaweicloud_dms_maintainwindow_v1" "maintainwindow1" { +seq = 1 +} +`) diff --git a/huaweicloud/data_source_huaweicloud_dms_product_v1.go b/huaweicloud/data_source_huaweicloud_dms_product_v1.go new file mode 100644 index 00000000000..b58024f18df --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_dms_product_v1.go @@ -0,0 +1,194 @@ +package huaweicloud + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/products" +) + +func dataSourceDmsProductV1() *schema.Resource { + return &schema.Resource{ + Read: dataSourceDmsProductV1Read, + + Schema: map[string]*schema.Schema{ + "engine": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "version": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "instance_type": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "vm_specification": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "storage": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "bandwidth": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "partition_num": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "storage_spec_code": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "io_type": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "node_num": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + } +} + +func getIObyIOtype(d *schema.ResourceData, IOs []products.IO) []products.IO { + io_type := d.Get("io_type").(string) + storage_spec_code := d.Get("storage_spec_code").(string) + + if io_type != "" || storage_spec_code != "" { + var getIOs []products.IO + for _, io := range IOs { + if io_type == io.IOType || storage_spec_code == io.StorageSpecCode { + getIOs = append(getIOs, io) + } + } + return getIOs + } + + return IOs +} + +func dataSourceDmsProductV1Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error get HuaweiCloud dms product client: %s", err) + } + + instance_engine := d.Get("engine").(string) + if instance_engine != "rabbitmq" && instance_engine != "kafka"{ + return fmt.Errorf("The instance_engine value should be 'rabbitmq' or 'kafka', not: %s", instance_engine) + } + + v, err := products.Get(dmsV1Client, instance_engine).Extract() + if err != nil { + return err + } + Products := v.Hourly + + log.Printf("[DEBUG] Dms get products : %+v", Products) + instance_type := d.Get("instance_type").(string) + if instance_type != "single" && instance_type != "cluster"{ + return fmt.Errorf("The instance_type value should be 'single' or 'cluster', not: %s", instance_type) + } + var FilteredPd []products.Detail + var FilteredPdInfo []products.ProductInfo + for _, pd := range Products{ + version := d.Get("version").(string) + if version != "" && pd.Version != version{ + continue + } + + for _, value := range pd.Values{ + if value.Name != instance_type { + continue + } + for _, detail := range value.Details { + vm_specification := d.Get("vm_specification").(string) + if vm_specification != "" && detail.VMSpecification != vm_specification { + continue + } + bandwidth := d.Get("bandwidth").(string) + if bandwidth != "" && detail.Bandwidth != bandwidth { + continue + } + + if instance_type == "single" || instance_engine == "kafka" { + storage := d.Get("storage").(string) + if storage != "" && detail.Storage != storage { + continue + } + IOs := getIObyIOtype(d, detail.IOs) + if len(IOs) == 0{ + continue + } + detail.IOs = IOs + } else{ + for _, pdInfo := range detail.ProductInfos { + storage := d.Get("storage").(string) + if storage != "" && pdInfo.Storage != storage { + continue + } + node_num := d.Get("node_num").(string) + if node_num != "" && pdInfo.NodeNum != node_num { + continue + } + + IOs := getIObyIOtype(d, pdInfo.IOs) + if len(IOs) == 0{ + continue + } + pdInfo.IOs = IOs + FilteredPdInfo = append(FilteredPdInfo, pdInfo) + } + if len(FilteredPdInfo) == 0 { + continue + } + detail.ProductInfos = FilteredPdInfo + } + FilteredPd = append(FilteredPd, detail) + } + } + } + + if len(FilteredPd) < 1 { + return fmt.Errorf("Your query returned no results. Please change your filters and try again.") + } + + pd := FilteredPd[0] + d.Set("vm_specification", pd.VMSpecification) + if instance_type == "single" || instance_engine == "kafka" { + d.SetId(pd.ProductID) + d.Set("storage", pd.Storage) + d.Set("partition_num", pd.PartitionNum) + d.Set("bandwidth", pd.Bandwidth) + d.Set("storage_spec_code", pd.IOs[0].StorageSpecCode) + d.Set("io_type", pd.IOs[0].IOType) + log.Printf("[DEBUG] Dms product : %+v", pd) + } else { + if len(pd.ProductInfos) < 1 { + return fmt.Errorf("Your query returned no results. Please change your filters and try again.") + } + pdInfo := pd.ProductInfos[0] + d.SetId(pdInfo.ProductID) + d.Set("storage", pdInfo.Storage) + d.Set("io_type", pdInfo.IOs[0].IOType) + d.Set("node_num", pdInfo.NodeNum) + d.Set("storage_spec_code", pdInfo.IOs[0].StorageSpecCode) + log.Printf("[DEBUG] Dms product : %+v", pdInfo) + } + + return nil +} diff --git a/huaweicloud/data_source_huaweicloud_dms_product_v1_test.go b/huaweicloud/data_source_huaweicloud_dms_product_v1_test.go new file mode 100644 index 00000000000..d6db3cf8064 --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_dms_product_v1_test.go @@ -0,0 +1,126 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccDmsProductV1DataSource_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsProductV1DataSource_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsProductV1DataSourceID("data.huaweicloud_dms_product_v1.product1"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "engine", "kafka"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "partition_num", "300"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "storage", "600"), + ), + }, + }, + }) +} + +func TestAccDmsProductV1DataSource_rabbitmqSingle(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsProductV1DataSource_rabbitmqSingle, + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsProductV1DataSourceID("data.huaweicloud_dms_product_v1.product1"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "engine", "rabbitmq"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "node_num", "3"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "io_type", "normal"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "storage", "100"), + ), + }, + }, + }) +} + +func TestAccDmsProductV1DataSource_rabbitmqCluster(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsProductV1DataSource_rabbitmqCluster, + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsProductV1DataSourceID("data.huaweicloud_dms_product_v1.product1"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "engine", "rabbitmq"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "node_num", "5"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "storage", "500"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "io_type", "high"), + resource.TestCheckResourceAttr( + "data.huaweicloud_dms_product_v1.product1", "storage_spec_code", "dms.physical.storage.high"), + ), + }, + }, + }) +} + +func testAccCheckDmsProductV1DataSourceID(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Can't find Dms product data source: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("Dms product data source ID not set") + } + + return nil + } +} + +var testAccDmsProductV1DataSource_basic = fmt.Sprintf(` +data "huaweicloud_dms_product_v1" "product1" { +engine = "kafka" +version = "1.1.0" +instance_type = "cluster" +partition_num = 300 +storage = 600 +storage_spec_code = "dms.physical.storage.high" +} +`) + +var testAccDmsProductV1DataSource_rabbitmqSingle = fmt.Sprintf(` +data "huaweicloud_dms_product_v1" "product1" { +engine = "rabbitmq" +version = "3.7.0" +instance_type = "single" +node_num = 3 +storage = 100 +storage_spec_code = "dms.physical.storage.normal" +} +`) + +var testAccDmsProductV1DataSource_rabbitmqCluster = fmt.Sprintf(` +data "huaweicloud_dms_product_v1" "product1" { +engine = "rabbitmq" +version = "3.7.0" +instance_type = "cluster" +node_num = 5 +storage = 500 +storage_spec_code = "dms.physical.storage.high" +} +`) diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index f54d6a44dd2..a5eb91931d4 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -209,6 +209,9 @@ func Provider() terraform.ResourceProvider { "huaweicloud_vpc_subnet_v1": dataSourceVpcSubnetV1(), "huaweicloud_vpc_subnet_ids_v1": dataSourceVpcSubnetIdsV1(), "huaweicloud_rts_software_config_v1": dataSourceRtsSoftwareConfigV1(), + "huaweicloud_dms_az_v1": dataSourceDmsAZV1(), + "huaweicloud_dms_product_v1": dataSourceDmsProductV1(), + "huaweicloud_dms_maintainwindow_v1": dataSourceDmsMaintainWindowV1(), }, ResourcesMap: map[string]*schema.Resource{ @@ -226,6 +229,9 @@ func Provider() terraform.ResourceProvider { "huaweicloud_fw_policy_v2": resourceFWPolicyV2(), "huaweicloud_fw_rule_v2": resourceFWRuleV2(), "huaweicloud_kms_key_v1": resourceKmsKeyV1(), + "huaweicloud_dms_queue_v1": resourceDmsQueuesV1(), + "huaweicloud_dms_group_v1": resourceDmsGroupsV1(), + "huaweicloud_dms_instance_v1": resourceDmsInstancesV1(), "huaweicloud_elb_loadbalancer": resourceELBLoadBalancer(), "huaweicloud_elb_listener": resourceELBListener(), "huaweicloud_elb_healthcheck": resourceELBHealthCheck(), diff --git a/huaweicloud/resource_huaweicloud_dms_group_v1.go b/huaweicloud/resource_huaweicloud_dms_group_v1.go new file mode 100644 index 00000000000..0efe54b4780 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dms_group_v1.go @@ -0,0 +1,139 @@ +package huaweicloud + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/groups" +) + +func resourceDmsGroupsV1() *schema.Resource { + return &schema.Resource{ + Create: resourceDmsGroupsV1Create, + Read: resourceDmsGroupsV1Read, + Delete: resourceDmsGroupsV1Delete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "queue_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "consumed_messages": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "available_messages": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "produced_messages": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "produced_deadletters": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "available_deadletters": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + }, + } +} + +func resourceDmsGroupsV1Create(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms group client: %s", err) + } + + var getGroups []groups.GroupOps + + n := groups.GroupOps{ + Name: d.Get("name").(string), + } + getGroups = append(getGroups, n) + + createOpts := &groups.CreateOps{ + Groups: getGroups, + } + + log.Printf("[DEBUG] Create Options: %#v", createOpts) + + v, err := groups.Create(dmsV1Client, d.Get("queue_id").(string), createOpts).Extract() + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud group: %s", err) + } + log.Printf("[INFO] group Name: %s", v[0].Name) + + // Store the group ID now + d.SetId(v[0].ID) + d.Set("queue_id", d.Get("queue_id").(string)) + + return resourceDmsGroupsV1Read(d, meta) +} + +func resourceDmsGroupsV1Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms group client: %s", err) + } + + queueID := d.Get("queue_id").(string) + page, err := groups.List(dmsV1Client, queueID, false).AllPages() + if err != nil { + return fmt.Errorf("Error getting groups in queue %s: %s", queueID, err) + } + groupsList, err := groups.ExtractGroups(page) + if len(groupsList) < 1 { + return fmt.Errorf("No matching resource found.") + } + + if len(groupsList) > 1 { + return fmt.Errorf("Multiple resources matched;") + } + + group := groupsList[0] + log.Printf("[DEBUG] Dms group %s: %+v", d.Id(), group) + + d.SetId(group.ID) + d.Set("name", group.Name) + d.Set("consumed_messages", group.ConsumedMessages) + d.Set("available_messages", group.AvailableMessages) + d.Set("produced_messages", group.ProducedMessages) + d.Set("produced_deadletters", group.ProducedDeadletters) + d.Set("available_deadletters", group.AvailableDeadletters) + + return nil +} + +func resourceDmsGroupsV1Delete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms group client: %s", err) + } + + err = groups.Delete(dmsV1Client, d.Get("queue_id").(string), d.Id()).ExtractErr() + if err != nil { + return fmt.Errorf("Error deleting HuaweiCloud group: %s", err) + } + + log.Printf("[DEBUG] Dms group %s deactivated.", d.Id()) + d.SetId("") + return nil +} diff --git a/huaweicloud/resource_huaweicloud_dms_group_v1_test.go b/huaweicloud/resource_huaweicloud_dms_group_v1_test.go new file mode 100644 index 00000000000..177c4f6b8ee --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dms_group_v1_test.go @@ -0,0 +1,115 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/groups" + + "github.com/hashicorp/terraform/helper/acctest" +) + +func TestAccDmsGroupsV1_basic(t *testing.T) { + var group groups.Group + var groupName = fmt.Sprintf("dms_group_%s", acctest.RandString(5)) + var queueName = fmt.Sprintf("dms_queue_%s", acctest.RandString(5)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDmsV1GroupDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsV1Group_basic(groupName, queueName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsV1GroupExists("huaweicloud_dms_group_v1.group_1", group), + resource.TestCheckResourceAttr( + "huaweicloud_dms_group_v1.group_1", "name", groupName), + ), + }, + }, + }) +} + +func testAccCheckDmsV1GroupDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + dmsClient, err := config.dmsV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud group client: %s", err) + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "huaweicloud_dms_group_v1" { + continue + } + + queueID := rs.Primary.Attributes["queue_id"] + page, err := groups.List(dmsClient, queueID, false).AllPages() + if err == nil { + groupsList, err := groups.ExtractGroups(page) + if err != nil { + return fmt.Errorf("Error getting groups in queue %s: %s", queueID, err) + } + if len(groupsList) > 0 { + for _, group := range groupsList { + if group.ID == rs.Primary.ID { + return fmt.Errorf("The Dms group still exists.") + } + } + } + } + } + return nil +} + +func testAccCheckDmsV1GroupExists(n string, group groups.Group) 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) + dmsClient, err := config.dmsV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud group client: %s", err) + } + + queueID := rs.Primary.Attributes["queue_id"] + page, err := groups.List(dmsClient, queueID, false).AllPages() + if err != nil { + return fmt.Errorf("Error getting groups in queue %s: %s", queueID, err) + } + + groupsList, err := groups.ExtractGroups(page) + if len(groupsList) > 0 { + for _, found := range groupsList { + if found.ID == rs.Primary.ID { + group = found + return nil + } + } + } + return fmt.Errorf("The Dms group not found.") + } +} + + + +func testAccDmsV1Group_basic(groupName string, queueName string) string { + return fmt.Sprintf(` + resource "huaweicloud_dms_queue_v1" "queue_1" { + name = "%s" + } + resource "huaweicloud_dms_group_v1" "group_1" { + name = "%s" + queue_id = "${huaweicloud_dms_queue_v1.queue_1.id}" + } + `, queueName, groupName) +} diff --git a/huaweicloud/resource_huaweicloud_dms_instance_v1.go b/huaweicloud/resource_huaweicloud_dms_instance_v1.go new file mode 100644 index 00000000000..7e437ac05c4 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dms_instance_v1.go @@ -0,0 +1,342 @@ +package huaweicloud + +import ( + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/instances" +) + +func resourceDmsInstancesV1() *schema.Resource { + return &schema.Resource{ + Create: resourceDmsInstancesV1Create, + Read: resourceDmsInstancesV1Read, + Update: resourceDmsInstancesV1Update, + Delete: resourceDmsInstancesV1Delete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "engine": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "engine_version": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "storage_space": &schema.Schema{ + Type: schema.TypeInt, + Required: true, + }, + "password": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "access_user": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "vpc_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "security_group_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "subnet_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "available_zones": &schema.Schema{ + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "product_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + "maintain_begin": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "maintain_end": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "partition_num": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "created_at": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "user_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "order_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "vpc_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "security_group_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "subnet_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "connect_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "port": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "resource_spec_code": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "used_storage_space": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "specification": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "storage_spec_code": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + }, + } +} + +func resourceDmsInstancesV1Create(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms instance client: %s", err) + } + + ssl_enable := false + if d.Get("access_user").(string) != "" || d.Get("password").(string) != ""{ + ssl_enable = true + } + createOpts := &instances.CreateOps{ + Name: d.Get("name").(string), + Description: d.Get("description").(string), + Engine: d.Get("engine").(string), + EngineVersion: d.Get("engine_version").(string), + StorageSpace: d.Get("storage_space").(int), + Password: d.Get("password").(string), + AccessUser: d.Get("access_user").(string), + VPCID: d.Get("vpc_id").(string), + SecurityGroupID: d.Get("security_group_id").(string), + SubnetID: d.Get("subnet_id").(string), + AvailableZones: getAllAvailableZones(d), + ProductID: d.Get("product_id").(string), + MaintainBegin: d.Get("maintain_begin").(string), + MaintainEnd: d.Get("maintain_end").(string), + PartitionNum: d.Get("partition_num").(int), + Specification: d.Get("specification").(string), + StorageSpecCode: d.Get("storage_spec_code").(string), + SslEnable: ssl_enable, + } + + log.Printf("[DEBUG] Create Options: %#v", createOpts) + v, err := instances.Create(dmsV1Client, createOpts).Extract() + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud instance: %s", err) + } + log.Printf("[INFO] instance ID: %s", v.InstanceID) + + stateConf := &resource.StateChangeConf{ + Pending: []string{"CREATING"}, + Target: []string{"RUNNING"}, + Refresh: DmsInstancesV1StateRefreshFunc(dmsV1Client, v.InstanceID), + Timeout: d.Timeout(schema.TimeoutCreate), + Delay: 10 * time.Second, + MinTimeout: 3 * time.Second, + } + _, err = stateConf.WaitForState() + if err != nil { + return fmt.Errorf( + "Error waiting for instance (%s) to become ready: %s", + v.InstanceID, err) + } + + // Store the instance ID now + d.SetId(v.InstanceID) + + return resourceDmsInstancesV1Read(d, meta) +} + +func resourceDmsInstancesV1Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms instance client: %s", err) + } + v, err := instances.Get(dmsV1Client, d.Id()).Extract() + if err != nil { + return err + } + + log.Printf("[DEBUG] Dms instance %s: %+v", d.Id(), v) + + d.SetId(v.InstanceID) + d.Set("name", v.Name) + d.Set("engine", v.Engine) + d.Set("engine_version", v.EngineVersion) + d.Set("specification", v.Specification) + d.Set("used_storage_space", v.UsedStorageSpace) + d.Set("connect_address", v.ConnectAddress) + d.Set("port", v.Port) + d.Set("status", v.Status) + d.Set("description", v.Description) + d.Set("instance_id", v.InstanceID) + d.Set("resource_spec_code", v.ResourceSpecCode) + d.Set("type", v.Type) + d.Set("vpc_id", v.VPCID) + d.Set("vpc_name", v.VPCName) + d.Set("created_at", v.CreatedAt) + d.Set("product_id", v.ProductID) + d.Set("security_group_id", v.SecurityGroupID) + d.Set("security_group_name", v.SecurityGroupName) + d.Set("subnet_id", v.SubnetID) + d.Set("subnet_name", v.SubnetName) + d.Set("user_id", v.UserID) + d.Set("user_name", v.UserName) + d.Set("order_id", v.OrderID) + d.Set("maintain_begin", v.MaintainBegin) + d.Set("maintain_end", v.MaintainEnd) + + return nil +} + +func resourceDmsInstancesV1Update(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error updating HuaweiCloud dms instance client: %s", err) + } + var updateOpts instances.UpdateOpts + if d.HasChange("name") { + updateOpts.Name = d.Get("name").(string) + } + if d.HasChange("description") { + description := d.Get("description").(string) + updateOpts.Description = &description + } + if d.HasChange("maintain_begin") { + maintain_begin := d.Get("maintain_begin").(string) + updateOpts.MaintainBegin = maintain_begin + } + if d.HasChange("maintain_end") { + maintain_end := d.Get("maintain_end").(string) + updateOpts.MaintainEnd = maintain_end + } + if d.HasChange("security_group_id") { + security_group_id := d.Get("security_group_id").(string) + updateOpts.SecurityGroupID = security_group_id + } + + err = instances.Update(dmsV1Client, d.Id(), updateOpts).Err + if err != nil { + return fmt.Errorf("Error updating HuaweiCloud Dms Instance: %s", err) + } + + return resourceDmsInstancesV1Read(d, meta) +} + +func resourceDmsInstancesV1Delete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms instance client: %s", err) + } + + _, err = instances.Get(dmsV1Client, d.Id()).Extract() + if err != nil { + return CheckDeleted(d, err, "instance") + } + + err = instances.Delete(dmsV1Client, d.Id()).ExtractErr() + if err != nil { + return fmt.Errorf("Error deleting HuaweiCloud instance: %s", err) + } + + // Wait for the instance to delete before moving on. + log.Printf("[DEBUG] Waiting for instance (%s) to delete", d.Id()) + + stateConf := &resource.StateChangeConf{ + Pending: []string{"DELETING", "RUNNING"}, + Target: []string{"DELETED"}, + Refresh: DmsInstancesV1StateRefreshFunc(dmsV1Client, d.Id()), + Timeout: d.Timeout(schema.TimeoutDelete), + Delay: 10 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + if err != nil { + return fmt.Errorf( + "Error waiting for instance (%s) to delete: %s", + d.Id(), err) + } + + log.Printf("[DEBUG] Dms instance %s deactivated.", d.Id()) + d.SetId("") + return nil +} + +func DmsInstancesV1StateRefreshFunc(client *golangsdk.ServiceClient, instanceID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + v, err := instances.Get(client, instanceID).Extract() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + return v, "DELETED", nil + } + return nil, "", err + } + + return v, v.Status, nil + } +} diff --git a/huaweicloud/resource_huaweicloud_dms_instance_v1_test.go b/huaweicloud/resource_huaweicloud_dms_instance_v1_test.go new file mode 100644 index 00000000000..03f2b4e1443 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dms_instance_v1_test.go @@ -0,0 +1,209 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/instances" + + "github.com/hashicorp/terraform/helper/acctest" +) + +func TestAccDmsInstancesV1_basic(t *testing.T) { + var instance instances.Instance + var instanceName = fmt.Sprintf("dms_instance_%s", acctest.RandString(5)) + var instanceUpdate = fmt.Sprintf("dms_instance_update_%s", acctest.RandString(5)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDmsV1InstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsV1Instance_basic(instanceName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsV1InstanceExists("huaweicloud_dms_instance_v1.instance_1", instance), + resource.TestCheckResourceAttr( + "huaweicloud_dms_instance_v1.instance_1", "name", instanceName), + resource.TestCheckResourceAttr( + "huaweicloud_dms_instance_v1.instance_1", "engine", "rabbitmq"), + ), + }, + resource.TestStep{ + Config: testAccDmsV1Instance_update(instanceUpdate), + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsV1InstanceExists("huaweicloud_dms_instance_v1.instance_1", instance), + resource.TestCheckResourceAttr( + "huaweicloud_dms_instance_v1.instance_1", "name", instanceUpdate), + resource.TestCheckResourceAttr( + "huaweicloud_dms_instance_v1.instance_1", "description", "instance update description"), + ), + }, + }, + }) +} + +func TestAccDmsInstancesV1_KafkaInstance(t *testing.T) { + var instance instances.Instance + var instanceName = fmt.Sprintf("dms_instance_%s", acctest.RandString(5)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDmsV1InstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsV1Instance_KafkaInstance(instanceName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsV1InstanceExists("huaweicloud_dms_instance_v1.instance_1", instance), + resource.TestCheckResourceAttr( + "huaweicloud_dms_instance_v1.instance_1", "name", instanceName), + ), + }, + }, + }) +} + +func testAccCheckDmsV1InstanceDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + dmsClient, err := config.dmsV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud instance client: %s", err) + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "huaweicloud_dms_instance_v1" { + continue + } + + _, err := instances.Get(dmsClient, rs.Primary.ID).Extract() + if err == nil { + return fmt.Errorf("The Dms instance still exists.") + } + } + return nil +} + +func testAccCheckDmsV1InstanceExists(n string, instance instances.Instance) 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) + dmsClient, err := config.dmsV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud instance client: %s", err) + } + + v, err := instances.Get(dmsClient, rs.Primary.ID).Extract() + if err != nil { + return fmt.Errorf("Error getting HuaweiCloud instance: %s, err: %s", rs.Primary.ID, err) + } + + if v.InstanceID != rs.Primary.ID { + return fmt.Errorf("The Dms instance not found.") + } + instance = *v + return nil + } +} + +func testAccDmsV1Instance_basic(instanceName string) string { + return fmt.Sprintf(` + resource "huaweicloud_networking_secgroup_v2" "secgroup_1" { + name = "secgroup_1" + description = "secgroup_1" + } + data "huaweicloud_dms_az_v1" "az_1" { + } + data "huaweicloud_dms_product_v1" "product_1" { + engine = "rabbitmq" + instance_type = "single" + version = "3.7.0" + } + resource "huaweicloud_dms_instance_v1" "instance_1" { + name = "%s" + engine = "rabbitmq" + storage_space = "${data.huaweicloud_dms_product_v1.product_1.storage}" + access_user = "user" + password = "Dmstest@123" + vpc_id = "%s" + security_group_id = "${huaweicloud_networking_secgroup_v2.secgroup_1.id}" + subnet_id = "%s" + available_zones = ["${data.huaweicloud_dms_az_v1.az_1.id}"] + product_id = "${data.huaweicloud_dms_product_v1.product_1.id}" + engine_version = "${data.huaweicloud_dms_product_v1.product_1.version}" + depends_on = ["data.huaweicloud_dms_product_v1.product_1", "huaweicloud_networking_secgroup_v2.secgroup_1"] + } + `, instanceName, OS_VPC_ID, OS_NETWORK_ID) +} + +func testAccDmsV1Instance_update(instanceUpdate string) string { + return fmt.Sprintf(` + resource "huaweicloud_networking_secgroup_v2" "secgroup_1" { + name = "secgroup_1" + description = "secgroup_1" + } + data "huaweicloud_dms_az_v1" "az_1" { + } + data "huaweicloud_dms_product_v1" "product_1" { + engine = "rabbitmq" + instance_type = "single" + version = "3.7.0" + } + resource "huaweicloud_dms_instance_v1" "instance_1" { + name = "%s" + description = "instance update description" + engine = "rabbitmq" + storage_space = "${data.huaweicloud_dms_product_v1.product_1.storage}" + access_user = "user" + password = "Dmstest@123" + vpc_id = "%s" + security_group_id = "${huaweicloud_networking_secgroup_v2.secgroup_1.id}" + subnet_id = "%s" + available_zones = ["${data.huaweicloud_dms_az_v1.az_1.id}"] + product_id = "${data.huaweicloud_dms_product_v1.product_1.id}" + engine_version = "${data.huaweicloud_dms_product_v1.product_1.version}" + depends_on = ["data.huaweicloud_dms_product_v1.product_1", "huaweicloud_networking_secgroup_v2.secgroup_1"] + } + `, instanceUpdate, OS_VPC_ID, OS_NETWORK_ID) +} + +func testAccDmsV1Instance_KafkaInstance(instanceName string) string { + return fmt.Sprintf(` + resource "huaweicloud_networking_secgroup_v2" "secgroup_1" { + name = "secgroup_1" + description = "secgroup_1" + } + data "huaweicloud_dms_az_v1" "az_1" { + } + data "huaweicloud_dms_product_v1" "product_1" { + engine = "kafka" + instance_type = "cluster" + version = "1.1.0" + } + resource "huaweicloud_dms_instance_v1" "instance_1" { + name = "%s" + engine = "kafka" + partition_num = "${data.huaweicloud_dms_product_v1.product_1.partition_num}" + storage_space = "${data.huaweicloud_dms_product_v1.product_1.storage}" + specification = "${data.huaweicloud_dms_product_v1.product_1.bandwidth}" + vpc_id = "%s" + security_group_id = "${huaweicloud_networking_secgroup_v2.secgroup_1.id}" + subnet_id = "%s" + available_zones = ["${data.huaweicloud_dms_az_v1.az_1.id}"] + product_id = "${data.huaweicloud_dms_product_v1.product_1.id}" + engine_version = "${data.huaweicloud_dms_product_v1.product_1.version}" + storage_spec_code = "${data.huaweicloud_dms_product_v1.product_1.storage_spec_code}" + depends_on = ["data.huaweicloud_dms_product_v1.product_1", "huaweicloud_networking_secgroup_v2.secgroup_1"] + } + `, instanceName, OS_VPC_ID, OS_NETWORK_ID) +} diff --git a/huaweicloud/resource_huaweicloud_dms_queue_v1.go b/huaweicloud/resource_huaweicloud_dms_queue_v1.go new file mode 100644 index 00000000000..cf931c2051d --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dms_queue_v1.go @@ -0,0 +1,158 @@ +package huaweicloud + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/queues" +) + +func resourceDmsQueuesV1() *schema.Resource { + return &schema.Resource{ + Create: resourceDmsQueuesV1Create, + Read: resourceDmsQueuesV1Read, + Delete: resourceDmsQueuesV1Delete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "queue_mode": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "redrive_policy": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "max_consume_count": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + "retention_hours": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + "created": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "reservation": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "max_msg_size_byte": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "produced_messages": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + "group_count": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + }, + } +} + +func resourceDmsQueuesV1Create(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms queue client: %s", err) + } + + createOpts := &queues.CreateOps{ + Name: d.Get("name").(string), + QueueMode: d.Get("queue_mode").(string), + Description: d.Get("description").(string), + RedrivePolicy: d.Get("redrive_policy").(string), + MaxConsumeCount: d.Get("max_consume_count").(int), + RetentionHours: d.Get("retention_hours").(int), + } + + log.Printf("[DEBUG] Create Options: %#v", createOpts) + v, err := queues.Create(dmsV1Client, createOpts).Extract() + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud queue: %s", err) + } + log.Printf("[INFO] Queue ID: %s", v.ID) + + // Store the queue ID now + d.SetId(v.ID) + + return resourceDmsQueuesV1Read(d, meta) +} + +func resourceDmsQueuesV1Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms queue client: %s", err) + } + v, err := queues.Get(dmsV1Client, d.Id(), true).Extract() + if err != nil { + return err + } + + log.Printf("[DEBUG] Dms queue %s: %+v", d.Id(), v) + + d.SetId(v.ID) + d.Set("name", v.Name) + d.Set("created", v.Created) + d.Set("description", v.Description) + d.Set("queue_mode", v.QueueMode) + d.Set("reservation", v.Reservation) + d.Set("max_msg_size_byte", v.MaxMsgSizeByte) + d.Set("produced_messages", v.ProducedMessages) + d.Set("redrive_policy", v.RedrivePolicy) + d.Set("max_consume_count", v.MaxConsumeCount) + d.Set("group_count", v.GroupCount) + + return nil +} + +func resourceDmsQueuesV1Delete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud dms queue client: %s", err) + } + + v, err := queues.Get(dmsV1Client, d.Id(), false).Extract() + if err != nil { + return CheckDeleted(d, err, "queue") + } + + err = queues.Delete(dmsV1Client, d.Id()).ExtractErr() + if err != nil { + return fmt.Errorf("Error deleting HuaweiCloud queue: %s", err) + } + + log.Printf("[DEBUG] Dms queue %s: %+v deactivated.", d.Id(), v) + d.SetId("") + return nil +} diff --git a/huaweicloud/resource_huaweicloud_dms_queue_v1_test.go b/huaweicloud/resource_huaweicloud_dms_queue_v1_test.go new file mode 100644 index 00000000000..b64aa3f6fc4 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_dms_queue_v1_test.go @@ -0,0 +1,133 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/huaweicloud/golangsdk/openstack/dms/v1/queues" + + "github.com/hashicorp/terraform/helper/acctest" +) + +func TestAccDmsQueuesV1_basic(t *testing.T) { + var queue queues.Queue + var queueName = fmt.Sprintf("dms_queue_%s", acctest.RandString(5)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDmsV1QueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsV1Queue_basic(queueName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsV1QueueExists("huaweicloud_dms_queue_v1.queue_1", queue), + resource.TestCheckResourceAttr( + "huaweicloud_dms_queue_v1.queue_1", "name", queueName), + resource.TestCheckResourceAttr( + "huaweicloud_dms_queue_v1.queue_1", "queue_mode", "NORMAL"), + ), + }, + }, + }) +} + +func TestAccDmsQueuesV1_FIFOmode(t *testing.T) { + var queue queues.Queue + var queueName = fmt.Sprintf("dms_queue_%s", acctest.RandString(5)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDmsV1QueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDmsV1Queue_FIFOmode(queueName), + Check: resource.ComposeTestCheckFunc( + testAccCheckDmsV1QueueExists("huaweicloud_dms_queue_v1.queue_1", queue), + resource.TestCheckResourceAttr( + "huaweicloud_dms_queue_v1.queue_1", "name", queueName), + resource.TestCheckResourceAttr( + "huaweicloud_dms_queue_v1.queue_1", "description", "test create dms queue"), + resource.TestCheckResourceAttr( + "huaweicloud_dms_queue_v1.queue_1", "queue_mode", "FIFO"), + resource.TestCheckResourceAttr( + "huaweicloud_dms_queue_v1.queue_1", "redrive_policy", "enable"), + resource.TestCheckResourceAttr( + "huaweicloud_dms_queue_v1.queue_1", "max_consume_count", "80"), + ), + }, + }, + }) +} + +func testAccCheckDmsV1QueueDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + dmsClient, err := config.dmsV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud queue client: %s", err) + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "huaweicloud_dms_queue_v1" { + continue + } + + _, err := queues.Get(dmsClient, rs.Primary.ID, false).Extract() + if err == nil { + return fmt.Errorf("The Dms queue still exists.") + } + } + return nil +} + +func testAccCheckDmsV1QueueExists(n string, queue queues.Queue) 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) + dmsClient, err := config.dmsV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud queue client: %s", err) + } + + v, err := queues.Get(dmsClient, rs.Primary.ID, false).Extract() + if err != nil { + return fmt.Errorf("Error getting HuaweiCloud queue: %s, err: %s", rs.Primary.ID, err) + } + if v.ID != rs.Primary.ID { + return fmt.Errorf("The Dms queue not found.") + } + queue = *v + return nil + } +} + +func testAccDmsV1Queue_basic(queueName string) string { + return fmt.Sprintf(` + resource "huaweicloud_dms_queue_v1" "queue_1" { + name = "%s" + } + `, queueName) +} + +func testAccDmsV1Queue_FIFOmode(queueName string) string { + return fmt.Sprintf(` + resource "huaweicloud_dms_queue_v1" "queue_1" { + name = "%s" + description = "test create dms queue" + queue_mode = "FIFO" + redrive_policy = "enable" + max_consume_count = 80 + } + `, queueName) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/requests.go new file mode 100644 index 00000000000..47d242ca30e --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/requests.go @@ -0,0 +1,11 @@ +package availablezones + +import ( + "github.com/huaweicloud/golangsdk" +) + +// Get available zones +func Get(client *golangsdk.ServiceClient) (r GetResult) { + _, r.Err = client.Get(getURL(client), &r.Body, nil) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/results.go new file mode 100644 index 00000000000..b2d9ecbd428 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/results.go @@ -0,0 +1,32 @@ +package availablezones + +import ( + "github.com/huaweicloud/golangsdk" +) + +// GetResponse response +type GetResponse struct { + RegionID string `json:"regionId"` + AvailableZones []AvailableZone `json:"available_zones"` +} + +// AvailableZone for dms +type AvailableZone struct { + ID string `json:"id"` + Code string `json:"code"` + Name string `json:"name"` + Port string `json:"port"` + ResourceAvailability string `json:"resource_availability"` +} + +// GetResult contains the body of getting detailed +type GetResult struct { + golangsdk.Result +} + +// Extract from GetResult +func (r GetResult) Extract() (*GetResponse, error) { + var s GetResponse + err := r.Result.ExtractInto(&s) + return &s, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/urls.go new file mode 100644 index 00000000000..9ce0f01e874 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones/urls.go @@ -0,0 +1,16 @@ +package availablezones + +import ( + "strings" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/availablezones +const resourcePath = "availableZones" + +// getURL will build the get url of get function +func getURL(client *golangsdk.ServiceClient) string { + // remove projectid from endpoint + return strings.Replace(client.ServiceURL(resourcePath), "/"+client.ProjectID, "", -1) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/requests.go new file mode 100644 index 00000000000..e733106431f --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/requests.go @@ -0,0 +1,61 @@ +package groups + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// CreateOpsBuilder is used for creating group parameters. +// any struct providing the parameters should implement this interface +type CreateOpsBuilder interface { + ToGroupCreateMap() (map[string]interface{}, error) +} + +// CreateOps is a struct that contains all the parameters. +type CreateOps struct { + // Indicates the informations of a consumer group. + Groups []GroupOps `json:"groups" required:"true"` +} + +// GroupOps is referred by CreateOps +type GroupOps struct { + // Indicates the name of a consumer group. + // A string of 1 to 32 characters that contain + // a-z, A-Z, 0-9, hyphens (-), and underscores (_). + Name string `json:"name" required:"true"` +} + +// ToGroupCreateMap is used for type convert +func (ops CreateOps) ToGroupCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(ops, "") +} + +// Create a group with given parameters. +func Create(client *golangsdk.ServiceClient, queueID string, ops CreateOpsBuilder) (r CreateResult) { + b, err := ops.ToGroupCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(createURL(client, queueID), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{201}, + }) + + return +} + +// Delete a group by id +func Delete(client *golangsdk.ServiceClient, queueID string, groupID string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, queueID, groupID), nil) + return +} + +// List all the groups +func List(client *golangsdk.ServiceClient, queueID string, includeDeadLetter bool) pagination.Pager { + url := listURL(client, queueID, includeDeadLetter) + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return GroupPage{pagination.SinglePageBase(r)} + }) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/results.go new file mode 100644 index 00000000000..daac1a0f9ad --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/results.go @@ -0,0 +1,69 @@ +package groups + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// GroupCreate response +type GroupCreate struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// CreateResult is a struct that contains all the return parameters of creation +type CreateResult struct { + golangsdk.Result +} + +// Extract from CreateResult +func (r CreateResult) Extract() ([]GroupCreate, error) { + var s struct { + GroupsCreate []GroupCreate `json:"groups"` + } + err := r.Result.ExtractInto(&s) + return s.GroupsCreate, err +} + +// DeleteResult is a struct which contains the result of deletion +type DeleteResult struct { + golangsdk.ErrResult +} + +// Group response +type Group struct { + ID string `json:"id"` + Name string `json:"name"` + ConsumedMessages int `json:"consumed_messages"` + AvailableMessages int `json:"available_messages"` + ProducedMessages int `json:"produced_messages"` + ProducedDeadletters int `json:"produced_deadletters"` + AvailableDeadletters int `json:"available_deadletters"` +} + +type Groups struct { + QueueId string `json:"queue_id"` + QueueName string `json:"queue_name"` + Details []Group `json:"groups"` +} + +// GroupPage may be embedded in a Page +// that contains all of the results from an operation at once. +type GroupPage struct { + pagination.SinglePageBase +} + +// IsEmpty returns true if a ListResult contains no groups. +func (r GroupPage) IsEmpty() (bool, error) { + rs, err := ExtractGroups(r) + return len(rs) == 0, err +} + +// ExtractGroups from List +func ExtractGroups(r pagination.Page) ([]Group, error) { + var s struct { + Groups []Group `json:"groups"` + } + err := (r.(GroupPage)).ExtractInto(&s) + return s.Groups, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/urls.go new file mode 100644 index 00000000000..ccba6c88731 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/groups/urls.go @@ -0,0 +1,26 @@ +package groups + +import ( + "fmt" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/queues/{queue_id}/groups +const resourcePathQueues = "queues" +const resourcePathGroups = "groups" + +// createURL will build the rest query url of creation +func createURL(client *golangsdk.ServiceClient, queueID string) string { + return client.ServiceURL(resourcePathQueues, queueID, resourcePathGroups) +} + +// deleteURL will build the url of deletion +func deleteURL(client *golangsdk.ServiceClient, queueID string, groupID string) string { + return client.ServiceURL(resourcePathQueues, queueID, resourcePathGroups, groupID) +} + +// listURL will build the list url of list function +func listURL(client *golangsdk.ServiceClient, queueID string, includeDeadLetter bool) string { + return client.ServiceURL(resourcePathQueues, queueID, fmt.Sprintf("%s?include_deadletter=%t", resourcePathGroups, includeDeadLetter)) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/requests.go new file mode 100644 index 00000000000..9cc78a2c57a --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/requests.go @@ -0,0 +1,169 @@ +package instances + +import ( + "github.com/huaweicloud/golangsdk" +) + +// CreateOpsBuilder is used for creating instance parameters. +// any struct providing the parameters should implement this interface +type CreateOpsBuilder interface { + ToInstanceCreateMap() (map[string]interface{}, error) +} + +// CreateOps is a struct that contains all the parameters. +type CreateOps struct { + // Indicates the name of an instance. + // An instance name starts with a letter, + // consists of 4 to 64 characters, and supports + // only letters, digits, and hyphens (-). + Name string `json:"name" required:"true"` + + // Indicates the description of an instance. + // It is a character string containing not more than 1024 characters. + Description string `json:"description,omitempty"` + + // Indicates a message engine. + // Currently, only RabbitMQ is supported. + Engine string `json:"engine" required:"true"` + + // Indicates the version of a message engine. + EngineVersion string `json:"engine_version,omitempty"` + + // Indicates the message storage space. + StorageSpace int `json:"storage_space" required:"true"` + + // Indicates the password of an instance. + // An instance password must meet the following complexity requirements: + // Must be 6 to 32 characters long. + // Must contain at least two of the following character types: + // Lowercase letters + // Uppercase letters + // Digits + // Special characters (`~!@#$%^&*()-_=+\|[{}]:'",<.>/?) + Password string `json:"password,omitempty"` + + // Indicates a username. + // A username consists of 1 to 64 characters + // and supports only letters, digits, and hyphens (-). + AccessUser string `json:"access_user,omitempty"` + + // Indicates the ID of a VPC. + VPCID string `json:"vpc_id" required:"true"` + + // Indicates the ID of a security group. + SecurityGroupID string `json:"security_group_id" required:"true"` + + // Indicates the ID of a subnet. + SubnetID string `json:"subnet_id" required:"true"` + + // Indicates the ID of an AZ. + // The parameter value can be left blank or an empty array. + AvailableZones []string `json:"available_zones,omitempty"` + + // Indicates a product ID. + ProductID string `json:"product_id" required:"true"` + + // Indicates the time at which a maintenance time window starts. + // Format: HH:mm:ss + MaintainBegin string `json:"maintain_begin,omitempty"` + + // Indicates the time at which a maintenance time window ends. + // Format: HH:mm:ss + MaintainEnd string `json:"maintain_end,omitempty"` + + //This parameter is mandatory when a Kafka instance is created. + //Indicates the maximum number of topics in a Kafka instance. + PartitionNum int `json:"partition_num,omitempty"` + + //Indicates whether to enable SSL-encrypted access. + SslEnable bool `json:"ssl_enable"` + + //This parameter is mandatory if the engine is kafka. + //Indicates the baseline bandwidth of a Kafka instance, that is, + //the maximum amount of data transferred per unit time. Unit: byte/s. + Specification string `json:"specification,omitempty"` + + //Indicates the storage I/O specification. For details on how to select a disk type + StorageSpecCode string `json:"storage_spec_code,omitempty"` +} + +// ToInstanceCreateMap is used for type convert +func (ops CreateOps) ToInstanceCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(ops, "") +} + +// Create an instance with given parameters. +func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) { + b, err := ops.ToInstanceCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + + return +} + +// Delete an instance by id +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} + +//UpdateOptsBuilder is an interface which can build the map paramter of update function +type UpdateOptsBuilder interface { + ToInstanceUpdateMap() (map[string]interface{}, error) +} + +//UpdateOpts is a struct which represents the parameters of update function +type UpdateOpts struct { + // Indicates the name of an instance. + // An instance name starts with a letter, + // consists of 4 to 64 characters, + // and supports only letters, digits, and hyphens (-). + Name string `json:"name,omitempty"` + + // Indicates the description of an instance. + // It is a character string containing not more than 1024 characters. + Description *string `json:"description,omitempty"` + + // Indicates the time at which a maintenance time window starts. + // Format: HH:mm:ss + MaintainBegin string `json:"maintain_begin,omitempty"` + + // Indicates the time at which a maintenance time window ends. + // Format: HH:mm:ss + MaintainEnd string `json:"maintain_end,omitempty"` + + // Indicates the ID of a security group. + SecurityGroupID string `json:"security_group_id,omitempty"` +} + +// ToInstanceUpdateMap is used for type convert +func (opts UpdateOpts) ToInstanceUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "") +} + +// Update is a method which can be able to update the instance +// via accessing to the service with Put method and parameters +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + body, err := opts.ToInstanceUpdateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Put(updateURL(client, id), body, nil, &golangsdk.RequestOpts{ + OkCodes: []int{204}, + }) + return +} + +// Get a instance with detailed information by id +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, nil) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/results.go new file mode 100644 index 00000000000..7e82e9fa5b4 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/results.go @@ -0,0 +1,78 @@ +package instances + +import ( + "github.com/huaweicloud/golangsdk" +) + +// InstanceCreate response +type InstanceCreate struct { + InstanceID string `json:"instance_id"` +} + +// CreateResult is a struct that contains all the return parameters of creation +type CreateResult struct { + golangsdk.Result +} + +// Extract from CreateResult +func (r CreateResult) Extract() (*InstanceCreate, error) { + var s InstanceCreate + err := r.Result.ExtractInto(&s) + return &s, err +} + +// DeleteResult is a struct which contains the result of deletion +type DeleteResult struct { + golangsdk.ErrResult +} + +// Instance response +type Instance struct { + Name string `json:"name"` + Engine string `json:"engine"` + EngineVersion string `json:"engine_version"` + Specification string `json:"specification"` + StorageSpace int `json:"storage_space"` + UsedStorageSpace int `json:"used_storage_space"` + ConnectAddress string `json:"connect_address"` + Port int `json:"port"` + Status string `json:"status"` + Description string `json:"description"` + InstanceID string `json:"instance_id"` + ResourceSpecCode string `json:"resource_spec_code"` + Type string `json:"type"` + ChargingMode int `json:"charging_mode"` + VPCID string `json:"vpc_id"` + VPCName string `json:"vpc_name"` + CreatedAt string `json:"created_at"` + ErrorCode string `json:"error_code"` + ProductID string `json:"product_id"` + SecurityGroupID string `json:"security_group_id"` + SecurityGroupName string `json:"security_group_name"` + SubnetID string `json:"subnet_id"` + SubnetName string `json:"subnet_name"` + SubnetCIDR string `json:"subnet_cidr"` + AvailableZones []string `json:"available_zones"` + UserID string `json:"user_id"` + UserName string `json:"user_name"` + OrderID string `json:"order_id"` + MaintainBegin string `json:"maintain_begin"` + MaintainEnd string `json:"maintain_end"` +} + +// UpdateResult is a struct from which can get the result of update method +type UpdateResult struct { + golangsdk.Result +} + +// GetResult contains the body of getting detailed +type GetResult struct { + golangsdk.Result +} + +// Extract from GetResult +func (r GetResult) Extract() (*Instance, error) { + var s Instance + err := r.Result.ExtractInto(&s) + return &s, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/urls.go new file mode 100644 index 00000000000..9308ec2c8a9 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/instances/urls.go @@ -0,0 +1,26 @@ +package instances + +import "github.com/huaweicloud/golangsdk" + +// endpoint/instances +const resourcePath = "instances" + +// createURL will build the rest query url of creation +func createURL(client *golangsdk.ServiceClient) string { + return client.ServiceURL(resourcePath) +} + +// deleteURL will build the url of deletion +func deleteURL(client *golangsdk.ServiceClient, id string) string { + return client.ServiceURL(resourcePath, id) +} + +// updateURL will build the url of update +func updateURL(c *golangsdk.ServiceClient, id string) string { + return c.ServiceURL(resourcePath, id) +} + +// getURL will build the get url of get function +func getURL(client *golangsdk.ServiceClient, id string) string { + return client.ServiceURL(resourcePath, id) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/requests.go new file mode 100644 index 00000000000..4f866c63885 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/requests.go @@ -0,0 +1,11 @@ +package maintainwindows + +import ( + "github.com/huaweicloud/golangsdk" +) + +// Get maintain windows +func Get(client *golangsdk.ServiceClient) (r GetResult) { + _, r.Err = client.Get(getURL(client), &r.Body, nil) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/results.go new file mode 100644 index 00000000000..1327e2dbb8b --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/results.go @@ -0,0 +1,30 @@ +package maintainwindows + +import ( + "github.com/huaweicloud/golangsdk" +) + +// GetResponse response +type GetResponse struct { + MaintainWindows []MaintainWindow `json:"maintain_windows"` +} + +// MaintainWindow for dms +type MaintainWindow struct { + ID int `json:"seq"` + Begin string `json:"begin"` + End string `json:"end"` + Default bool `json:"default"` +} + +// GetResult contains the body of getting detailed +type GetResult struct { + golangsdk.Result +} + +// Extract from GetResult +func (r GetResult) Extract() (*GetResponse, error) { + var s GetResponse + err := r.Result.ExtractInto(&s) + return &s, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/urls.go new file mode 100644 index 00000000000..b5d8186b703 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows/urls.go @@ -0,0 +1,16 @@ +package maintainwindows + +import ( + "strings" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/instances/maintain-windows +const resourcePath = "instances/maintain-windows" + +// getURL will build the get url of get function +func getURL(client *golangsdk.ServiceClient) string { + // remove projectid from endpoint + return strings.Replace(client.ServiceURL(resourcePath), "/"+client.ProjectID, "", -1) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/requests.go new file mode 100644 index 00000000000..424b9113ae5 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/requests.go @@ -0,0 +1,11 @@ +package products + +import ( + "github.com/huaweicloud/golangsdk" +) + +// Get products +func Get(client *golangsdk.ServiceClient, engine string) (r GetResult) { + _, r.Err = client.Get(getURL(client, engine), &r.Body, nil) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/results.go new file mode 100644 index 00000000000..fa725f73708 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/results.go @@ -0,0 +1,62 @@ +package products + +import ( + "github.com/huaweicloud/golangsdk" +) + +// GetResponse response +type GetResponse struct { + Hourly []Parameter `json:"Hourly"` + Monthly []Parameter `json:"Monthly"` +} + +// Parameter for dms +type Parameter struct { + Name string `json:"name"` + Version string `json:"version"` + Values []Value `json:"values"` +} + +// Value for dms +type Value struct { + Details []Detail `json:"detail"` + Name string `json:"name"` +} + +// Detail for dms +type Detail struct { + Storage string `json:"storage"` + ProductID string `json:"product_id"` + SpecCode string `json:"spec_code"` + VMSpecification string `json:"vm_specification"` + ProductInfos []ProductInfo `json:"product_info"` + PartitionNum string `json:"partition_num"` + Bandwidth string `json:"bandwidth"` + IOs []IO `json:"io"` +} + +// ProductInfo for dms +type ProductInfo struct { + Storage string `json:"storage"` + NodeNum string `json:"node_num"` + ProductID string `json:"product_id"` + SpecCode string `json:"spec_code"` + IOs []IO `json:"io"` +} + +type IO struct { + IOType string `json:"io_type"` + StorageSpecCode string `json:"storage_spec_code"` +} + +// GetResult contains the body of getting detailed +type GetResult struct { + golangsdk.Result +} + +// Extract from GetResult +func (r GetResult) Extract() (*GetResponse, error) { + var s GetResponse + err := r.Result.ExtractInto(&s) + return &s, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/urls.go new file mode 100644 index 00000000000..2d133d84735 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/products/urls.go @@ -0,0 +1,16 @@ +package products + +import ( + "strings" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/products +const resourcePath = "products" + +// getURL will build the get url of get function +func getURL(client *golangsdk.ServiceClient, engine string) string { + // remove projectid from endpoint + return strings.Replace(client.ServiceURL(resourcePath+"?engine="+engine), "/"+client.ProjectID, "", -1) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/requests.go new file mode 100644 index 00000000000..f3fba217c62 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/requests.go @@ -0,0 +1,94 @@ +package queues + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// CreateOpsBuilder is used for creating queue parameters. +// any struct providing the parameters should implement this interface +type CreateOpsBuilder interface { + ToQueueCreateMap() (map[string]interface{}, error) +} + +// CreateOps is a struct that contains all the parameters. +type CreateOps struct { + // Indicates the unique name of a queue. + // A string of 1 to 64 characters that contain + // a-z, A-Z, 0-9, hyphens (-), and underscores (_). + // The name cannot be modified once specified. + Name string `json:"name" required:"true"` + + // Indicates the queue type. Default value: NORMAL. Options: + // NORMAL: Standard queue. Best-effort ordering. + // FIFO: First-ln-First-out (FIFO) queue. FIFO delivery. + // KAFKA_HA: High-availability Kafka queue. + // KAFKA_HT: High-throughput Kafka queue. + // AMQP: Advanced Message Queuing Protocol (AMQP) queue. + QueueMode string `json:"queue_mode,omitempty"` + + // Indicates the basic information about a queue. + // The queue description must be 0 to 160 characters in length, + // and does not contain angle brackets (<) and (>). + Description string `json:"description,omitempty"` + + // This parameter is mandatory only when queue_mode is NORMAL or FIFO. + // Indicates whether to enable dead letter messages. + // Default value: disable. Options: enable, disable. + RedrivePolicy string `json:"redrive_policy,omitempty"` + + // This parameter is mandatory only when + // redrive_policy is set to enable. + // This parameter indicates the maximum number + // of allowed message consumption failures. + // Value range: 1-100. + MaxConsumeCount int `json:"max_consume_count,omitempty"` + + // This parameter is mandatory only when + // queue_mode is set to KAFKA_HA or KAFKA_HT. + // This parameter indicates the retention time + // of messages in Kafka queues. + // Value range: 1 to 72 hours. + RetentionHours int `json:"retention_hours,omitempty"` +} + +// ToQueueCreateMap is used for type convert +func (ops CreateOps) ToQueueCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(ops, "") +} + +// Create a queue with given parameters. +func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) { + b, err := ops.ToQueueCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{201}, + }) + + return +} + +// Delete a queue by id +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} + +// Get a queue with detailed information by id +func Get(client *golangsdk.ServiceClient, id string, includeDeadLetter bool) (r GetResult) { + _, r.Err = client.Get(getURL(client, id, includeDeadLetter), &r.Body, nil) + return +} + +// List all the queues +func List(client *golangsdk.ServiceClient, includeDeadLetter bool) pagination.Pager { + url := listURL(client, includeDeadLetter) + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return QueuePage{pagination.SinglePageBase(r)} + }) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/results.go new file mode 100644 index 00000000000..ae005b997b3 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/results.go @@ -0,0 +1,78 @@ +package queues + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// QueueCreate response +type QueueCreate struct { + ID string `json:"id"` + Name string `json:"name"` + KafkaTopic string `json:"kafka_topic"` +} + +// CreateResult is a struct that contains all the return parameters of creation +type CreateResult struct { + golangsdk.Result +} + +// Extract from CreateResult +func (r CreateResult) Extract() (*QueueCreate, error) { + var s QueueCreate + err := r.Result.ExtractInto(&s) + return &s, err +} + +// DeleteResult is a struct which contains the result of deletion +type DeleteResult struct { + golangsdk.ErrResult +} + +// Queue response +type Queue struct { + ID string `json:"id"` + Name string `json:"name"` + Created float64 `json:"created"` + Description string `json:"description"` + QueueMode string `json:"queue_mode"` + Reservation int `json:"reservation"` + MaxMsgSizeByte int `json:"max_msg_size_byte"` + ProducedMessages int `json:"produced_messages"` + RedrivePolicy string `json:"redrive_policy"` + MaxConsumeCount int `json:"max_consume_count"` + GroupCount int `json:"group_count"` +} + +// GetResult contains the body of getting detailed +type GetResult struct { + golangsdk.Result +} + +// Extract from GetResult +func (r GetResult) Extract() (*Queue, error) { + var s Queue + err := r.Result.ExtractInto(&s) + return &s, err +} + +// QueuePage may be embedded in a Page +// that contains all of the results from an operation at once. +type QueuePage struct { + pagination.SinglePageBase +} + +// IsEmpty returns true if a ListResult contains no queues. +func (r QueuePage) IsEmpty() (bool, error) { + rs, err := ExtractQueues(r) + return len(rs) == 0, err +} + +// ExtractQueues from List +func ExtractQueues(r pagination.Page) ([]Queue, error) { + var s struct { + Queues []Queue `json:"queues"` + } + err := (r.(QueuePage)).ExtractInto(&s) + return s.Queues, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/urls.go new file mode 100644 index 00000000000..83bfdf07b10 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dms/v1/queues/urls.go @@ -0,0 +1,30 @@ +package queues + +import ( + "fmt" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/queues +const resourcePath = "queues" + +// createURL will build the rest query url of creation +func createURL(client *golangsdk.ServiceClient) string { + return client.ServiceURL(resourcePath) +} + +// deleteURL will build the url of deletion +func deleteURL(client *golangsdk.ServiceClient, id string) string { + return client.ServiceURL(resourcePath, id) +} + +// getURL will build the get url of get function +func getURL(client *golangsdk.ServiceClient, id string, includeDeadLetter bool) string { + return client.ServiceURL(resourcePath, fmt.Sprintf("%s?include_deadletter=%t", id, includeDeadLetter)) +} + +// listURL will build the list url of list function +func listURL(client *golangsdk.ServiceClient, includeDeadLetter bool) string { + return client.ServiceURL(fmt.Sprintf("%s?include_deadletter=%t", resourcePath, includeDeadLetter)) +} diff --git a/vendor/vendor.json b/vendor/vendor.json index e7d5e293640..3a9527893a0 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -661,6 +661,42 @@ "revision": "75837c0e32c3577a74950b521e3ad3aaec05b34b", "revisionTime": "2018-09-11T07:04:38Z" }, + { + "checksumSHA1": "bndllnyp7+JlhisoXzhyStpRP+4=", + "path": "github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones", + "revision": "d4446b73ef22ba4b87676d45d4e4a37d191615e9", + "revisionTime": "2018-09-26T10:00:47Z" + }, + { + "checksumSHA1": "xUPgyEWhuzH/NwKM6tQQ8cfIQTg=", + "path": "github.com/huaweicloud/golangsdk/openstack/dms/v1/groups", + "revision": "d4446b73ef22ba4b87676d45d4e4a37d191615e9", + "revisionTime": "2018-09-26T10:00:47Z" + }, + { + "checksumSHA1": "CaMxk3kwCc6qXn2zHcUV0cAkDyE=", + "path": "github.com/huaweicloud/golangsdk/openstack/dms/v1/instances", + "revision": "d4446b73ef22ba4b87676d45d4e4a37d191615e9", + "revisionTime": "2018-09-26T10:00:47Z" + }, + { + "checksumSHA1": "J9APHo3AwtJmO/1+EYFt44s6i78=", + "path": "github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows", + "revision": "d4446b73ef22ba4b87676d45d4e4a37d191615e9", + "revisionTime": "2018-09-26T10:00:47Z" + }, + { + "checksumSHA1": "RqWZKJBu4TqAABYXbTVkE5oWZS8=", + "path": "github.com/huaweicloud/golangsdk/openstack/dms/v1/products", + "revision": "d4446b73ef22ba4b87676d45d4e4a37d191615e9", + "revisionTime": "2018-09-26T10:00:47Z" + }, + { + "checksumSHA1": "O4gYvHhOXXqmUXLwT2SFCDfDEIc=", + "path": "github.com/huaweicloud/golangsdk/openstack/dms/v1/queues", + "revision": "d4446b73ef22ba4b87676d45d4e4a37d191615e9", + "revisionTime": "2018-09-26T10:00:47Z" + }, { "checksumSHA1": "plsG8kyRJhFGnhGfO0scQk5kRLw=", "path": "github.com/huaweicloud/golangsdk/openstack/dns/v2/recordsets", @@ -1102,5 +1138,5 @@ "versionExact": "v1.6.1" } ], - "rootPath": "github.com/freesky-edward/terraform-provider-huaweicloud" + "rootPath": "github.com/terraform-providers/terraform-provider-huaweicloud" } diff --git a/website/docs/d/dms_az_v1.html.markdown b/website/docs/d/dms_az_v1.html.markdown new file mode 100644 index 00000000000..8cd7f714bc2 --- /dev/null +++ b/website/docs/d/dms_az_v1.html.markdown @@ -0,0 +1,40 @@ +--- +layout: "huaweicloud" +page_title: "HuaweiCloud: huaweicloud_dms_az_v1" +sidebar_current: "docs-huaweicloud-datasource-dms-az-v1" +description: |- + Get information on an HuaweiCloud dms az. +--- + +# huaweicloud\_dms\_az_v1 + +Use this data source to get the ID of an available HuaweiCloud dms az. + +## Example Usage + +```hcl + +data "huaweicloud_dms_az_v1" "az1" { + name = "可用区1" + port = "8002" + code = "cn-north-1a" +} +``` + +## Argument Reference + +* `name` - (Required) Indicates the name of an AZ. + +* `code` - (Optional) Indicates the code of an AZ. + +* `port` - (Required) Indicates the port number of an AZ. + + +## Attributes Reference + +`id` is set to the ID of the found az. In addition, the following attributes +are exported: + +* `name` - See Argument Reference above. +* `code` - See Argument Reference above. +* `port` - See Argument Reference above. diff --git a/website/docs/d/dms_maintainwindow_v1.html.markdown b/website/docs/d/dms_maintainwindow_v1.html.markdown new file mode 100644 index 00000000000..b1b6868442d --- /dev/null +++ b/website/docs/d/dms_maintainwindow_v1.html.markdown @@ -0,0 +1,40 @@ +--- +layout: "huaweicloud" +page_title: "HuaweiCloud: huaweicloud_dms_maintainwindow_v1" +sidebar_current: "docs-huaweicloud-datasource-dms-maintainwindow-v1" +description: |- + Get information on an HuaweiCloud dms maintainwindow. +--- + +# huaweicloud\_dms\_maintainwindow_v1 + +Use this data source to get the ID of an available HuaweiCloud dms maintainwindow. + +## Example Usage + +```hcl + +data "huaweicloud_dms_maintainwindow_v1" "maintainwindow1" { +seq = 1 +} + +``` + +## Argument Reference + +* `seq` - (Required) Indicates the sequential number of a maintenance time window. + +* `begin` - (Optional) Indicates the time at which a maintenance time window starts. + +* `end` - (Required) Indicates the time at which a maintenance time window ends. + +* `default` - (Required) Indicates whether a maintenance time window is set to the default time segment. + +## Attributes Reference + +`id` is set to the ID of the found maintainwindow. In addition, the following attributes +are exported: + +* `begin` - See Argument Reference above. +* `end` - See Argument Reference above. +* `default` - See Argument Reference above. diff --git a/website/docs/d/dms_product_v1.html.markdown b/website/docs/d/dms_product_v1.html.markdown new file mode 100644 index 00000000000..3a45c3ba06d --- /dev/null +++ b/website/docs/d/dms_product_v1.html.markdown @@ -0,0 +1,63 @@ +--- +layout: "huaweicloud" +page_title: "HuaweiCloud: huaweicloud_dms_product_v1" +sidebar_current: "docs-huaweicloud-datasource-dms-product-v1" +description: |- + Get information on an HuaweiCloud dms product. +--- + +# huaweicloud\_dms\_product_v1 + +Use this data source to get the ID of an available HuaweiCloud dms product. + +## Example Usage + +```hcl + +data "huaweicloud_dms_product_v1" "product1" { + engine = "kafka" + version = "1.1.0" + instance_type = "cluster" + partition_num = 300 + storage = 600 + storage_spec_code = "dms.physical.storage.high" +} +``` + +## Argument Reference + +* `engine` - (Required) Indicates the name of a message engine. + +* `version` - (Optional) Indicates the version of a message engine. + +* `instance_type` - (Required) Indicates an instance type. Options: "single" and "cluster" + +* `vm_specification` - (Optional) Indicates VM specifications. + +* `storage` - (Optional) Indicates the message storage space. + +* `bandwidth` - (Optional) Indicates the baseline bandwidth of a Kafka instance. + +* `partition_num` - (Optional) Indicates the maximum number of topics that can be created for a Kafka instance. + +* `storage_spec_code` - (Optional) Indicates an I/O specification. + +* `io_type` - (Optional) Indicates an I/O type. + +* `node_num` - (Optional) Indicates the number of nodes in a cluster. + + +## Attributes Reference + +`id` is set to the ID of the found product. In addition, the following attributes +are exported: + +* `engine` - See Argument Reference above. +* `version` - See Argument Reference above. +* `instance_type` - See Argument Reference above. +* `vm_specification` - See Argument Reference above. +* `bandwidth` - See Argument Reference above. +* `partition_num` - See Argument Reference above. +* `storage_spec_code` - See Argument Reference above. +* `io_type` - See Argument Reference above. +* `node_num` - See Argument Reference above. diff --git a/website/docs/r/dms_group_v1.html.markdown b/website/docs/r/dms_group_v1.html.markdown new file mode 100644 index 00000000000..2b5bd6e1191 --- /dev/null +++ b/website/docs/r/dms_group_v1.html.markdown @@ -0,0 +1,55 @@ +--- +layout: "huaweicloud" +page_title: "huaweicloud: huaweicloud_dms_group_v1" +sidebar_current: "docs-huaweicloud-resource-dms-group-v1" +description: |- + Manages a DMS group in the huaweicloud DMS Service +--- + +# huaweicloud\_dms\_group_v1 + +Manages a DMS group in the huaweicloud DMS Service. + +## Example Usage + +### Automatically detect the correct network + +```hcl +resource "huaweicloud_dms_group_v1" "queue_1" { + name = "queue_1" + description = "test create dms queue" + queue_mode = "FIFO" + redrive_policy = "enable" + max_consume_count = 80 +} + +resource "huaweicloud_dms_group_v1" "group_1" { + name = "group_1" + queue_id = "${huaweicloud_dms_queue_v1.queue_1.id}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Indicates the unique name of a group. A string of 1 to 64 + characters that contain a-z, A-Z, 0-9, hyphens (-), and underscores (_). + The name cannot be modified once specified. + +* `queue_id` - (Required) Indicates the ID of a specified queue. + + +## Attributes Reference + +The following attributes are exported: + + +* `name` - See Argument Reference above. +* `queue_id` - Indicates the ID of a queue. +* `redrive_policy` - Indicates whether to enable dead letter messages. +* `produced_messages` - Indicates the total number of messages (not including the messages that have expired and been deleted) in a queue. +* `consumed_messages` - Indicates the total number of messages that are successfully consumed. +* `available_messages` - Indicates the accumulated number of messages that can be consumed. +* `produced_deadletters` - Indicates the total number of dead letter messages generated by the consumer group. +* `available_deadletters` - Indicates the accumulated number of dead letter messages that have not been consumed. diff --git a/website/docs/r/dms_instance_v1.html.markdown b/website/docs/r/dms_instance_v1.html.markdown new file mode 100644 index 00000000000..5e523bf0139 --- /dev/null +++ b/website/docs/r/dms_instance_v1.html.markdown @@ -0,0 +1,174 @@ +--- +layout: "huaweicloud" +page_title: "huaweicloud: huaweicloud_dms_instance_v1" +sidebar_current: "docs-huaweicloud-resource-dms-instance-v1" +description: |- + Manages a DMS instance in the huaweicloud DMS Service +--- + +# huaweicloud\_dms\_instance_v1 + +Manages a DMS instance in the huaweicloud DMS Service. + +## Example Usage + +### Automatically detect the correct network + +```hcl +resource "huaweicloud_networking_secgroup_v2" "secgroup_1" { + name = "secgroup_1" + description = "secgroup_1" +} +data "huaweicloud_dms_az_v1" "az_1" { +} +data "huaweicloud_dms_product_v1" "product_1" { + engine = "rabbitmq" + instance_type = "single" + version = "3.7.0" +} +resource "huaweicloud_dms_instance_v1" "instance_1" { + name = "%s" + engine = "rabbitmq" + storage_space = "${data.huaweicloud_dms_product_v1.product_1.storage}" + access_user = "user" + password = "Dmstest@123" + vpc_id = "%s" + security_group_id = "${huaweicloud_networking_secgroup_v2.secgroup_1.id}" + subnet_id = "%s" + available_zones = ["${data.huaweicloud_dms_az_v1.az_1.id}"] + product_id = "${data.huaweicloud_dms_product_v1.product_1.id}" + engine_version = "${data.huaweicloud_dms_product_v1.product_1.version}" + depends_on = ["data.huaweicloud_dms_product_v1.product_1", "huaweicloud_networking_secgroup_v2.secgroup_1"] +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Indicates the name of an instance. An instance name starts with a letter, + consists of 4 to 64 characters, and supports only letters, digits, and hyphens (-). + +* `description` - (Optional) Indicates the description of an instance. It is a character + string containing not more than 1024 characters. + +* `engine` - (Optional) Indicates a message engine. Options: rabbitmq and kafka. + +* `engine_version` - (Optional) Indicates the version of a message engine. + +* `specification` - (Optional) This parameter is mandatory if the engine is kafka. + Indicates the baseline bandwidth of a Kafka instance, that is, the maximum amount + of data transferred per unit time. Unit: byte/s. Options: 300 MB, 600 MB, 1200 MB. + +* `storage_space` - (Required) Indicates the message storage space. + Value range: + Single-node RabbitMQ instance: 100–90000 GB + Cluster RabbitMQ instance: 100 GB x Number of nodes to 90000 GB, 200 GB x Number of + nodes to 90000 GB, 300 GB x Number of nodes to 90000 GB + Kafka instance with specification being 300 MB: 1200–90000 GB + Kafka instance with specification being 600 MB: 2400–90000 GB + Kafka instance with specification being 1200 MB: 4800–90000 GB + +* `partition_num` - (Optional) This parameter is mandatory when a Kafka instance is created. + Indicates the maximum number of topics in a Kafka instance. + When specification is 300 MB: 900 + When specification is 600 MB: 1800 + When specification is 1200 MB: 1800 + +* `access_user` - (Optional) Indicates a username. If the engine is rabbitmq, this + parameter is mandatory. If the engine is kafka, this parameter is optional. + A username consists of 4 to 64 characters and supports only letters, digits, and + hyphens (-). + +* `password` - (Optional) If the engine is rabbitmq, this parameter is mandatory. + If the engine is kafka, this parameter is mandatory when ssl_enable is true and is + invalid when ssl_enable is false. Indicates the password of an instance. An instance + password must meet the following complexity requirements: Must be 8 to 32 characters long. + Must contain at least 2 of the following character types: lowercase letters, uppercase + letters, digits, and special characters (`~!@#$%^&*()-_=+\|[{}]:'",<.>/?). + +* `vpc_id` - (Required) Indicates the ID of a VPC. + +* `security_group_id` - (Required) Indicates the ID of a security group. + +* `subnet_id` - (Required) Indicates the ID of a subnet. + +* `available_zones` - (Required) Indicates the ID of an AZ. The parameter value can not be + left blank or an empty array. For details, see section Querying AZ Information. + +* `product_id` - (Required) Indicates a product ID. + +* `maintain_begin` - (Optional) Indicates the time at which a maintenance time window starts. + Format: HH:mm:ss. + The start time and end time of a maintenance time window must indicate the time segment of + a supported maintenance time window. For details, see section Querying Maintenance Time Windows. + The start time must be set to 22:00, 02:00, 06:00, 10:00, 14:00, or 18:00. + Parameters maintain_begin and maintain_end must be set in pairs. If parameter maintain_begin + is left blank, parameter maintain_end is also blank. In this case, the system automatically + allocates the default start time 02:00. + +* `maintain_end` - (Optional) Indicates the time at which a maintenance time window ends. + Format: HH:mm:ss. + The start time and end time of a maintenance time window must indicate the time segment of + a supported maintenance time window. For details, see section Querying Maintenance Time Windows. + The end time is four hours later than the start time. For example, if the start time is 22:00, + the end time is 02:00. + Parameters maintain_begin and maintain_end must be set in pairs. If parameter maintain_end is left + blank, parameter maintain_begin is also blank. In this case, the system automatically allocates + the default end time 06:00. + +* `enable_publicip` - (Optional) Indicates whether to enable public access to a RabbitMQ instance. + true: enable, false: disable + +* `publicip_id` - (Optional) Indicates the ID of the elastic IP address (EIP) bound to a RabbitMQ instance. + This parameter is mandatory if public access is enabled (that is, enable_publicip is set to true). + +* `storage_spec_code` - (Optional) Indicates the storage I/O specification. For details on how to + select a disk type, see Disk Types and Disk Performance. Options for a RabbitMQ instance: + dms.physical.storage.normal + dms.physical.storage.high + dms.physical.storage.ultra + Options for a Kafka instance: + When specification is 300 MB: dms.physical.storage.high or dms.physical.storage.ultra + When specification is 600 MB: dms.physical.storage.ultra + When specification is 1200 MB: dms.physical.storage.ultra + + +## Attributes Reference + +The following attributes are exported: + + +* `name` - See Argument Reference above. +* `description` - See Argument Reference above. +* `engine` - See Argument Reference above. +* `engine_version` - See Argument Reference above. +* `specification` - See Argument Reference above. +* `storage_space` - Indicates the time when a instance is created. +* `partition_num` - See Argument Reference above. +* `access_user` - See Argument Reference above. +* `password` - See Argument Reference above. +* `vpc_id` - See Argument Reference above. +* `security_group_id` - See Argument Reference above. +* `security_group_name` - Indicates the name of a security group. +* `subnet_id` - See Argument Reference above. +* `subnet_name` - Indicates the name of a subnet. +* `subnet_cidr` - Indicates a subnet segment. +* `available_zones` - See Argument Reference above. +* `product_id` - See Argument Reference above. +* `maintain_begin` - See Argument Reference above. +* `maintain_end` - See Argument Reference above. +* `enable_publicip` - See Argument Reference above. +* `publicip_id` - See Argument Reference above. +* `storage_spec_code` - See Argument Reference above. +* `used_storage_space` - Indicates the used message storage space. Unit: GB +* `connect_address` - Indicates the IP address of an instance. +* `port` - Indicates the port number of an instance. +* `status` - Indicates the status of an instance. For details, see section Instance Status. +* `instance_id` - Indicates the ID of an instance. +* `resource_spec_code` - Indicates a resource specifications identifier. +* `type` - Indicates an instance type. Options: "single" and "cluster" +* `created_at` - Indicates the time when an instance is created. The time is in the format + of timestamp, that is, the offset milliseconds from 1970-01-01 00:00:00 UTC to the specified time. +* `user_id` - Indicates a user ID. +* `user_name` - Indicates a username. diff --git a/website/docs/r/dms_queue_v1.html.markdown b/website/docs/r/dms_queue_v1.html.markdown new file mode 100644 index 00000000000..ebc30f2275b --- /dev/null +++ b/website/docs/r/dms_queue_v1.html.markdown @@ -0,0 +1,71 @@ +--- +layout: "huaweicloud" +page_title: "huaweicloud: huaweicloud_dms_queue_v1" +sidebar_current: "docs-huaweicloud-resource-dms-queue-v1" +description: |- + Manages a DMS queue in the huaweicloud DMS Service +--- + +# huaweicloud\_dms\_queue_v1 + +Manages a DMS queue in the huaweicloud DMS Service. + +## Example Usage + +### Automatically detect the correct network + +```hcl +resource "huaweicloud_dms_queue_v1" "queue_1" { + name = "queue_1" + description = "test create dms queue" + queue_mode = "FIFO" + redrive_policy = "enable" + max_consume_count = 80 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Indicates the unique name of a queue. A string of 1 to 64 + characters that contain a-z, A-Z, 0-9, hyphens (-), and underscores (_). + The name cannot be modified once specified. + +* `queue_mode` - (Optional) Indicates the queue type. It only support 'NORMAL' and 'FIFO'. + NORMAL: Standard queue. Best-effort ordering. Messages might be retrieved in an order + different from which they were sent. Select standard queues when throughput is important. + FIFO: First-ln-First-out (FIFO) queue. FIFO delivery. Messages are retrieved in the + order they were sent. Select FIFO queues when the order of messages is important. + Default value: NORMAL. + +* `description` - (Optional) Indicates the basic information about a queue. The queue + description must be 0 to 160 characters in length, and does not contain angle + brackets (<) and (>). + +* `redrive_policy` - (Optional) Indicates whether to enable dead letter messages. + Dead letter messages indicate messages that cannot be normally consumed. + The redrive_policy should be set to 'enable' or 'disable'. The default value is 'disable'. + +* `max_consume_count` - (Optional) This parameter is mandatory only when redrive_policy is + set to enable. This parameter indicates the maximum number of allowed message consumption + failures. When a message fails to be consumed after the number of consumption attempts of + this message reaches this value, DMS stores this message into the dead letter queue. + The max_consume_count value range is 1–100. + + +## Attributes Reference + +The following attributes are exported: + + +* `name` - See Argument Reference above. +* `queue_mode` - See Argument Reference above. +* `description` - See Argument Reference above. +* `redrive_policy` - See Argument Reference above. +* `max_consume_count` - See Argument Reference above. +* `created` - Indicates the time when a queue is created. +* `reservation` - Indicates the retention period (unit: min) of a message in a queue. +* `max_msg_size_byte` - Indicates the maximum message size (unit: byte) that is allowed in queue. +* `produced_messages` - Indicates the total number of messages (not including the messages that have expired and been deleted) in a queue. +* `group_count` - Indicates the total number of consumer groups in a queue.