Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DLI): Synchronized a DLI resource. #1102

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions docs/resources/dli_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,53 @@ resource "flexibleengine_dli_queue" "queue" {

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the dli queue resource. If omitted,
the provider-level region will be used. Changing this will create a new VPC channel resource.

* `cu_count` - (Required, Int) Minimum number of CUs that are bound to a queue. Initial value can be `16`,
`64`, or `256`. When scale_out or scale_in, the number must be a multiple of 16
`64`, or `256`. When scale_out or scale_in, the number must be a multiple of 16.

* `name` - (Required, String, ForceNew) Name of a queue. Name of a newly created resource queue.
The name can contain only digits, letters, and underscores (\_),
but cannot contain only digits or start with an underscore (_).
Length range: 1 to 128 characters. Changing this parameter will create a new resource.
The name can contain only digits, letters, and underscores (\_),
but cannot contain only digits or start with an underscore (_).
Length range: 1 to 128 characters. Changing this parameter will create a new resource.

* `description` - (Optional, String, ForceNew) Description of a queue.
Changing this parameter will create a new resource.
Changing this parameter will create a new resource.

* `queue_type` - (Optional, String, ForceNew) Indicates the queue type.
Changing this parameter will create a new resource. The options are as follows:
- sql,
- general
Changing this parameter will create a new resource. The options are as follows:
- **sql**. SQL queue type, used to run SQL jobs.
- **general**. Universal queue type for running Flink, Spark Jar jobs.

The default value is `sql`.

* `resource_mode` - (Optional, String, ForceNew) Queue resource mode.
Changing this parameter will create a new resource.
The options are as follows:
- 0: indicates the shared resource mode.
- 1: indicates the exclusive resource mode.
- **0**: indicates the shared resource mode.
- **1**: indicates the exclusive resource mode.

* `feature` - (Optional, String, ForceNew)Indicates the queue feature. Changing this parameter will create a new
resource. The options are as follows:
- **basic**: basic type (default value)

* `platform` - (Optional, String, ForceNew) CPU architecture of queue compute resources. Changing this parameter will
create a new resource. The options are as follows:
- **x86_64** : default value.
- **aarch64**.

* `vpc_cidr` - (Optional, String) The CIDR block of a queue. If use DLI enhanced datasource connections, the CIDR block
cannot be the same as that of the data source.
The CIDR blocks supported by different CU specifications:

- When `cu_count` is `16` or `64`: 10.0.0.0~10.255.0.0/8~24, 172.16.0.0~172.31.0.0/12~24,
192.168.0.0~192.168.0.0/16~24.
- When `cu_count` is `256`: 10.0.0.0~10.255.0.0/8~22, 172.16.0.0~172.31.0.0/12~22, 192.168.0.0~192.168.0.0/16~22.

* `tags` - (Optional, Map, ForceNew) Label of a queue. Changing this parameter will create a new resource.

## Attributes Reference
## Attribute Reference

In addition to all arguments above, the following attributes are exported:

Expand All @@ -66,12 +86,12 @@ In addition to all arguments above, the following attributes are exported:

This resource provides the following timeouts configuration options:

* `update` - Default is 45 minute.
* `update` - Default is 45 minutes.

## Import

DLI queue can be imported by `id`. For example,

```shell
terraform import flexibleengine_dli_queue.example abc123
terraform import flexibleengine_dli_queue.example abc123
```
209 changes: 209 additions & 0 deletions flexibleengine/acceptance/resource_flexibleengine_dli_queue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/chnsz/golangsdk/openstack/dli/v1/queues"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

const (
CU16 = 16
QueueTypeGeneral = "general"
QueueTypeSQL = "sql"
)

func getDliQueueResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := cfg.DliV1Client(OS_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating Dli v1 client, err=%s", err)
}

result := queues.Get(client, state.Primary.Attributes["name"])
return result.Body, result.Err
}

func TestAccDliQueue_basic(t *testing.T) {
rName := acceptance.RandomAccResourceName()
resourceName := "flexibleengine_dli_queue.test"

var obj queues.CreateOpts
rc := acceptance.InitResourceCheck(
resourceName,
&obj,
getDliQueueResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccDliQueue_basic(rName, CU16),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "queue_type", QueueTypeSQL),
resource.TestCheckResourceAttr(resourceName, "cu_count", fmt.Sprintf("%d", CU16)),
resource.TestCheckResourceAttrSet(resourceName, "resource_mode"),
resource.TestCheckResourceAttrSet(resourceName, "create_time"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccQueueImportStateFunc(resourceName),
ImportStateVerifyIgnore: []string{
"tags",
},
},
},
})
}

