|
| 1 | +// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! |
| 2 | +package alicloud |
| 3 | + |
| 4 | +import ( |
| 5 | + "fmt" |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" |
| 11 | +) |
| 12 | + |
| 13 | +func TestAccAlicloudAmqpOpenSourceAccountDataSource(t *testing.T) { |
| 14 | + testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"}) |
| 15 | + rand := acctest.RandIntRange(1000000, 9999999) |
| 16 | + |
| 17 | + idsConf := dataSourceTestAccConfig{ |
| 18 | + existConfig: testAccCheckAlicloudAmqpOpenSourceAccountSourceConfig(rand, map[string]string{ |
| 19 | + "ids": `["${alicloud_amqp_open_source_account.default.id}"]`, |
| 20 | + "instance_id": `"${alicloud_amqp_instance.CreateInstance.id}"`, |
| 21 | + }), |
| 22 | + fakeConfig: testAccCheckAlicloudAmqpOpenSourceAccountSourceConfig(rand, map[string]string{ |
| 23 | + "ids": `["${alicloud_amqp_open_source_account.default.id}_fake"]`, |
| 24 | + "instance_id": `"${alicloud_amqp_instance.CreateInstance.id}"`, |
| 25 | + }), |
| 26 | + } |
| 27 | + |
| 28 | + outputFileConf := dataSourceTestAccConfig{ |
| 29 | + existConfig: testAccCheckAlicloudAmqpOpenSourceAccountSourceConfig(rand, map[string]string{ |
| 30 | + "ids": `["${alicloud_amqp_open_source_account.default.id}"]`, |
| 31 | + "instance_id": `"${alicloud_amqp_instance.CreateInstance.id}"`, |
| 32 | + "output_file": `"./tf-testacc-amqp-open-source-accounts.txt"`, |
| 33 | + }), |
| 34 | + fakeConfig: testAccCheckAlicloudAmqpOpenSourceAccountSourceConfig(rand, map[string]string{ |
| 35 | + "ids": `["${alicloud_amqp_open_source_account.default.id}_fake"]`, |
| 36 | + "instance_id": `"${alicloud_amqp_instance.CreateInstance.id}"`, |
| 37 | + "output_file": `"./tf-testacc-amqp-open-source-accounts-fake.txt"`, |
| 38 | + }), |
| 39 | + } |
| 40 | + |
| 41 | + AmqpOpenSourceAccountCheckInfo.dataSourceTestCheck(t, rand, idsConf, outputFileConf) |
| 42 | +} |
| 43 | + |
| 44 | +var existAmqpOpenSourceAccountMapFunc = func(rand int) map[string]string { |
| 45 | + return map[string]string{ |
| 46 | + "accounts.#": "1", |
| 47 | + "accounts.0.user_name": CHECKSET, |
| 48 | + "accounts.0.description": CHECKSET, |
| 49 | + "accounts.0.instance_id": CHECKSET, |
| 50 | + "accounts.0.password": CHECKSET, |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +var fakeAmqpOpenSourceAccountMapFunc = func(rand int) map[string]string { |
| 55 | + return map[string]string{ |
| 56 | + "accounts.#": "0", |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +var AmqpOpenSourceAccountCheckInfo = dataSourceAttr{ |
| 61 | + resourceId: "data.alicloud_amqp_open_source_accounts.default", |
| 62 | + existMapFunc: existAmqpOpenSourceAccountMapFunc, |
| 63 | + fakeMapFunc: fakeAmqpOpenSourceAccountMapFunc, |
| 64 | +} |
| 65 | + |
| 66 | +func testAccCheckAlicloudAmqpOpenSourceAccountSourceConfig(rand int, attrMap map[string]string) string { |
| 67 | + var pairs []string |
| 68 | + for k, v := range attrMap { |
| 69 | + pairs = append(pairs, k+" = "+v) |
| 70 | + } |
| 71 | + config := fmt.Sprintf(` |
| 72 | +variable "name" { |
| 73 | + default = "tf-testAccAmqpOpenSourceAccount%d" |
| 74 | +} |
| 75 | +variable "instance_name" { |
| 76 | + default = "测试开源鉴权实例" |
| 77 | +} |
| 78 | +
|
| 79 | +variable "user_name" { |
| 80 | + default = "Suhao123_" |
| 81 | +} |
| 82 | +
|
| 83 | +variable "user_name_update" { |
| 84 | + default = "Suhao456_" |
| 85 | +} |
| 86 | +
|
| 87 | +resource "alicloud_amqp_instance" "CreateInstance" { |
| 88 | + renewal_duration = "1" |
| 89 | + max_tps = "3000" |
| 90 | + period_cycle = "Month" |
| 91 | + max_connections = "2000" |
| 92 | + support_eip = true |
| 93 | + auto_renew = false |
| 94 | + renewal_status = "AutoRenewal" |
| 95 | + period = "12" |
| 96 | + instance_name = var.instance_name |
| 97 | + support_tracing = false |
| 98 | + payment_type = "Subscription" |
| 99 | + renewal_duration_unit = "Month" |
| 100 | + instance_type = "enterprise" |
| 101 | + queue_capacity = "200" |
| 102 | + max_eip_tps = "128" |
| 103 | + vpc_id = alicloud_vpc.default.id |
| 104 | + vswitch_ids = [alicloud_vswitch.default_b.id, alicloud_vswitch.default_g.id] |
| 105 | + security_group_id = alicloud_security_group.default.id |
| 106 | +} |
| 107 | +
|
| 108 | +resource "alicloud_vpc" "default" { |
| 109 | + vpc_name = var.name |
| 110 | + cidr_block = "172.16.0.0/16" |
| 111 | +} |
| 112 | +
|
| 113 | +resource "alicloud_vswitch" "default_b" { |
| 114 | + vswitch_name = "${var.name}-b" |
| 115 | + cidr_block = "172.16.0.0/24" |
| 116 | + vpc_id = alicloud_vpc.default.id |
| 117 | + zone_id = "cn-hangzhou-b" |
| 118 | +} |
| 119 | +
|
| 120 | +resource "alicloud_vswitch" "default_g" { |
| 121 | + vswitch_name = "${var.name}-g" |
| 122 | + cidr_block = "172.16.1.0/24" |
| 123 | + vpc_id = alicloud_vpc.default.id |
| 124 | + zone_id = "cn-hangzhou-g" |
| 125 | +} |
| 126 | +
|
| 127 | +resource "alicloud_security_group" "default" { |
| 128 | + security_group_name = var.name |
| 129 | + vpc_id = alicloud_vpc.default.id |
| 130 | +} |
| 131 | +
|
| 132 | +
|
| 133 | +resource "alicloud_amqp_open_source_account" "default" { |
| 134 | + user_name = var.user_name |
| 135 | + description = var.user_name |
| 136 | + password = var.user_name |
| 137 | + instance_id = alicloud_amqp_instance.CreateInstance.id |
| 138 | +} |
| 139 | +
|
| 140 | +data "alicloud_amqp_open_source_accounts" "default" { |
| 141 | +%s |
| 142 | +} |
| 143 | +`, rand, strings.Join(pairs, "\n ")) |
| 144 | + return config |
| 145 | +} |
0 commit comments