Skip to content

Commit

Permalink
Fixed #541
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinhard-Pilz-Dynatrace committed Sep 30, 2024
1 parent 98514e6 commit 52c4a36
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions dynatrace/api/v1/config/credentials/aws/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (me *service) Create(ctx context.Context, v *services.Settings) (*api.Stub,
if err = me.client.Put(fmt.Sprintf("/api/config/v1/aws/credentials/%s/services", credentialsID), response).Expect(204).Finish(); err != nil {
r := regexp.MustCompile(`Invalid\sservices\sconfiguration\:\srecommended\smetrics\s\[([^\]]*)\]\sfor\sservice\s'([^']*)'\smust\sbe\sselected`)
r2 := regexp.MustCompile(`Invalid\sservices\sconfiguration\:\smetric\s'([^']*)'\sfor\sservice\s'([^']*)'\shas\smissing\sdimension\s\[([^\]]*)\],\suse\sall\srecommended\sdimensions\s\[([^\]]*)\]`)
r3 := regexp.MustCompile("Invalid services configuration: you can't have (.*) and (.*) services turned on simultaneously")
if m := r.FindStringSubmatch(err.Error()); m != nil {
var service *services.Settings
for _, service = range response.Services {
Expand Down Expand Up @@ -192,6 +193,43 @@ func (me *service) Create(ctx context.Context, v *services.Settings) (*api.Stub,
metric.Dimensions = append(metric.Dimensions, k)
}
v.MonitoredMetrics = service.MonitoredMetrics
} else if m := r3.FindStringSubmatch(err.Error()); len(m) == 3 {
// Example:
// Invalid services configuration: you can't have lambda and lambda_builtin services turned on simultaneously
builtin_service := ""
if strings.HasSuffix(m[1], "_builtin") {
builtin_service = m[1]
if strings.HasSuffix(m[2], "_builtin") {
// if both services mentioned within the error messages are
// apparently "builtin" we don't know which one to axe
return nil, err
}
} else if strings.HasSuffix(m[2], "_builtin") {
builtin_service = m[2]
}
// if neither of the two services mentioned within the error message is "builtin"
// (i.e. its name ends with "_builtin") we don't know which one to axe
if len(builtin_service) == 0 {
return nil, err
}
// rebuilding the payloads "Services" property
// all entries except the one where the "name" matches the service to remove
// will remain
var newServices []*services.Settings
removedOneEntry := false
for _, entry := range response.Services {
if entry.Name != builtin_service {
newServices = append(newServices, entry)
} else {
removedOneEntry = true
}
}
// sanity check - did we ACTUALLY remove something from the payload?
if !removedOneEntry {
return nil, err
}
// re-assigning reduced slice to payload
response.Services = newServices
} else {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (awscc *AWSCredentialsConfig) Schema() map[string]*schema.Schema {
},
"remove_defaults": {
Type: schema.TypeBool,
Description: "Instructs the provider to remove the supporting services Dynatrace applies by default to newly created AWS Credentials. Supporting Services applied by via `dynatrace_aws_service` subsequently won't get touched.",
Description: "Instructs the provider to remove the supporting services Dynatrace applies by default to newly created AWS Credentials. Supporting Services applied by via `dynatrace_aws_service` subsequently won't get touched.\nNote: This attribute is only getting considered during creation of the resource. Changing it afterwards won't have an effect",
Optional: true,
Default: false,
},
Expand Down

0 comments on commit 52c4a36

Please sign in to comment.