Skip to content

Commit 8db9380

Browse files
authored
feat: set default TF_ACC_TIMEOUT for tests and update integration schema (#77)
* feat: set default TF_ACC_TIMEOUT for tests and update integration schema * feat: enhance integration tests with BYOC endpoint and credentials * docs: update kafka_instance documentation to clarify integrations schema
1 parent 35bc103 commit 8db9380

11 files changed

+248
-38
lines changed

docs/data-sources/kafka_instance.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,16 @@ Read-Only:
107107
<a id="nestedatt--features"></a>
108108
### Nested Schema for `features`
109109

110+
Optional:
111+
112+
- `integrations` (Set of String) Integration identifiers
113+
110114
Read-Only:
111115

112116
- `instance_configs` (Map of String) Additional configuration for the Kafka Instance. The currently supported parameters can be set by referring to the [documentation](https://docs.automq.com/automq-cloud/using-automq-for-kafka/restrictions#instance-level-configuration).
113-
- `integrations` (Attributes List) Integration configurations (see [below for nested schema](#nestedatt--features--integrations))
114117
- `security` (Attributes) (see [below for nested schema](#nestedatt--features--security))
115118
- `wal_mode` (String) Write-Ahead Logging mode: EBSWAL (using EBS as write buffer) or S3WAL (using object storage as write buffer). Defaults to EBSWAL.
116119

117-
<a id="nestedatt--features--integrations"></a>
118-
### Nested Schema for `features.integrations`
119-
120-
Read-Only:
121-
122-
- `id` (String) Integration ID
123-
124-
125120
<a id="nestedatt--features--security"></a>
126121
### Nested Schema for `features.security`
127122

internal/framework/util_wait.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func WaitForKafkaClusterState(ctx context.Context, c *client.Client, clusterId, pendingState, targetState string, timeout time.Duration, refreshFunc retry.StateRefreshFunc) error {
15-
delay, pollInterval := 20*time.Second, 5*time.Second
15+
delay, pollInterval := 20*time.Second, 10*time.Second
1616
stateConf := &retry.StateChangeConf{
1717
Pending: []string{pendingState},
1818
Target: []string{targetState},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package provider
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
)
9+
10+
func TestDataBucketProfilesDataSource(t *testing.T) {
11+
envId := os.Getenv("AUTOMQ_TEST_ENV_ID")
12+
if envId == "" {
13+
t.Skip("AUTOMQ_TEST_ENV_ID must be set for this test")
14+
}
15+
16+
envVars := getRequiredEnvVars(t)
17+
18+
resource.Test(t, resource.TestCase{
19+
PreCheck: func() { testAccPreCheck(t) },
20+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
21+
Steps: []resource.TestStep{
22+
{
23+
Config: testAccDataBucketProfilesDataSourceConfig(envVars),
24+
Check: resource.ComposeAggregateTestCheckFunc(
25+
// Check that the attributes exist and have non-empty values
26+
resource.TestCheckResourceAttrSet("data.automq_data_bucket_profiles.test", "environment_id"),
27+
resource.TestCheckResourceAttrSet("data.automq_data_bucket_profiles.test", "profile_name"),
28+
// Verify the values match our environment variables
29+
resource.TestCheckResourceAttr("data.automq_data_bucket_profiles.test", "environment_id", envVars["AUTOMQ_TEST_ENV_ID"]),
30+
resource.TestCheckResourceAttr("data.automq_data_bucket_profiles.test", "profile_name", envVars["AUTOMQ_TEST_DEPLOY_PROFILE"]),
31+
// Verify that data_buckets list exists and has elements
32+
resource.TestCheckResourceAttrSet("data.automq_data_bucket_profiles.test", "data_buckets.#"),
33+
),
34+
},
35+
},
36+
})
37+
}
38+
39+
func testAccDataBucketProfilesDataSourceConfig(envVars map[string]string) string {
40+
return `
41+
provider "automq" {
42+
automq_byoc_endpoint = "` + envVars["AUTOMQ_BYOC_ENDPOINT"] + `"
43+
automq_byoc_access_key_id = "` + envVars["AUTOMQ_BYOC_ACCESS_KEY_ID"] + `"
44+
automq_byoc_secret_key = "` + envVars["AUTOMQ_BYOC_SECRET_KEY"] + `"
45+
}
46+
47+
data "automq_data_bucket_profiles" "test" {
48+
environment_id = "` + envVars["AUTOMQ_TEST_ENV_ID"] + `"
49+
profile_name = "` + envVars["AUTOMQ_TEST_DEPLOY_PROFILE"] + `"
50+
}
51+
`
52+
}

internal/provider/datasource_deploy_profile_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ func TestAccDeployProfileDataSource(t *testing.T) {
4141
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "ops_bucket.provider"),
4242
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "ops_bucket.region"),
4343

44-
// Verify data buckets
45-
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "data_buckets.#"),
46-
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "data_buckets.0.id"),
47-
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "data_buckets.0.bucket_name"),
48-
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "data_buckets.0.provider"),
49-
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "data_buckets.0.region"),
50-
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "data_buckets.0.gmt_create"),
51-
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "data_buckets.0.gmt_modified"),
52-
5344
// Verify DNS and instance profile
5445
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "dns_zone"),
5546
resource.TestCheckResourceAttrSet("data.automq_deploy_profile.test", "instance_profile"),

