Skip to content

Commit 80f0d05

Browse files
committed
Added - Support for Stack Monitoring to detect OCI compute launch and auto-enable host monitoring
1 parent 15daff2 commit 80f0d05

File tree

7 files changed

+158
-31
lines changed

7 files changed

+158
-31
lines changed

examples/stack_monitoring/config/config.tf

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,36 @@ variable "region" {}
99
variable "compartment_ocid" {}
1010

1111
provider "oci" {
12-
tenancy_ocid = var.tenancy_ocid
13-
user_ocid = var.user_ocid
14-
fingerprint = var.fingerprint
15-
private_key_path = var.private_key_path
16-
region = var.region
12+
tenancy_ocid = var.tenancy_ocid
13+
user_ocid = var.user_ocid
14+
fingerprint = var.fingerprint
15+
private_key_path = var.private_key_path
16+
region = var.region
1717
}
1818

1919
resource "oci_stack_monitoring_config" "test_config_autopromote" {
20-
compartment_id = var.compartment_ocid
21-
config_type = "AUTO_PROMOTE"
22-
resource_type = "HOST"
23-
is_enabled = true
20+
compartment_id = var.compartment_ocid
21+
config_type = "AUTO_PROMOTE"
22+
resource_type = "HOST"
23+
is_enabled = true
24+
}
25+
26+
resource "oci_stack_monitoring_config" "test_compute_auto_activate_plugin_config" {
27+
compartment_id = var.compartment_ocid
28+
config_type = "COMPUTE_AUTO_ACTIVATE_PLUGIN"
29+
is_enabled = true
2430
}
2531

2632
resource "oci_stack_monitoring_config" "test_auto_assign_config" {
2733
compartment_id = var.compartment_ocid
28-
config_type = "LICENSE_AUTO_ASSIGN"
29-
license = "STANDARD_EDITION"
34+
config_type = "LICENSE_AUTO_ASSIGN"
35+
license = "STANDARD_EDITION"
3036
}
3137

3238
resource "oci_stack_monitoring_config" "test_enterprise_extensibility_config" {
3339
compartment_id = var.compartment_ocid
34-
config_type = "LICENSE_ENTERPRISE_EXTENSIBILITY"
35-
is_enabled = true
40+
config_type = "LICENSE_ENTERPRISE_EXTENSIBILITY"
41+
is_enabled = true
3642
}
3743

