|
| 1 | +package servicestage |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "regexp" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 10 | + |
| 11 | + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" |
| 12 | + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" |
| 13 | + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/servicestage" |
| 14 | +) |
| 15 | + |
| 16 | +func getV3Configuration(conf *config.Config, state *terraform.ResourceState) (interface{}, error) { |
| 17 | + client, err := conf.NewServiceClient("servicestage", acceptance.HW_REGION_NAME) |
| 18 | + if err != nil { |
| 19 | + return nil, fmt.Errorf("error creating ServiceStage client: %s", err) |
| 20 | + } |
| 21 | + return servicestage.GetV3ConfigurationFile(client, state.Primary.ID) |
| 22 | +} |
| 23 | + |
| 24 | +func TestAccV3Configuration_basic(t *testing.T) { |
| 25 | + var ( |
| 26 | + configuration interface{} |
| 27 | + resourceName = "huaweicloud_servicestagev3_configuration.test" |
| 28 | + rc = acceptance.InitResourceCheck(resourceName, &configuration, getV3Configuration) |
| 29 | + |
| 30 | + name = acceptance.RandomAccResourceName() |
| 31 | + ) |
| 32 | + |
| 33 | + resource.ParallelTest(t, resource.TestCase{ |
| 34 | + PreCheck: func() { acceptance.TestAccPreCheck(t) }, |
| 35 | + ProviderFactories: acceptance.TestAccProviderFactories, |
| 36 | + CheckDestroy: rc.CheckResourceDestroy(), |
| 37 | + Steps: []resource.TestStep{ |
| 38 | + { |
| 39 | + Config: testAccV3Configuration_basic_step1(name), |
| 40 | + Check: resource.ComposeTestCheckFunc( |
| 41 | + rc.CheckResourceExists(), |
| 42 | + resource.TestCheckResourceAttrPair(resourceName, "config_group_id", "huaweicloud_servicestagev3_configuration_group.test", "id"), |
| 43 | + resource.TestCheckResourceAttr(resourceName, "name", name), |
| 44 | + resource.TestCheckResourceAttr(resourceName, "type", "properties"), |
| 45 | + resource.TestCheckResourceAttr(resourceName, "content", "testkey = testvalue"), |
| 46 | + resource.TestCheckResourceAttr(resourceName, "sensitive", "true"), |
| 47 | + resource.TestCheckResourceAttr(resourceName, "description", "Created by TF script"), |
| 48 | + resource.TestCheckResourceAttr(resourceName, "components.#", "0"), |
| 49 | + resource.TestCheckResourceAttrSet(resourceName, "version"), |
| 50 | + resource.TestCheckResourceAttrSet(resourceName, "creator"), |
| 51 | + resource.TestMatchResourceAttr(resourceName, "created_at", |
| 52 | + regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), |
| 53 | + resource.TestMatchResourceAttr(resourceName, "created_at", |
| 54 | + regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), |
| 55 | + ), |
| 56 | + }, |
| 57 | + { |
| 58 | + Config: testAccV3Configuration_basic_step2(name), |
| 59 | + Check: resource.ComposeTestCheckFunc( |
| 60 | + rc.CheckResourceExists(), |
| 61 | + resource.TestCheckResourceAttr(resourceName, "type", "yaml"), |
| 62 | + resource.TestCheckResourceAttr(resourceName, "sensitive", "false"), |
| 63 | + resource.TestCheckResourceAttr(resourceName, "description", ""), |
| 64 | + ), |
| 65 | + }, |
| 66 | + { |
| 67 | + ResourceName: resourceName, |
| 68 | + ImportState: true, |
| 69 | + ImportStateVerify: true, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }) |
| 73 | +} |
| 74 | + |
| 75 | +func testAccV3Configuration_basic_step1(name string) string { |
| 76 | + return fmt.Sprintf(` |
| 77 | +%[1]s |
| 78 | +
|
| 79 | +resource "huaweicloud_servicestagev3_configuration" "test" { |
| 80 | + config_group_id = huaweicloud_servicestagev3_configuration_group.test.id |
| 81 | + name = "%[2]s" |
| 82 | + type = "properties" |
| 83 | + content = "testkey = testvalue" |
| 84 | + sensitive = true |
| 85 | + description = "Created by TF script" |
| 86 | +} |
| 87 | +`, testAccV3ConfigurationGroup_basic(name), name) |
| 88 | +} |
| 89 | + |
| 90 | +func testAccV3Configuration_basic_step2(name string) string { |
| 91 | + return fmt.Sprintf(` |
| 92 | +%[1]s |
| 93 | +
|
| 94 | +resource "huaweicloud_servicestagev3_configuration" "test" { |
| 95 | + config_group_id = huaweicloud_servicestagev3_configuration_group.test.id |
| 96 | + name = "%[2]s" |
| 97 | + type = "yaml" |
| 98 | + content = <<EOF |
| 99 | +spring: |
| 100 | + application: |
| 101 | + name: "service" |
| 102 | + cloud: |
| 103 | + servicecomb: |
| 104 | + service: |
| 105 | + name: service |
| 106 | + version: $${CAS_INSTANCE_VERSION} |
| 107 | + application: $${CAS_APPLICATION_NAME} |
| 108 | + discovery: |
| 109 | + address: $${PAAS_CSE_SC_ENDPOINT} |
| 110 | + healthCheckInterval: 10 |
| 111 | + pollInterval: 15000 |
| 112 | + waitTimeForShutDownInMillis: 15000 |
| 113 | + config: |
| 114 | + serverAddr: $${PAAS_CSE_CC_ENDPOINT} |
| 115 | + serverType: kie |
| 116 | + fileSource: governance.yaml,application.yaml |
| 117 | +EOF |
| 118 | +} |
| 119 | +`, testAccV3ConfigurationGroup_basic(name), name) |
| 120 | +} |
0 commit comments