@@ -15,17 +15,33 @@ import (
1515type ComponentSuite struct {
1616 helper.TestSuite
1717
18- DDAPIKey string
19- DDHost string
20- RandomID string
21- AWSRegion string
18+ datadogAPIKey string // Datadog API key
19+ datadogAppKey string // Datadog App key
20+ datadogHost string // Datadog host
21+ randomID string
22+ awsRegion string
2223}
2324
2425func (s * ComponentSuite ) TestBasicDatadogMonitor () {
2526 const component = "datadog-monitor/basic"
2627 const stack = "default-test"
2728 const awsRegion = "us-east-2"
2829
30+ randomID := strings .ToLower (random .UniqueId ())
31+
32+ // Store the Datadog API key in SSM for the duration of the test.
33+ apiKeyPath := fmt .Sprintf ("/datadog/%s/datadog_api_key" , randomID )
34+ awsTerratest .PutParameter (s .T (), s .awsRegion , apiKeyPath , "Datadog API Key" , s .datadogAPIKey )
35+
36+ // Store the Datadog App key in SSM for the duration of the test.
37+ appKeyPath := fmt .Sprintf ("/datadog/%s/datadog_app_key" , randomID )
38+ awsTerratest .PutParameter (s .T (), s .awsRegion , appKeyPath , "Datadog App Key" , s .datadogAppKey )
39+
40+ defer func () {
41+ awsTerratest .DeleteParameter (s .T (), awsRegion , apiKeyPath )
42+ awsTerratest .DeleteParameter (s .T (), awsRegion , appKeyPath )
43+ }()
44+
2945 defer s .DestroyAtmosComponent (s .T (), component , stack , nil )
3046 options , _ := s .DeployAtmosComponent (s .T (), component , stack , nil )
3147 assert .NotNil (s .T (), options )
@@ -36,6 +52,23 @@ func (s *ComponentSuite) TestBasicDatadogMonitor() {
3652func (s * ComponentSuite ) TestEnabledFlag () {
3753 const component = "datadog-monitor/disabled"
3854 const stack = "default-test"
55+ const awsRegion = "us-east-2"
56+
57+ randomID := strings .ToLower (random .UniqueId ())
58+
59+ // Store the Datadog API key in SSM for the duration of the test.
60+ apiKeyPath := fmt .Sprintf ("/datadog/%s/datadog_api_key" , randomID )
61+ awsTerratest .PutParameter (s .T (), s .awsRegion , apiKeyPath , "Datadog API Key" , s .datadogAPIKey )
62+
63+ // Store the Datadog App key in SSM for the duration of the test.
64+ appKeyPath := fmt .Sprintf ("/datadog/%s/datadog_app_key" , randomID )
65+ awsTerratest .PutParameter (s .T (), s .awsRegion , appKeyPath , "Datadog App Key" , s .datadogAppKey )
66+
67+ defer func () {
68+ awsTerratest .DeleteParameter (s .T (), awsRegion , apiKeyPath )
69+ awsTerratest .DeleteParameter (s .T (), awsRegion , appKeyPath )
70+ }()
71+
3972 s .VerifyEnabledFlag (component , stack , nil )
4073}
4174
@@ -44,27 +77,39 @@ func (s *ComponentSuite) SetupSuite() {
4477 s .Config .ComponentDestDir = "components/terraform/datadog-monitor"
4578
4679 // Store the Datadog API key in SSM for the duration of the test.
47- // The API key is obtained from GitHub secrets as an environment variable
48- // in the test pipelines .
49- s .DDAPIKey = os .Getenv ("DD_API_KEY" )
50- if s .DDAPIKey == "" {
80+ // Add the key to /datadog/<RANDOMID>/datadog_api_key to avoid
81+ // conflicts during parallel tests and remove the key after the test .
82+ s .datadogAPIKey = os .Getenv ("DD_API_KEY" )
83+ if s .datadogAPIKey == "" {
5184 s .T ().Fatal ("DD_API_KEY environment variable must be set" )
5285 }
5386
54- s .RandomID = strings .ToLower (random .UniqueId ())
55- s .AWSRegion = "us-east-2"
56- s .DDHost = "us5.datadoghq.com"
87+ // Store the Datadog App key in SSM for the duration of the test.
88+ // Add the key to /datadog/<RANDOMID>/datadog_app_key to avoid
89+ // conflicts during parallel tests and remove the key after the test.
90+ s .datadogAppKey = os .Getenv ("DD_APP_KEY" )
91+ if s .datadogAPIKey == "" {
92+ s .T ().Fatal ("DD_APP_KEY environment variable must be set" )
93+ }
94+
95+ s .randomID = strings .ToLower (random .UniqueId ())
96+ s .awsRegion = "us-east-2"
97+ s .datadogHost = "us5.datadoghq.com"
5798
5899 if ! s .Config .SkipDeployDependencies {
59- secretPath := fmt .Sprintf ("/datadog/%s/api_key" , s .RandomID )
60- awsTerratest .PutParameter (s .T (), s .AWSRegion , secretPath , "Datadog API Key" , s .DDAPIKey )
100+ apiKeyPath := fmt .Sprintf ("/datadog/%s/datadog_api_key" , s .randomID )
101+ awsTerratest .PutParameter (s .T (), s .awsRegion , apiKeyPath , "Datadog API Key" , s .datadogAPIKey )
102+
103+ appKeyPath := fmt .Sprintf ("/datadog/%s/datadog_app_key" , s .randomID )
104+ awsTerratest .PutParameter (s .T (), s .awsRegion , appKeyPath , "Datadog App Key" , s .datadogAppKey )
61105
62106 inputs := map [string ]any {
63- "datadog_site_url" : s .DDHost ,
64- "datadog_secrets_source_store_account_region" : s .AWSRegion ,
65- "datadog_secrets_source_store_account_stage" : "default" ,
66- "datadog_secrets_source_store_account_tenant" : "test" ,
67- "datadog_api_secret_key" : s .RandomID ,
107+ "datadog_site_url" : s .datadogHost ,
108+ "datadog_secrets_source_store_account_region" : s .awsRegion ,
109+ "datadog_secrets_source_store_account_stage" : "test" ,
110+ "datadog_secrets_source_store_account_tenant" : "default" ,
111+ "datadog_api_secret_key" : s .randomID ,
112+ "datadog_app_secret_key" : s .randomID ,
68113 }
69114 s .AddDependency (s .T (), "datadog-configuration" , "default-test" , & inputs )
70115 }
@@ -75,8 +120,11 @@ func (s *ComponentSuite) SetupSuite() {
75120func (s * ComponentSuite ) TearDownSuite () {
76121 s .TestSuite .TearDownSuite ()
77122 if ! s .Config .SkipDestroyDependencies {
78- secretPath := fmt .Sprintf ("/datadog/%s/api_key" , s .RandomID )
79- awsTerratest .DeleteParameter (s .T (), s .AWSRegion , secretPath )
123+ apiKeyPath := fmt .Sprintf ("/datadog/%s/datadog_api_key" , s .randomID )
124+ awsTerratest .DeleteParameter (s .T (), s .awsRegion , apiKeyPath )
125+
126+ appKeyPath := fmt .Sprintf ("/datadog/%s/datadog_app_key" , s .randomID )
127+ awsTerratest .DeleteParameter (s .T (), s .awsRegion , appKeyPath )
80128 }
81129}
82130
0 commit comments