Skip to content

Commit 8f4ad91

Browse files
rcohenmaalexng-canuck
authored andcommitted
Adding ability to disable monitoring in instances
1 parent 4bc8444 commit 8f4ad91

11 files changed

+183
-2
lines changed

oci/core_image_resource.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ func CoreImageResource() *schema.Resource {
119119
},
120120

121121
// Computed
122+
"agent_features": {
123+
Type: schema.TypeList,
124+
Computed: true,
125+
MaxItems: 1,
126+
MinItems: 1,
127+
Elem: &schema.Resource{
128+
Schema: map[string]*schema.Schema{
129+
// Required
130+
131+
// Optional
132+
133+
// Computed
134+
"is_monitoring_supported": {
135+
Type: schema.TypeBool,
136+
Computed: true,
137+
},
138+
},
139+
},
140+
},
122141
"base_image_id": {
123142
Type: schema.TypeString,
124143
Computed: true,
@@ -379,6 +398,12 @@ func (s *CoreImageResourceCrud) Delete() error {
379398
}
380399

381400
func (s *CoreImageResourceCrud) SetData() error {
401+
if s.Res.AgentFeatures != nil {
402+
s.D.Set("agent_features", []interface{}{InstanceAgentFeaturesToMap(s.Res.AgentFeatures)})
403+
} else {
404+
s.D.Set("agent_features", nil)
405+
}
406+
382407
if s.Res.BaseImageId != nil {
383408
s.D.Set("base_image_id", *s.Res.BaseImageId)
384409
}
@@ -474,3 +499,13 @@ func (s *CoreImageResourceCrud) mapToImageSourceDetails(fieldKeyFormat string) (
474499
}
475500
return baseObject, nil
476501
}
502+
503+
func InstanceAgentFeaturesToMap(obj *oci_core.InstanceAgentFeatures) map[string]interface{} {
504+
result := map[string]interface{}{}
505+
506+
if obj.IsMonitoringSupported != nil {
507+
result["is_monitoring_supported"] = bool(*obj.IsMonitoringSupported)
508+
}
509+
510+
return result
511+
}

oci/core_images_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ func (s *CoreImagesDataSourceCrud) SetData() error {
157157
image["compartment_id"] = *r.CompartmentId
158158
}
159159

160+
if r.AgentFeatures != nil {
161+
image["agent_features"] = []interface{}{InstanceAgentFeaturesToMap(r.AgentFeatures)}
162+
} else {
163+
image["agent_features"] = nil
164+
}
165+
160166
if r.BaseImageId != nil {
161167
image["base_image_id"] = *r.BaseImageId
162168
}

oci/core_instance_data_source.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ func CoreInstanceDataSource() *schema.Resource {
2121
Required: true,
2222
},
2323
// Computed
24+
"agent_config": {
25+
Type: schema.TypeList,
26+
Computed: true,
27+
Elem: &schema.Resource{
28+
Schema: map[string]*schema.Schema{
29+
// Required
30+
31+
// Optional
32+
"is_monitoring_disabled": {
33+
Type: schema.TypeBool,
34+
Optional: true,
35+
Computed: true,
36+
},
37+
38+
// Computed
39+
},
40+
},
41+
},
2442
"availability_domain": {
2543
Type: schema.TypeString,
2644
Computed: true,
@@ -239,6 +257,12 @@ func (s *CoreInstanceDataSourceCrud) SetData() error {
239257

240258
s.D.SetId(*s.Res.Id)
241259

260+
if s.Res.AgentConfig != nil {
261+
s.D.Set("agent_config", []interface{}{InstanceAgentConfigToMap(s.Res.AgentConfig)})
262+
} else {
263+
s.D.Set("agent_config", nil)
264+
}
265+
242266
if s.Res.AvailabilityDomain != nil {
243267
s.D.Set("availability_domain", *s.Res.AvailabilityDomain)
244268
}

oci/core_instance_resource.go

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ func CoreInstanceResource() *schema.Resource {
5252
},
5353

5454
// Optional
55+
"agent_config": {
56+
Type: schema.TypeList,
57+
Optional: true,
58+
Computed: true,
59+
MaxItems: 1,
60+
MinItems: 1,
61+
Elem: &schema.Resource{
62+
Schema: map[string]*schema.Schema{
63+
// Required
64+
65+
// Optional
66+
"is_monitoring_disabled": {
67+
Type: schema.TypeBool,
68+
Optional: true,
69+
Computed: true,
70+
},
71+
72+
// Computed
73+
},
74+
},
75+
},
5576
"create_vnic_details": {
5677
Type: schema.TypeList,
5778
Optional: true,
@@ -425,6 +446,17 @@ func (s *CoreInstanceResourceCrud) DeletedTarget() []string {
425446
func (s *CoreInstanceResourceCrud) Create() error {
426447
request := oci_core.LaunchInstanceRequest{}
427448

449+
if agentConfig, ok := s.D.GetOkExists("agent_config"); ok {
450+
if tmpList := agentConfig.([]interface{}); len(tmpList) > 0 {
451+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "agent_config", 0)
452+
tmp, err := s.mapToLaunchInstanceAgentConfigDetails(fieldKeyFormat)
453+
if err != nil {
454+
return err
455+
}
456+
request.AgentConfig = &tmp
457+
}
458+
}
459+
428460
if availabilityDomain, ok := s.D.GetOkExists("availability_domain"); ok {
429461
tmp := availabilityDomain.(string)
430462
request.AvailabilityDomain = &tmp
@@ -552,6 +584,17 @@ func (s *CoreInstanceResourceCrud) Get() error {
552584
func (s *CoreInstanceResourceCrud) Update() error {
553585
request := oci_core.UpdateInstanceRequest{}
554586

587+
if agentConfig, ok := s.D.GetOkExists("agent_config"); ok {
588+
if tmpList := agentConfig.([]interface{}); len(tmpList) > 0 {
589+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "agent_config", 0)
590+
tmp, err := s.mapToUpdateInstanceAgentConfigDetails(fieldKeyFormat)
591+
if err != nil {
592+
return err
593+
}
594+
request.AgentConfig = &tmp
595+
}
596+
}
597+
555598
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
556599
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
557600
if err != nil {
@@ -646,6 +689,12 @@ func (s *CoreInstanceResourceCrud) Delete() error {
646689
}
647690

648691
func (s *CoreInstanceResourceCrud) SetData() error {
692+
if s.Res.AgentConfig != nil {
693+
s.D.Set("agent_config", []interface{}{InstanceAgentConfigToMap(s.Res.AgentConfig)})
694+
} else {
695+
s.D.Set("agent_config", nil)
696+
}
697+
649698
if s.Res.AvailabilityDomain != nil {
650699
s.D.Set("availability_domain", *s.Res.AvailabilityDomain)
651700
}
@@ -929,7 +978,7 @@ func (s *CoreInstanceResourceCrud) mapToInstanceSourceDetails(fieldKeyFormat str
929978
tmp := bootVolumeSizeInGBs.(string)
930979
tmpInt64, err := strconv.ParseInt(tmp, 10, 64)
931980
if err != nil {
932-
return details, fmt.Errorf("unable to convert bootVolumeSizeInGBs string: %s to an int64 and encountered error: %v", tmp, err)
981+
return nil, fmt.Errorf("unable to convert bootVolumeSizeInGBs string: %s to an int64 and encountered error: %v", tmp, err)
933982
}
934983
details.BootVolumeSizeInGBs = &tmpInt64
935984
}
@@ -987,6 +1036,38 @@ func InstanceSourceDetailsToMap(obj *oci_core.InstanceSourceDetails, bootVolume
9871036
return result
9881037
}
9891038

1039+
func (s *CoreInstanceResourceCrud) mapToLaunchInstanceAgentConfigDetails(fieldKeyFormat string) (oci_core.LaunchInstanceAgentConfigDetails, error) {
1040+
result := oci_core.LaunchInstanceAgentConfigDetails{}
1041+
1042+
if isMonitoringDisabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_monitoring_disabled")); ok {
1043+
tmp := isMonitoringDisabled.(bool)
1044+
result.IsMonitoringDisabled = &tmp
1045+
}
1046+
1047+
return result, nil
1048+
}
1049+
1050+
func (s *CoreInstanceResourceCrud) mapToUpdateInstanceAgentConfigDetails(fieldKeyFormat string) (oci_core.UpdateInstanceAgentConfigDetails, error) {
1051+
result := oci_core.UpdateInstanceAgentConfigDetails{}
1052+
1053+
if isMonitoringDisabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_monitoring_disabled")); ok {
1054+
tmp := isMonitoringDisabled.(bool)
1055+
result.IsMonitoringDisabled = &tmp
1056+
}
1057+
1058+
return result, nil
1059+
}
1060+
1061+
func InstanceAgentConfigToMap(obj *oci_core.InstanceAgentConfig) map[string]interface{} {
1062+
result := map[string]interface{}{}
1063+
1064+
if obj.IsMonitoringDisabled != nil {
1065+
result["is_monitoring_disabled"] = bool(*obj.IsMonitoringDisabled)
1066+
}
1067+
1068+
return result
1069+
}
1070+
9901071
func mapToExtendedMetadata(rm map[string]interface{}) (map[string]interface{}, error) {
9911072
result := make(map[string]interface{})
9921073
for k, v := range rm {

oci/core_instance_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
"availability_domain": Representation{repType: Required, create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
4242
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
4343
"shape": Representation{repType: Required, create: `VM.Standard2.1`},
44+
"agent_config": RepresentationGroup{Optional, instanceAgentConfigRepresentation},
4445
"create_vnic_details": RepresentationGroup{Optional, instanceCreateVnicDetailsRepresentation},
4546
"defined_tags": Representation{repType: 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")}`},
4647
"display_name": Representation{repType: Optional, create: `displayName`, update: `displayName2`},
@@ -62,6 +63,9 @@ var (
6263
"source_details": RepresentationGroup{Optional, instanceSourceDetailsRepresentation},
6364
"subnet_id": Representation{repType: Required, create: `${oci_core_subnet.test_subnet.id}`},
6465
}
66+
instanceAgentConfigRepresentation = map[string]interface{}{
67+
"is_monitoring_disabled": Representation{repType: Optional, create: `false`, update: `true`},
68+
}
6569
instanceCreateVnicDetailsRepresentation = map[string]interface{}{
6670
"subnet_id": Representation{repType: Required, create: `${oci_core_subnet.test_subnet.id}`},
6771
"assign_public_ip": Representation{repType: Optional, create: `true`},
@@ -177,6 +181,8 @@ func TestCoreInstanceResource_basic(t *testing.T) {
177181
Config: config + compartmentIdVariableStr + InstanceResourceDependencies +
178182
generateResourceFromRepresentationMap("oci_core_instance", "test_instance", Optional, Create, instanceRepresentation),
179183
Check: resource.ComposeAggregateTestCheckFunc(
184+
resource.TestCheckResourceAttr(resourceName, "agent_config.#", "1"),
185+
resource.TestCheckResourceAttr(resourceName, "agent_config.0.is_monitoring_disabled", "false"),
180186
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
181187
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
182188
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.#", "1"),
@@ -221,6 +227,8 @@ func TestCoreInstanceResource_basic(t *testing.T) {
221227
Config: config + compartmentIdVariableStr + InstanceResourceDependencies +
222228
generateResourceFromRepresentationMap("oci_core_instance", "test_instance", Optional, Update, instanceRepresentation),
223229
Check: resource.ComposeAggregateTestCheckFunc(
230+
resource.TestCheckResourceAttr(resourceName, "agent_config.#", "1"),
231+
resource.TestCheckResourceAttr(resourceName, "agent_config.0.is_monitoring_disabled", "true"),
224232
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
225233
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
226234
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.#", "1"),
@@ -274,6 +282,8 @@ func TestCoreInstanceResource_basic(t *testing.T) {
274282
resource.TestCheckResourceAttr(datasourceName, "state", "RUNNING"),
275283

276284
resource.TestCheckResourceAttr(datasourceName, "instances.#", "1"),
285+
resource.TestCheckResourceAttr(datasourceName, "instances.0.agent_config.#", "1"),
286+
resource.TestCheckResourceAttr(datasourceName, "instances.0.agent_config.0.is_monitoring_disabled", "true"),
277287
resource.TestCheckResourceAttrSet(datasourceName, "instances.0.availability_domain"),
278288
resource.TestCheckResourceAttr(datasourceName, "instances.0.compartment_id", compartmentId),
279289
resource.TestCheckResourceAttr(datasourceName, "instances.0.defined_tags.%", "1"),
@@ -304,6 +314,8 @@ func TestCoreInstanceResource_basic(t *testing.T) {
304314
resource.TestCheckResourceAttrSet(singularDatasourceName, "instance_id"),
305315
resource.TestCheckResourceAttrSet(singularDatasourceName, "subnet_id"),
306316

317+
resource.TestCheckResourceAttr(singularDatasourceName, "agent_config.#", "1"),
318+
resource.TestCheckResourceAttr(singularDatasourceName, "agent_config.0.is_monitoring_disabled", "true"),
307319
resource.TestCheckResourceAttrSet(singularDatasourceName, "availability_domain"),
308320
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", compartmentId),
309321
resource.TestCheckResourceAttr(singularDatasourceName, "defined_tags.%", "1"),

oci/core_instances_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ func (s *CoreInstancesDataSourceCrud) SetData() error {
126126
"compartment_id": *r.CompartmentId,
127127
}
128128

129+
if r.AgentConfig != nil {
130+
instance["agent_config"] = []interface{}{InstanceAgentConfigToMap(r.AgentConfig)}
131+
} else {
132+
instance["agent_config"] = nil
133+
}
134+
129135
if r.AvailabilityDomain != nil {
130136
instance["availability_domain"] = *r.AvailabilityDomain
131137
}

website/docs/d/core_images.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ The following attributes are exported:
5656

5757
The following attributes are exported:
5858

59+
* `agent_features` -
60+
* `is_monitoring_supported` - Whether the agent running on the instance can gather performance metrics and monitor the instance.
5961
* `base_image_id` - The OCID of the image originally used to launch the instance.
6062
* `compartment_id` - The OCID of the compartment containing the instance you want to use as the basis for the image.
6163
* `create_image_allowed` - Whether instances launched with this image can be used to create new images. For example, you cannot create an image of an Oracle Database instance. Example: `true`

website/docs/d/core_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ The following arguments are supported:
3131

3232
The following attributes are exported:
3333

34+
* `agent_config` -
35+
* `is_monitoring_disabled` - Whether the agent running on the instance can gather performance metrics and monitor the instance.
3436
* `availability_domain` - The availability domain the instance is running in. Example: `Uocm:PHX-AD-1`
3537
* `boot_volume_id` - The OCID of the attached boot volume. If the `source_type` is `bootVolume`, this will be the same OCID as the `source_id`.
3638
* `compartment_id` - The OCID of the compartment that contains the instance.

website/docs/d/core_instances.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ The following attributes are exported:
4848

4949
The following attributes are exported:
5050

51-
* `availability_domain` - The availability domain the instance is running in. Example: `Uocm:PHX-AD-1`
51+
* `agent_config` -
52+
* `is_monitoring_disabled` - Whether the agent running on the instance can gather performance metrics and monitor the instance.
53+
* `availability_domain` - The availability domain the instance is running in. Example: `Uocm:PHX-AD-1`
5254
* `boot_volume_id` - The OCID of the attached boot volume. If the `source_type` is `bootVolume`, this will be the same OCID as the `source_id`.
5355
* `compartment_id` - The OCID of the compartment that contains the instance.
5456
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`

website/docs/r/core_image.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Any change to a property that does not support update will force the destruction
129129

130130
The following attributes are exported:
131131

132+
* `agent_features` -
133+
* `is_monitoring_supported` - Whether the agent running on the instance can gather performance metrics and monitor the instance.
132134
* `base_image_id` - The OCID of the image originally used to launch the instance.
133135
* `compartment_id` - The OCID of the compartment containing the instance you want to use as the basis for the image.
134136
* `create_image_allowed` - Whether instances launched with this image can be used to create new images. For example, you cannot create an image of an Oracle Database instance. Example: `true`

0 commit comments

Comments
 (0)