internal/provider/datasource_instance.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,10 @@ func (r *KafkaInstanceDataSource) Schema(_ context.Context, _ datasource.SchemaR
124124
MarkdownDescription: "Additional configuration for the Kafka Instance. The currently supported parameters can be set by referring to the [documentation](https://docs.automq.com/automq-cloud/using-automq-for-kafka/restrictions#instance-level-configuration).",
125125
Computed: true,
126126
},
127-
"integrations": schema.ListNestedAttribute{
128-
Computed: true,
129-
Description: "Integration configurations",
130-
NestedObject: schema.NestedAttributeObject{
131-
Attributes: map[string]schema.Attribute{
132-
"id": schema.StringAttribute{
133-
Computed: true,
134-
Description: "Integration ID",
135-
},
136-
},
137-
},
127+
"integrations": schema.SetAttribute{
128+
Optional: true,
129+
ElementType: types.StringType,
130+
Description: "Integration identifiers",
138131
},
139132
"security": schema.SingleNestedAttribute{
140133
Computed: true,

internal/provider/datasource_instance_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
)
1010

1111
func TestAccKafkaInstanceDataSource(t *testing.T) {
12+
if os.Getenv("TF_ACC_TIMEOUT") == "" {
13+
t.Setenv("TF_ACC_TIMEOUT", "2h")
14+
}
1215
if os.Getenv("AUTOMQ_BYOC_ENDPOINT") == "" {
1316
t.Skip("Skipping test as AUTOMQ_TEST_DEPLOY_PROFILE is not set")
1417
}

internal/provider/resource_instance.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,10 @@ func (r *KafkaInstanceResource) ImportState(ctx context.Context, req resource.Im
736736
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), instanceId)...)
737737

738738
config := types.MapValueMust(types.StringType, map[string]attr.Value{})
739+
integration := types.SetValueMust(types.StringType, []attr.Value{})
739740
features := models.FeaturesModel{
740741
InstanceConfigs: config,
742+
Integrations: integration,
741743
}
742744
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("features"), features)...)
743745
}

