|
| 1 | +package provider |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 9 | +) |
| 10 | + |
| 11 | +func TestAccIntegrationResource(t *testing.T) { |
| 12 | + envId := os.Getenv("AUTOMQ_TEST_ENV_ID") |
| 13 | + if envId == "" { |
| 14 | + t.Skip("AUTOMQ_TEST_ENV_ID must be set for this test") |
| 15 | + } |
| 16 | + deployProfile := os.Getenv("AUTOMQ_TEST_DEPLOY_PROFILE") |
| 17 | + if deployProfile == "" { |
| 18 | + t.Skip("AUTOMQ_TEST_DEPLOY_PROFILE must be set for this test") |
| 19 | + } |
| 20 | + endpoint := os.Getenv("AUTOMQ_TEST_BYOC_ENDPOINT") |
| 21 | + if endpoint == "" { |
| 22 | + t.Skip("AUTOMQ_TEST_BYOC_ENDPOINT must be set for this test") |
| 23 | + } |
| 24 | + accessKeyId := os.Getenv("AUTOMQ_TEST_BYOC_ACCESS_KEY_ID") |
| 25 | + if accessKeyId == "" { |
| 26 | + t.Skip("AUTOMQ_TEST_BYOC_ACCESS_KEY_ID must be set for this test") |
| 27 | + } |
| 28 | + secretKey := os.Getenv("AUTOMQ_TEST_BYOC_SECRET_KEY") |
| 29 | + if secretKey == "" { |
| 30 | + t.Skip("AUTOMQ_TEST_BYOC_SECRET_KEY must be set for this test") |
| 31 | + } |
| 32 | + |
| 33 | + if os.Getenv("TF_ACC_TIMEOUT") == "" { |
| 34 | + t.Setenv("TF_ACC_TIMEOUT", "2h") |
| 35 | + } |
| 36 | + |
| 37 | + // Test Prometheus Integration |
| 38 | + resource.Test(t, resource.TestCase{ |
| 39 | + PreCheck: func() { testAccPreCheck(t) }, |
| 40 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 41 | + Steps: []resource.TestStep{ |
| 42 | + // Create and Read testing for Prometheus |
| 43 | + { |
| 44 | + Config: testAccIntegrationPrometheusConfig(envId, deployProfile, endpoint, accessKeyId, secretKey), |
| 45 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 46 | + resource.TestCheckResourceAttrSet("automq_integration.test_prometheus", "id"), |
| 47 | + resource.TestCheckResourceAttr("automq_integration.test_prometheus", "environment_id", envId), |
| 48 | + resource.TestCheckResourceAttr("automq_integration.test_prometheus", "deploy_profile", deployProfile), |
| 49 | + resource.TestCheckResourceAttr("automq_integration.test_prometheus", "type", "prometheusRemoteWrite"), |
| 50 | + resource.TestCheckResourceAttr("automq_integration.test_prometheus", "name", "test-prometheus"), |
| 51 | + resource.TestCheckResourceAttrSet("automq_integration.test_prometheus", "created_at"), |
| 52 | + ), |
| 53 | + }, |
| 54 | + // ImportState testing |
| 55 | + { |
| 56 | + ResourceName: "automq_integration.test_prometheus", |
| 57 | + ImportState: true, |
| 58 | + ImportStateVerify: true, |
| 59 | + }, |
| 60 | + // Update testing |
| 61 | + { |
| 62 | + Config: testAccIntegrationPrometheusConfigUpdate(envId, deployProfile, endpoint, accessKeyId, secretKey), |
| 63 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 64 | + resource.TestCheckResourceAttr("automq_integration.test_prometheus", "name", "test-prometheus-updated"), |
| 65 | + ), |
| 66 | + }, |
| 67 | + }, |
| 68 | + }) |
| 69 | + |
| 70 | + // Test CloudWatch Integration |
| 71 | + resource.Test(t, resource.TestCase{ |
| 72 | + PreCheck: func() { testAccPreCheck(t) }, |
| 73 | + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, |
| 74 | + Steps: []resource.TestStep{ |
| 75 | + // Create and Read testing for CloudWatch |
| 76 | + { |
| 77 | + Config: testAccIntegrationCloudWatchConfig(envId, deployProfile, endpoint, accessKeyId, secretKey), |
| 78 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 79 | + resource.TestCheckResourceAttrSet("automq_integration.test_cloudwatch", "id"), |
| 80 | + resource.TestCheckResourceAttr("automq_integration.test_cloudwatch", "environment_id", envId), |
| 81 | + resource.TestCheckResourceAttr("automq_integration.test_cloudwatch", "deploy_profile", deployProfile), |
| 82 | + resource.TestCheckResourceAttr("automq_integration.test_cloudwatch", "type", "cloudWatch"), |
| 83 | + resource.TestCheckResourceAttr("automq_integration.test_cloudwatch", "name", "test-cloudwatch"), |
| 84 | + resource.TestCheckResourceAttrSet("automq_integration.test_cloudwatch", "created_at"), |
| 85 | + ), |
| 86 | + }, |
| 87 | + }, |
| 88 | + }) |
| 89 | +} |
| 90 | + |
| 91 | +func testAccIntegrationPrometheusConfig(envId, deployProfile string, endpoint string, ak string, sk string) string { |
| 92 | + return fmt.Sprintf(` |
| 93 | +provider "automq" { |
| 94 | + automq_byoc_endpoint = "%[3]s" |
| 95 | + automq_byoc_access_key_id = "%[4]s" |
| 96 | + automq_byoc_secret_key = "%[5]s" |
| 97 | +} |
| 98 | +
|
| 99 | +resource "automq_integration" "test_prometheus" { |
| 100 | + environment_id = %[1]q |
| 101 | + deploy_profile = %[2]q |
| 102 | + name = "test-prometheus" |
| 103 | + type = "prometheusRemoteWrite" |
| 104 | + endpoint = "http://localhost:9090/api/v1/write" |
| 105 | + prometheus_remote_write_config = { |
| 106 | + auth_type = "basic" |
| 107 | + username = "user" |
| 108 | + password = "pass" |
| 109 | + } |
| 110 | +} |
| 111 | +`, envId, deployProfile, endpoint, ak, sk) |
| 112 | +} |
| 113 | + |
| 114 | +func testAccIntegrationPrometheusConfigUpdate(envId, deployProfile string, endpoint string, ak string, sk string) string { |
| 115 | + return fmt.Sprintf(` |
| 116 | +provider "automq" { |
| 117 | + automq_byoc_endpoint = "%[3]s" |
| 118 | + automq_byoc_access_key_id = "%[4]s" |
| 119 | + automq_byoc_secret_key = "%[5]s" |
| 120 | +} |
| 121 | +
|
| 122 | +resource "automq_integration" "test_prometheus" { |
| 123 | + environment_id = %[1]q |
| 124 | + deploy_profile = %[2]q |
| 125 | + name = "test-prometheus-updated" |
| 126 | + type = "prometheusRemoteWrite" |
| 127 | + endpoint = "http://localhost:9090/api/v1/write" |
| 128 | + prometheus_remote_write_config = { |
| 129 | + auth_type = "basic" |
| 130 | + username = "user" |
| 131 | + password = "pass" |
| 132 | + } |
| 133 | +} |
| 134 | +`, envId, deployProfile, endpoint, ak, sk) |
| 135 | +} |
| 136 | + |
| 137 | +func testAccIntegrationCloudWatchConfig(envId, deployProfile string, endpoint string, ak string, sk string) string { |
| 138 | + return fmt.Sprintf(` |
| 139 | +provider "automq" { |
| 140 | + automq_byoc_endpoint = "%[3]s" |
| 141 | + automq_byoc_access_key_id = "%[4]s" |
| 142 | + automq_byoc_secret_key = "%[5]s" |
| 143 | +} |
| 144 | + |
| 145 | +resource "automq_integration" "test_cloudwatch" { |
| 146 | + environment_id = %[1]q |
| 147 | + deploy_profile = %[2]q |
| 148 | + name = "test-cloudwatch" |
| 149 | + type = "cloudWatch" |
| 150 | + cloudwatch_config { |
| 151 | + namespace = "AutoMQ/Test" |
| 152 | + } |
| 153 | +} |
| 154 | +`, envId, deployProfile, endpoint, ak, sk) |
| 155 | +} |
0 commit comments