func testAccQueueImportStateFunc(rName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[rName]
if !ok {
return "", fmt.Errorf("resource (%s) not found: %s", rName, rs)
}
name := rs.Primary.Attributes["name"]
if name == "" {
return "", fmt.Errorf("the queue name is incorrect, got '%s'", name)
}
return name, nil
}
}

func TestAccDliQueue_withGeneral(t *testing.T) {
rName := acceptance.RandomAccResourceName()
resourceName := "flexibleengine_dli_queue.test"

var obj queues.CreateOpts
rc := acceptance.InitResourceCheck(
resourceName,
&obj,
getDliQueueResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccDliQueue_withGeneral(rName, CU16),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "queue_type", QueueTypeGeneral),
resource.TestCheckResourceAttr(resourceName, "cu_count", fmt.Sprintf("%d", CU16)),
resource.TestCheckResourceAttrSet(resourceName, "resource_mode"),
resource.TestCheckResourceAttrSet(resourceName, "create_time"),
),
},
},
})
}

func testAccDliQueue_basic(rName string, cuCount int) string {
return fmt.Sprintf(`
resource "flexibleengine_dli_queue" "test" {
name = "%s"
cu_count = %d

tags = {
foo = "bar"
}
}
`, rName, cuCount)
}

func testAccDliQueue_withGeneral(rName string, cuCount int) string {
return fmt.Sprintf(`
resource "flexibleengine_dli_queue" "test" {
name = "%s"
cu_count = %d
queue_type = "general"

tags = {
foo = "bar"
}
}
`, rName, cuCount)
}

func TestAccDliQueue_cidr(t *testing.T) {
rName := acceptance.RandomAccResourceName()
resourceName := "flexibleengine_dli_queue.test"

var obj queues.CreateOpts
rc := acceptance.InitResourceCheck(
resourceName,
&obj,
getDliQueueResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccDliQueue_cidr(rName, "172.16.0.0/21"),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "queue_type", QueueTypeSQL),
resource.TestCheckResourceAttr(resourceName, "cu_count", "16"),
resource.TestCheckResourceAttr(resourceName, "resource_mode", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc_cidr", "172.16.0.0/21"),
resource.TestCheckResourceAttrSet(resourceName, "create_time"),
),
},
{

Config: testAccDliQueue_cidr(rName, "172.16.0.0/18"),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "queue_type", QueueTypeSQL),
resource.TestCheckResourceAttr(resourceName, "cu_count", "16"),
resource.TestCheckResourceAttr(resourceName, "resource_mode", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc_cidr", "172.16.0.0/18"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccQueueImportStateFunc(resourceName),
ImportStateVerifyIgnore: []string{
"tags",
},
},
},
})
}

func testAccDliQueue_cidr(rName string, cidr string) string {
return fmt.Sprintf(`
resource "flexibleengine_dli_queue" "test" {
name = "%s"
cu_count = 16
resource_mode = 1
vpc_cidr = "%s"

tags = {
foo = "bar"
}
}`, rName, cidr)
}
3 changes: 1 addition & 2 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,6 @@ func Provider() *schema.Provider {
"flexibleengine_waf_rule_precise_protection": resourceWafRulePreciseProtection(),
"flexibleengine_waf_rule_web_tamper_protection": resourceWafRuleWebTamperProtection(),

"flexibleengine_dli_queue": ResourceDliQueueV1(),

// importing new resource
"flexibleengine_aom_service_discovery_rule": aom.ResourceServiceDiscoveryRule(),

Expand Down Expand Up @@ -610,6 +608,7 @@ func Provider() *schema.Provider {
"flexibleengine_dli_flinksql_job": dli.ResourceFlinkSqlJob(),
"flexibleengine_dli_global_variable": dli.ResourceGlobalVariable(),
"flexibleengine_dli_package": dli.ResourceDliPackageV2(),
"flexibleengine_dli_queue": dli.ResourceDliQueue(),
"flexibleengine_dli_spark_job": dli.ResourceDliSparkJobV2(),
"flexibleengine_dli_sql_job": dli.ResourceSqlJob(),
"flexibleengine_dli_table": dli.ResourceDliTable(),
Expand Down
Loading