internal/provider/resource_instance_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import (
1919

2020
func getRequiredEnvVars(t *testing.T) map[string]string {
2121
envVars := map[string]string{
22-
"AUTOMQ_BYOC_ENDPOINT": "http://44.207.11.83:8080", // os.Getenv("AUTOMQ_BYOC_ENDPOINT"),
23-
"AUTOMQ_BYOC_ACCESS_KEY_ID": "TeDaXnaRASROF9AZ", // os.Getenv("AUTOMQ_BYOC_ACCESS_KEY_ID"),
24-
"AUTOMQ_BYOC_SECRET_KEY": "Lj41KSn5WciTS9UNc5cf4k3MRcIbs0D4", // os.Getenv("AUTOMQ_BYOC_SECRET_KEY"),
25-
"AUTOMQ_TEST_ENV_ID": "env-vstohprknxupims1", // os.Getenv("AUTOMQ_TEST_ENV_ID"),
26-
"AUTOMQ_TEST_SUBNET_ID": "subnet-0005ed305e0891752", //os.Getenv("AUTOMQ_TEST_SUBNET_ID"),
27-
"AUTOMQ_TEST_ZONE": "us-east-1a", // os.Getenv("AUTOMQ_TEST_ZONE"),
28-
"AUTOMQ_TEST_DEPLOY_PROFILE": "default", // os.Getenv("AUTOMQ_TEST_DEPLOY_PROFILE"),
22+
"AUTOMQ_BYOC_ENDPOINT": os.Getenv("AUTOMQ_BYOC_ENDPOINT"),
23+
"AUTOMQ_BYOC_ACCESS_KEY_ID": os.Getenv("AUTOMQ_BYOC_ACCESS_KEY_ID"),
24+
"AUTOMQ_BYOC_SECRET_KEY": os.Getenv("AUTOMQ_BYOC_SECRET_KEY"),
25+
"AUTOMQ_TEST_ENV_ID": os.Getenv("AUTOMQ_TEST_ENV_ID"),
26+
"AUTOMQ_TEST_SUBNET_ID": os.Getenv("AUTOMQ_TEST_SUBNET_ID"),
27+
"AUTOMQ_TEST_ZONE": os.Getenv("AUTOMQ_TEST_ZONE"),
28+
"AUTOMQ_TEST_DEPLOY_PROFILE": os.Getenv("AUTOMQ_TEST_DEPLOY_PROFILE"),
2929
}
3030

3131
missingVars := []string{}
@@ -59,7 +59,7 @@ func generateRandomSuffix() string {
5959
// Define version upgrade path
6060
var kafkaVersionUpgrades = []string{
6161
"1.3.10",
62-
"1.4.0",
62+
"1.4.1",
6363
}
6464

6565
// TestConfig holds the test configuration parameters
@@ -244,6 +244,9 @@ func TestAccKafkaInstanceResource(t *testing.T) {
244244
if os.Getenv("AUTOMQ_BYOC_ENDPOINT") == "" {
245245
t.Skip("Skipping test as AUTOMQ_TEST_DEPLOY_PROFILE is not set")
246246
}
247+
if os.Getenv("TF_ACC_TIMEOUT") == "" {
248+
t.Setenv("TF_ACC_TIMEOUT", "2h")
249+
}
247250

248251
envVars := getRequiredEnvVars(t)
249252
suffix := generateRandomSuffix()
@@ -416,6 +419,11 @@ func TestAccKafkaInstanceSecurityCombinations(t *testing.T) {
416419
if os.Getenv("AUTOMQ_BYOC_ENDPOINT") == "" {
417420
t.Skip("Skipping test as AUTOMQ_TEST_DEPLOY_PROFILE is not set")
418421
}
422+
if os.Getenv("TF_ACC_TIMEOUT") == "" {
423+
t.Setenv("TF_ACC_TIMEOUT", "2h")
424+
}
425+
426+
t.Skip("Skipping test")
419427

420428
envVars := getRequiredEnvVars(t)
421429
suffix := generateRandomSuffix()
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
}

internal/provider/resource_topic_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ func TestAccKafkaTopicResource(t *testing.T) {
1313
if os.Getenv("AUTOMQ_BYOC_ENDPOINT") == "" {
1414
t.Skip("Skipping test as AUTOMQ_TEST_DEPLOY_PROFILE is not set")
1515
}
16+
if os.Getenv("TF_ACC_TIMEOUT") == "" {
17+
t.Setenv("TF_ACC_TIMEOUT", "2h")
18+
}
1619

1720
envVars := getRequiredEnvVars(t)
1821
suffix := generateRandomSuffix()
@@ -94,6 +97,11 @@ func TestAccKafkaTopicResource(t *testing.T) {
9497
ImportState: true,
9598
ImportStateVerify: true,
9699
ImportStateVerifyIdentifierAttribute: "topic_id",
100+
ImportStateVerifyIgnore: []string{
101+
"configs.%", // ignore configs
102+
"configs.cleanup.policy",
103+
"configs.retention.ms",
104+
},
97105
ImportStateIdFunc: func(s *terraform.State) (string, error) {
98106
rs, ok := s.RootModule().Resources["automq_kafka_topic.test"]
99107
if !ok {

0 commit comments

Comments
 (0)