3844
resource "oci_stack_monitoring_config" "test_onboard_config" {

internal/integrationtest/stack_monitoring_config_test.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var (
5353
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
5454
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
5555
"state": acctest.Representation{RepType: acctest.Optional, Create: `ACTIVE`},
56-
"type": acctest.Representation{RepType: acctest.Optional, Create: `AUTO_PROMOTE`},
56+
"type": acctest.Representation{RepType: acctest.Optional, Create: `COMPUTE_AUTO_ACTIVATE_PLUGIN`},
5757
"filter": acctest.RepresentationGroup{RepType: acctest.Required, Group: StackMonitoringConfigDataSourceFilterRepresentation}}
5858
StackMonitoringConfigDataSourceFilterRepresentation = map[string]interface{}{
5959
"name": acctest.Representation{RepType: acctest.Required, Create: `id`},
@@ -88,9 +88,8 @@ var (
8888
StackMonitoringConfigRepresentation = map[string]interface{}{
8989

9090
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
91-
"config_type": acctest.Representation{RepType: acctest.Required, Create: `AUTO_PROMOTE`},
91+
"config_type": acctest.Representation{RepType: acctest.Required, Create: `COMPUTE_AUTO_ACTIVATE_PLUGIN`},
9292
"is_enabled": acctest.Representation{RepType: acctest.Required, Create: `true`, Update: `false`},
93-
"resource_type": acctest.Representation{RepType: acctest.Required, Create: `HOST`},
9493
//"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
9594
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
9695
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},
@@ -131,9 +130,8 @@ func TestStackMonitoringConfigResource_basic(t *testing.T) {
131130
acctest.GenerateResourceFromRepresentationMap("oci_stack_monitoring_config", "test_config", acctest.Required, acctest.Create, StackMonitoringConfigRepresentation),
132131
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
133132
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
134-
resource.TestCheckResourceAttr(resourceName, "config_type", "AUTO_PROMOTE"),
133+
resource.TestCheckResourceAttr(resourceName, "config_type", "COMPUTE_AUTO_ACTIVATE_PLUGIN"),
135134
resource.TestCheckResourceAttr(resourceName, "is_enabled", "true"),
136-
resource.TestCheckResourceAttr(resourceName, "resource_type", "HOST"),
137135

138136
func(s *terraform.State) (err error) {
139137
resId, err = acctest.FromInstanceState(s, resourceName, "id")
@@ -238,6 +236,7 @@ func TestStackMonitoringConfigResource_basic(t *testing.T) {
238236
resource.TestCheckResourceAttr(singularOnboardDatasourceName, "version", "version2"),
239237
),
240238
},
239+
241240
// delete before next Create
242241
{
243242
Config: config + compartmentIdVariableStr + StackMonitoringConfigResourceDependencies,
@@ -248,12 +247,11 @@ func TestStackMonitoringConfigResource_basic(t *testing.T) {
248247
acctest.GenerateResourceFromRepresentationMap("oci_stack_monitoring_config", "test_config", acctest.Optional, acctest.Create, StackMonitoringConfigRepresentation),
249248
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
250249
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
251-
resource.TestCheckResourceAttr(resourceName, "config_type", "AUTO_PROMOTE"),
250+
resource.TestCheckResourceAttr(resourceName, "config_type", "COMPUTE_AUTO_ACTIVATE_PLUGIN"),
252251
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
253252
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
254253
resource.TestCheckResourceAttrSet(resourceName, "id"),
255254
resource.TestCheckResourceAttr(resourceName, "is_enabled", "true"),
256-
resource.TestCheckResourceAttr(resourceName, "resource_type", "HOST"),
257255
resource.TestCheckResourceAttrSet(resourceName, "state"),
258256

259257
func(s *terraform.State) (err error) {
@@ -277,12 +275,11 @@ func TestStackMonitoringConfigResource_basic(t *testing.T) {
277275
})),
278276
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
279277
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentIdU),
280-
resource.TestCheckResourceAttr(resourceName, "config_type", "AUTO_PROMOTE"),
278+
resource.TestCheckResourceAttr(resourceName, "config_type", "COMPUTE_AUTO_ACTIVATE_PLUGIN"),
281279
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
282280
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
283281
resource.TestCheckResourceAttrSet(resourceName, "id"),
284282
resource.TestCheckResourceAttr(resourceName, "is_enabled", "true"),
285-
resource.TestCheckResourceAttr(resourceName, "resource_type", "HOST"),
286283
resource.TestCheckResourceAttrSet(resourceName, "state"),
287284

288285
func(s *terraform.State) (err error) {
@@ -301,14 +298,12 @@ func TestStackMonitoringConfigResource_basic(t *testing.T) {
301298
acctest.GenerateResourceFromRepresentationMap("oci_stack_monitoring_config", "test_config", acctest.Optional, acctest.Update, StackMonitoringConfigRepresentation),
302299
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
303300
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
304-
resource.TestCheckResourceAttr(resourceName, "config_type", "AUTO_PROMOTE"),
301+
resource.TestCheckResourceAttr(resourceName, "config_type", "COMPUTE_AUTO_ACTIVATE_PLUGIN"),
305302
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
306303
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
307304
resource.TestCheckResourceAttrSet(resourceName, "id"),
308305

309306
resource.TestCheckResourceAttr(resourceName, "is_enabled", "false"),
310-
311-
resource.TestCheckResourceAttr(resourceName, "resource_type", "HOST"),
312307
resource.TestCheckResourceAttrSet(resourceName, "state"),
313308

314309
func(s *terraform.State) (err error) {
@@ -330,7 +325,7 @@ func TestStackMonitoringConfigResource_basic(t *testing.T) {
330325
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
331326
resource.TestCheckResourceAttr(datasourceName, "display_name", "displayName2"),
332327
resource.TestCheckResourceAttr(datasourceName, "state", "ACTIVE"),
333-
resource.TestCheckResourceAttr(datasourceName, "type", "AUTO_PROMOTE"),
328+
resource.TestCheckResourceAttr(datasourceName, "type", "COMPUTE_AUTO_ACTIVATE_PLUGIN"),
334329

335330
resource.TestCheckResourceAttr(datasourceName, "config_collection.#", "1"),
336331
resource.TestCheckResourceAttr(datasourceName, "config_collection.0.items.#", "1"),
@@ -344,12 +339,11 @@ func TestStackMonitoringConfigResource_basic(t *testing.T) {
344339
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
345340
resource.TestCheckResourceAttrSet(singularDatasourceName, "config_id"),
346341
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", compartmentId),
347-
resource.TestCheckResourceAttr(singularDatasourceName, "config_type", "AUTO_PROMOTE"),
342+
resource.TestCheckResourceAttr(singularDatasourceName, "config_type", "COMPUTE_AUTO_ACTIVATE_PLUGIN"),
348343
resource.TestCheckResourceAttr(singularDatasourceName, "display_name", "displayName2"),
349344
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
350345
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
351346
resource.TestCheckResourceAttr(singularDatasourceName, "is_enabled", "false"),
352-
resource.TestCheckResourceAttr(singularDatasourceName, "resource_type", "HOST"),
353347
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
354348
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
355349
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_updated"),

internal/service/stack_monitoring/stack_monitoring_config_data_source.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ func (s *StackMonitoringConfigDataSourceCrud) SetData() error {
100100
s.D.Set("time_created", v.TimeCreated.String())
101101
}
102102

103+
if v.TimeUpdated != nil {
104+
s.D.Set("time_updated", v.TimeUpdated.String())
105+
}
106+
case oci_stack_monitoring.ComputeAutoActivatePluginConfigDetails:
107+
s.D.Set("config_type", "COMPUTE_AUTO_ACTIVATE_PLUGIN")
108+
109+
if v.IsEnabled != nil {
110+
s.D.Set("is_enabled", *v.IsEnabled)
111+
}
112+
113+
if v.CompartmentId != nil {
114+
s.D.Set("compartment_id", *v.CompartmentId)
115+
}
116+
117+
if v.DefinedTags != nil {
118+
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(v.DefinedTags))
119+
}
120+
121+
if v.DisplayName != nil {
122+
s.D.Set("display_name", *v.DisplayName)
123+
}
124+
125+
s.D.Set("freeform_tags", v.FreeformTags)
126+
127+
s.D.Set("state", v.LifecycleState)
128+
129+
if v.SystemTags != nil {
130+
s.D.Set("system_tags", tfresource.SystemTagsToMap(v.SystemTags))
131+
}
132+
133+
if v.TimeCreated != nil {
134+
s.D.Set("time_created", v.TimeCreated.String())
135+
}
136+
103137
if v.TimeUpdated != nil {
104138
s.D.Set("time_updated", v.TimeUpdated.String())
105139
}

internal/service/stack_monitoring/stack_monitoring_config_resource.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func StackMonitoringConfigResource() *schema.Resource {
4040
DiffSuppressFunc: tfresource.EqualIgnoreCaseSuppressDiff,
4141
ValidateFunc: validation.StringInSlice([]string{
4242
"AUTO_PROMOTE",
43+
"COMPUTE_AUTO_ACTIVATE_PLUGIN",
4344
"LICENSE_AUTO_ASSIGN",
4445
"LICENSE_ENTERPRISE_EXTENSIBILITY",
4546
"ONBOARD",
@@ -374,6 +375,44 @@ func (s *StackMonitoringConfigResourceCrud) SetData() error {
374375
s.D.Set("time_created", v.TimeCreated.String())
375376
}
376377

378+
if v.TimeUpdated != nil {
379+
s.D.Set("time_updated", v.TimeUpdated.String())
380+
}
381+
case oci_stack_monitoring.ComputeAutoActivatePluginConfigDetails:
382+
s.D.Set("config_type", "COMPUTE_AUTO_ACTIVATE_PLUGIN")
383+
384+
if v.IsEnabled != nil {
385+
s.D.Set("is_enabled", *v.IsEnabled)
386+
}
387+
388+
if v.CompartmentId != nil {
389+
s.D.Set("compartment_id", *v.CompartmentId)
390+
}
391+
392+
if v.DefinedTags != nil {
393+
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(v.DefinedTags))
394+
}
395+
396+
if v.DisplayName != nil {
397+
s.D.Set("display_name", *v.DisplayName)
398+
}
399+
400+
s.D.Set("freeform_tags", v.FreeformTags)
401+
402+
if v.Id != nil {
403+
s.D.SetId(*v.Id)
404+
}
405+
406+
s.D.Set("state", v.LifecycleState)
407+
408+
if v.SystemTags != nil {
409+
s.D.Set("system_tags", tfresource.SystemTagsToMap(v.SystemTags))
410+
}
411+
412+
if v.TimeCreated != nil {
413+
s.D.Set("time_created", v.TimeCreated.String())
414+
}
415+
377416
if v.TimeUpdated != nil {
378417
s.D.Set("time_updated", v.TimeUpdated.String())
379418
}
@@ -582,6 +621,12 @@ func ConfigSummaryToMap(obj oci_stack_monitoring.ConfigSummary) map[string]inter
582621
}
583622

584623
result["resource_type"] = string(v.ResourceType)
624+
case oci_stack_monitoring.ComputeAutoActivatePluginConfigSummary:
625+
result["config_type"] = "COMPUTE_AUTO_ACTIVATE_PLUGIN"
626+
627+
if v.IsEnabled != nil {
628+
result["is_enabled"] = bool(*v.IsEnabled)
629+
}
585630
case oci_stack_monitoring.LicenseAutoAssignConfigSummary:
586631
result["config_type"] = "LICENSE_AUTO_ASSIGN"
587632

@@ -723,6 +768,31 @@ func (s *StackMonitoringConfigResourceCrud) populateTopLevelPolymorphicCreateCon
723768
details.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
724769
}
725770
request.CreateConfigDetails = details
771+
case strings.ToLower("COMPUTE_AUTO_ACTIVATE_PLUGIN"):
772+
details := oci_stack_monitoring.CreateComputeAutoActivatePluginConfigDetails{}
773+
if isEnabled, ok := s.D.GetOkExists("is_enabled"); ok {
774+
tmp := isEnabled.(bool)
775+
details.IsEnabled = &tmp
776+
}
777+
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
778+
tmp := compartmentId.(string)
779+
details.CompartmentId = &tmp
780+
}
781+
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
782+
convertedDefinedTags, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
783+
if err != nil {
784+
return err
785+
}
786+
details.DefinedTags = convertedDefinedTags
787+
}
788+
if displayName, ok := s.D.GetOkExists("display_name"); ok {
789+
tmp := displayName.(string)
790+
details.DisplayName = &tmp
791+
}
792+
if freeformTags, ok := s.D.GetOkExists("freeform_tags"); ok {
793+
details.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
794+
}
795+
request.CreateConfigDetails = details
726796
case strings.ToLower("LICENSE_AUTO_ASSIGN"):
727797
details := oci_stack_monitoring.CreateLicenseAutoAssignConfigDetails{}
728798
if license, ok := s.D.GetOkExists("license"); ok {
@@ -894,6 +964,29 @@ func (s *StackMonitoringConfigResourceCrud) populateTopLevelPolymorphicUpdateCon
894964
details.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
895965
}
896966
request.UpdateConfigDetails = details
967+
case strings.ToLower("COMPUTE_AUTO_ACTIVATE_PLUGIN"):
968+
details := oci_stack_monitoring.UpdateComputeAutoActivatePluginConfigDetails{}
969+
if isEnabled, ok := s.D.GetOkExists("is_enabled"); ok {
970+
tmp := isEnabled.(bool)
971+
details.IsEnabled = &tmp
972+
}
973+
tmp := s.D.Id()
974+
request.ConfigId = &tmp
975+
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
976+
convertedDefinedTags, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
977+
if err != nil {
978+
return err
979+
}
980+
details.DefinedTags = convertedDefinedTags
981+
}
982+
if displayName, ok := s.D.GetOkExists("display_name"); ok {
983+
tmp := displayName.(string)
984+
details.DisplayName = &tmp
985+
}
986+
if freeformTags, ok := s.D.GetOkExists("freeform_tags"); ok {
987+
details.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
988+
}
989+
request.UpdateConfigDetails = details
897990
case strings.ToLower("LICENSE_AUTO_ASSIGN"):
898991
details := oci_stack_monitoring.UpdateLicenseAutoAssignConfigDetails{}
899992
if license, ok := s.D.GetOkExists("license"); ok {

website/docs/d/stack_monitoring_config.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ The following attributes are exported:
4444
* `stack_monitoring_assignment` - Assignment of dynamic group in context of Stack Monitoring service. It describes the purpose of dynamic groups in Stack Monitoring.
4545
* `freeform_tags` - Simple key-value pair that is applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
4646
* `id` - The Unique Oracle ID (OCID) that is immutable on creation.
47+
* `is_enabled` - True if automatic activation of the Management Agent plugin, automatic promotion or enterprise extensibility is enabled, false if it is not enabled.
4748
* `is_manually_onboarded` - True if customer decides marks configuration as manually configured.
48-
* `is_enabled` - True if automatic promotion or enterprise extensibility is enabled, false if it is not enabled.
4949
* `license` - License edition.
5050
* `policy_names` - List of policy names assigned for onboarding
5151
* `resource_type` - The type of resource to configure for automatic promotion.

website/docs/d/stack_monitoring_configs.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The following attributes are exported:
6060
* `freeform_tags` - Simple key-value pair that is applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
6161
* `id` - The Unique Oracle ID (OCID) that is immutable on creation.
6262
* `is_manually_onboarded` - True if customer decides marks configuration as manually configured.
63-
* `is_enabled` - True if automatic promotion or enterprise extensibility is enabled, false if it is not enabled.
63+
* `is_enabled` - True if automatic activation of the Management Agent plugin, automatic promotion or enterprise extensibility is enabled, false if it is not enabled.
6464
* `license` - License edition.
6565
* `policy_names` - List of policy names assigned for onboarding
6666
* `resource_type` - The type of resource to configure for automatic promotion.

website/docs/r/stack_monitoring_config.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The following attributes are exported:
8484
* `freeform_tags` - Simple key-value pair that is applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
8585
* `id` - The Unique Oracle ID (OCID) that is immutable on creation.
8686
* `is_manually_onboarded` - True if customer decides marks configuration as manually configured.
87-
* `is_enabled` - True if automatic promotion or enterprise extensibility is enabled, false if it is not enabled.
87+
* `is_enabled` - True if automatic activation of the Management Agent plugin, automatic promotion or enterprise extensibility is enabled, false if it is not enabled.
8888
* `license` - License edition.
8989
* `policy_names` - List of policy names assigned for onboarding
9090
* `resource_type` - The type of resource to configure for automatic promotion.

0 commit comments

Comments
 (0)