Skip to content

Commit

Permalink
Prevent null bool in filter predicate/require all booleans to be set (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad authored Jan 3, 2024
1 parent fa909d8 commit 6075b40
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 90 deletions.
4 changes: 4 additions & 0 deletions .changes/unreleased/Bugfix-20240103-113615.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Bugfix
body: '[BREAKING CHANGE] require filter predicate case_sensitive bool to prevent bug
where value cannot be set to false'
time: 2024-01-03T11:36:15.475217-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240103-122651.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: '[BREAKING CHANGE] all optional boolean fields are now required'
time: 2024-01-03T12:26:51.595274-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Removed-20240103-122630.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Removed
body: '[BREAKING CHANGE] remove support for skip_welcome_email in User resource'
time: 2024-01-03T12:26:30.593973-05:00
12 changes: 5 additions & 7 deletions opslevel/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,11 @@ func expandFilterPredicates(d *schema.ResourceData) []opslevel.FilterPredicate {
for _, item := range d.Get("predicate").([]interface{}) {
data := item.(map[string]interface{})
predicate := opslevel.FilterPredicate{
Type: opslevel.PredicateTypeEnum(data["type"].(string)),
Value: strings.TrimSpace(data["value"].(string)),
Key: opslevel.PredicateKeyEnum(data["key"].(string)),
KeyData: strings.TrimSpace(data["key_data"].(string)),
}
if caseSensitive, ok := d.GetOk("case_sensitive"); ok {
predicate.CaseSensitive = opslevel.Bool(caseSensitive.(bool))
Type: opslevel.PredicateTypeEnum(data["type"].(string)),
Value: strings.TrimSpace(data["value"].(string)),
Key: opslevel.PredicateKeyEnum(data["key"].(string)),
KeyData: strings.TrimSpace(data["key_data"].(string)),
CaseSensitive: opslevel.Bool(data["case_sensitive"].(bool)),
}
output = append(output, predicate)
}
Expand Down
18 changes: 5 additions & 13 deletions opslevel/resource_opslevel_check_custom_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func resourceCheckCustomEvent() *schema.Resource {
Type: schema.TypeBool,
Description: "True if this check should pass by default. Otherwise the default 'pending' state counts as a failure.",
ForceNew: false,
Optional: true,
Required: true,
},
"service_selector": {
Type: schema.TypeString,
Expand Down Expand Up @@ -55,9 +55,7 @@ func resourceCheckCustomEventCreate(d *schema.ResourceData, client *opslevel.Cli
setCheckCreateInput(d, &input)

input.Integration = *opslevel.NewID(d.Get("integration").(string))
if passPending, ok := d.GetOk("pass_pending"); ok {
input.PassPending = opslevel.Bool(passPending.(bool))
}
input.PassPending = opslevel.Bool(d.Get("pass_pending").(bool))
input.ServiceSelector = d.Get("service_selector").(string)
input.SuccessCondition = d.Get("success_condition").(string)
input.Message = d.Get("message").(string)
Expand Down Expand Up @@ -87,10 +85,8 @@ func resourceCheckCustomEventRead(d *schema.ResourceData, client *opslevel.Clien
return err
}

if _, ok := d.GetOk("pass_pending"); ok {
if err := d.Set("pass_pending", resource.PassPending); err != nil {
return err
}
if err := d.Set("pass_pending", resource.PassPending); err != nil {
return err
}
if _, ok := d.GetOk("service_selector"); ok {
if err := d.Set("service_selector", resource.ServiceSelector); err != nil {
Expand Down Expand Up @@ -118,11 +114,7 @@ func resourceCheckCustomEventUpdate(d *schema.ResourceData, client *opslevel.Cli
if d.HasChange("integration") {
input.Integration = opslevel.NewID(d.Get("integration").(string))
}
if d.HasChange("pass_pending") {
if passPending, ok := d.GetOk("pass_pending"); ok {
input.PassPending = opslevel.Bool(passPending.(bool))
}
}
input.PassPending = opslevel.Bool(d.Get("pass_pending").(bool))
if d.HasChange("service_selector") {
input.ServiceSelector = d.Get("service_selector").(string)
}
Expand Down
4 changes: 1 addition & 3 deletions opslevel/resource_opslevel_check_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ func resourceCheckManualUpdate(d *schema.ResourceData, client *opslevel.Client)
if d.HasChange("update_frequency") {
input.UpdateFrequency = expandUpdateFrequency(d, "update_frequency")
}
if d.HasChange("update_requires_comment") {
input.UpdateRequiresComment = d.Get("update_requires_comment").(bool)
}
input.UpdateRequiresComment = d.Get("update_requires_comment").(bool)

_, err := client.UpdateCheckManual(input)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions opslevel/resource_opslevel_check_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func resourceCheckRepositoryFile() *schema.Resource {
Type: schema.TypeBool,
Description: "Whether the check looks for the existence of a directory instead of a file.",
ForceNew: false,
Optional: true,
Required: true,
},
"filepaths": {
Type: schema.TypeList,
Expand All @@ -37,7 +37,7 @@ func resourceCheckRepositoryFile() *schema.Resource {
Type: schema.TypeBool,
Description: "Whether the checks looks at the absolute root of a repo or the relative root (the directory specified when attached a repo to a service).",
ForceNew: false,
Optional: true,
Required: true,
},
}),
}
Expand Down
8 changes: 3 additions & 5 deletions opslevel/resource_opslevel_check_repository_grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func resourceCheckRepositoryGrep() *schema.Resource {
Schema: getCheckSchema(map[string]*schema.Schema{
"directory_search": {
Type: schema.TypeBool,
Description: "Whether the check looks for the existence of a directory instead of a file. Defaults to false",
Description: "Whether the check looks for the existence of a directory instead of a file.",
ForceNew: false,
Optional: true,
Required: true,
},
"filepaths": {
Type: schema.TypeList,
Expand Down Expand Up @@ -92,9 +92,7 @@ func resourceCheckRepositoryGrepUpdate(d *schema.ResourceData, client *opslevel.
input := opslevel.CheckRepositoryGrepUpdateInput{}
setCheckUpdateInput(d, &input)

if d.HasChange("directory_search") {
input.DirectorySearch = d.Get("directory_search").(bool)
}
input.DirectorySearch = d.Get("directory_search").(bool)

if d.HasChange("filepaths") {
input.Filepaths = getStringArray(d, "filepaths")
Expand Down
16 changes: 5 additions & 11 deletions opslevel/resource_opslevel_check_service_ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func resourceCheckServiceOwnership() *schema.Resource {
Type: schema.TypeBool,
Description: "True if a service's owner must have a contact method, False otherwise.",
ForceNew: false,
Optional: true,
Required: true,
},
"contact_method": {
Type: schema.TypeString,
Expand All @@ -45,9 +45,7 @@ func resourceCheckServiceOwnershipCreate(d *schema.ResourceData, client *opsleve
input := opslevel.CheckServiceOwnershipCreateInput{}
setCheckCreateInput(d, &input)

if requireContactMethod, ok := d.GetOk("require_contact_method"); ok {
input.RequireContactMethod = opslevel.Bool(requireContactMethod.(bool))
}
input.RequireContactMethod = opslevel.Bool(d.Get("require_contact_method").(bool))
if value, ok := d.GetOk("contact_method"); ok {
contactMethod := opslevel.ContactType(value.(string))
input.ContactMethod = &contactMethod
Expand Down Expand Up @@ -79,10 +77,8 @@ func resourceCheckServiceOwnershipRead(d *schema.ResourceData, client *opslevel.
return err
}

if _, ok := d.GetOk("require_contact_method"); ok {
if err := d.Set("require_contact_method", resource.RequireContactMethod); err != nil {
return err
}
if err := d.Set("require_contact_method", resource.RequireContactMethod); err != nil {
return err
}

if _, ok := d.GetOk("contact_method"); ok {
Expand All @@ -109,9 +105,7 @@ func resourceCheckServiceOwnershipUpdate(d *schema.ResourceData, client *opsleve
input := opslevel.CheckServiceOwnershipUpdateInput{}
setCheckUpdateInput(d, &input)

if d.HasChange("require_contact_method") {
input.RequireContactMethod = opslevel.Bool(d.Get("require_contact_method").(bool))
}
input.RequireContactMethod = opslevel.Bool(d.Get("require_contact_method").(bool))

if d.HasChange("contact_method") {
contactMethod := opslevel.ContactType(d.Get("contact_method").(string))
Expand Down
2 changes: 1 addition & 1 deletion opslevel/resource_opslevel_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func resourceFilter() *schema.Resource {
Type: schema.TypeBool,
Description: "Option for determining whether to compare strings case-sensitively.\n\n",
ForceNew: false,
Optional: true,
Required: true,
},
},
},
Expand Down
30 changes: 11 additions & 19 deletions opslevel/resource_opslevel_integration_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func resourceIntegrationAWS() *schema.Resource {
Type: schema.TypeBool,
Description: "Allow tags imported from AWS to override ownership set in OpsLevel directly.",
ForceNew: false,
Optional: true,
Required: true,
},
"ownership_tag_keys": {
Type: schema.TypeList,
Expand All @@ -58,15 +58,12 @@ func resourceIntegrationAWS() *schema.Resource {

func resourceIntegrationAWSCreate(d *schema.ResourceData, client *opslevel.Client) error {
input := opslevel.AWSIntegrationInput{
Name: opslevel.NewString(d.Get("name").(string)),
IAMRole: opslevel.NewString(d.Get("iam_role").(string)),
ExternalID: opslevel.NewString(d.Get("external_id").(string)),
Name: opslevel.NewString(d.Get("name").(string)),
IAMRole: opslevel.NewString(d.Get("iam_role").(string)),
ExternalID: opslevel.NewString(d.Get("external_id").(string)),
OwnershipTagOverride: opslevel.Bool(d.Get("ownership_tag_overrides").(bool)),
}

if value, ok := d.GetOk("ownership_tag_overrides"); ok {
casted := value.(bool)
input.OwnershipTagOverride = &casted
}
input.OwnershipTagKeys = getStringArray(d, "ownership_tag_keys")

resource, err := client.CreateIntegrationAWS(input)
Expand All @@ -92,10 +89,8 @@ func resourceIntegrationAWSRead(d *schema.ResourceData, client *opslevel.Client)
if err := d.Set("external_id", resource.ExternalID); err != nil {
return err
}
if _, ok := d.GetOk("ownership_tag_overrides"); ok {
if err := d.Set("ownership_tag_overrides", resource.OwnershipTagOverride); err != nil {
return err
}
if err := d.Set("ownership_tag_overrides", resource.OwnershipTagOverride); err != nil {
return err
}
if _, ok := d.GetOk("ownership_tag_keys"); ok {
if err := d.Set("ownership_tag_keys", resource.OwnershipTagKeys); err != nil {
Expand All @@ -108,15 +103,12 @@ func resourceIntegrationAWSRead(d *schema.ResourceData, client *opslevel.Client)

func resourceIntegrationAWSUpdate(d *schema.ResourceData, client *opslevel.Client) error {
input := opslevel.AWSIntegrationInput{
Name: opslevel.NewString(d.Get("name").(string)),
IAMRole: opslevel.NewString(d.Get("iam_role").(string)),
ExternalID: opslevel.NewString(d.Get("external_id").(string)),
Name: opslevel.NewString(d.Get("name").(string)),
IAMRole: opslevel.NewString(d.Get("iam_role").(string)),
ExternalID: opslevel.NewString(d.Get("external_id").(string)),
OwnershipTagOverride: opslevel.Bool(d.Get("ownership_tag_overrides").(bool)),
}

if value, ok := d.GetOk("ownership_tag_overrides"); ok {
casted := value.(bool)
input.OwnershipTagOverride = &casted
}
input.OwnershipTagKeys = getStringArray(d, "ownership_tag_keys")

_, err := client.UpdateIntegrationAWS(d.Id(), input)
Expand Down
18 changes: 4 additions & 14 deletions opslevel/resource_opslevel_trigger_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ func resourceTriggerDefinition() *schema.Resource {
},
"published": {
Type: schema.TypeBool,
Description: "The published state of the Custom Action; true if the Trigger Definition is ready for use; false if it is a draft. Defaults to false.",
Default: false,
Description: "The published state of the Custom Action; true if the Trigger Definition is ready for use; false if it is a draft.",
ForceNew: false,
Optional: true,
Required: true,
},
"access_control": {
Type: schema.TypeString,
Expand Down Expand Up @@ -121,9 +120,7 @@ func resourceTriggerDefinitionCreate(d *schema.ResourceData, client *opslevel.Cl
input.ResponseTemplate = responseTemplate
}

if published, ok := d.GetOk("published"); ok {
input.Published = opslevel.Bool(published.(bool))
}
input.Published = opslevel.Bool(d.Get("published").(bool))

if _, ok := d.GetOk("entity_type"); ok {
entityType := d.Get("entity_type").(string)
Expand Down Expand Up @@ -220,14 +217,7 @@ func resourceTriggerDefinitionUpdate(d *schema.ResourceData, client *opslevel.Cl
input.Filter = opslevel.NewID(d.Get("filter").(string))
}

if d.HasChange("published") {
published, ok := d.GetOk("published")
if ok {
input.Published = opslevel.Bool(published.(bool))
} else {
input.Published = opslevel.Bool(false)
}
}
input.Published = opslevel.Bool(d.Get("published").(bool))

if d.HasChange("access_control") {
input.AccessControl = opslevel.CustomActionsTriggerDefinitionAccessControlEnum(d.Get("access_control").(string))
Expand Down
12 changes: 2 additions & 10 deletions opslevel/resource_opslevel_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,15 @@ func resourceUser() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringInSlice(opslevel.AllUserRole, false),
},
"skip_welcome_email": {
Type: schema.TypeBool,
Description: "Don't send an email welcoming the user to OpsLevel.",
Default: false,
ForceNew: false,
Optional: true,
},
},
}
}

func resourceUserCreate(d *schema.ResourceData, client *opslevel.Client) error {
email := d.Get("email").(string)
input := opslevel.UserInput{
Name: d.Get("name").(string),
Role: opslevel.UserRole(d.Get("role").(string)),
SkipWelcomeEmail: d.Get("skip_welcome_email").(bool),
Name: d.Get("name").(string),
Role: opslevel.UserRole(d.Get("role").(string)),
}
resource, err := client.InviteUser(email, input)
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions opslevel/schema_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getCheckSchema(extras map[string]*schema.Schema) map[string]*schema.Schema
Type: schema.TypeBool,
Description: `Whether the check is enabled or not. Do not use this field in tandem with 'enable_on'.`,
ForceNew: false,
Optional: true,
Required: true,
},
"enable_on": {
Type: schema.TypeString,
Expand Down Expand Up @@ -126,10 +126,7 @@ func setCheckUpdateInput(d *schema.ResourceData, p opslevel.CheckUpdateInputProv
if d.HasChange("name") {
input.Name = d.Get("name").(string)
}
if d.HasChange("enabled") {
value := d.Get("enabled").(bool)
input.Enabled = &value
}
input.Enabled = opslevel.Bool(d.Get("enabled").(bool))
if d.HasChange("enable_on") {
enable_on := opslevel.NewISO8601Date(d.Get("enable_on").(string))
input.EnableOn = &enable_on
Expand Down

0 comments on commit 6075b40

Please sign in to comment.