Skip to content

Commit

Permalink
Do not return on d.Set() errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-silvas committed Mar 27, 2024
1 parent 674a4d3 commit e31d87b
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 139 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.0
v1.0.1
3 changes: 2 additions & 1 deletion internal/awx/data_source_credential_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package awx

import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -88,7 +89,7 @@ func dataSourceCredentialMachineRoleRead(ctx context.Context, d *schema.Resource

func setCredentialRoleData(d *schema.ResourceData, r *awx.ApplyRole) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
d.SetId(strconv.Itoa(r.ID))
return d
Expand Down
3 changes: 2 additions & 1 deletion internal/awx/data_source_inventory_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package awx

import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -88,7 +89,7 @@ func dataSourceInventoryRoleRead(ctx context.Context, d *schema.ResourceData, m

func setInventoryRoleData(d *schema.ResourceData, r *awx.ApplyRole) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
d.SetId(strconv.Itoa(r.ID))
return d
Expand Down
3 changes: 2 additions & 1 deletion internal/awx/data_source_job_template_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package awx

import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -88,7 +89,7 @@ func dataSourceJobTemplateRoleRead(ctx context.Context, d *schema.ResourceData,

func setJobTemplateRoleData(d *schema.ResourceData, r *awx.ApplyRole) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
d.SetId(strconv.Itoa(r.ID))
return d
Expand Down
3 changes: 2 additions & 1 deletion internal/awx/data_source_organization_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package awx

import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -98,7 +99,7 @@ func dataSourceOrganizationRolesRead(ctx context.Context, d *schema.ResourceData

func setOrganizationRoleData(d *schema.ResourceData, r *awx.ApplyRole) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
d.SetId(strconv.Itoa(r.ID))
return d
Expand Down
3 changes: 2 additions & 1 deletion internal/awx/data_source_project_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package awx

import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -87,7 +88,7 @@ func dataSourceProjectRolesRead(ctx context.Context, d *schema.ResourceData, m i

func setProjectRoleData(d *schema.ResourceData, r *awx.ApplyRole) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
d.SetId(strconv.Itoa(r.ID))
return d
Expand Down
10 changes: 5 additions & 5 deletions internal/awx/resource_execution_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ func resourceExecutionEnvironmentsDelete(ctx context.Context, d *schema.Resource

func setExecutionEnvironmentsResourceData(d *schema.ResourceData, r *awx.ExecutionEnvironment) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
if err := d.Set("image", r.Image); err != nil {
return d
fmt.Println("Error setting image", err)
}
if err := d.Set("description", r.Description); err != nil {
return d
fmt.Println("Error setting description", err)
}
if err := d.Set("organization", r.Organization); err != nil {
return d
fmt.Println("Error setting organization", err)
}
if err := d.Set("credential", r.Credential); err != nil {
return d
fmt.Println("Error setting credential", err)
}
d.SetId(strconv.Itoa(r.ID))
return d
Expand Down
14 changes: 7 additions & 7 deletions internal/awx/resource_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,25 @@ func resourceHostDelete(ctx context.Context, d *schema.ResourceData, m interface

func setHostResourceData(d *schema.ResourceData, r *awx.Host) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
if err := d.Set("description", r.Description); err != nil {
return d
fmt.Println("Error setting description", err)
}
if err := d.Set("inventory_id", r.Inventory); err != nil {
return d
fmt.Println("Error setting inventory_id", err)
}
if err := d.Set("enabled", r.Enabled); err != nil {
return d
fmt.Println("Error setting enabled", err)
}
if err := d.Set("instance_id", r.InstanceID); err != nil {
return d
fmt.Println("Error setting instance_id", err)
}
if err := d.Set("variables", normalizeJsonYaml(r.Variables)); err != nil {
return d
fmt.Println("Error setting variables", err)
}
if err := d.Set("group_ids", d.Get("group_ids").([]interface{})); err != nil {
return d
fmt.Println("Error setting group_ids", err)
}
return d
}
6 changes: 3 additions & 3 deletions internal/awx/resource_instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ func resourceInstanceGroupRead(ctx context.Context, d *schema.ResourceData, m in

func setInstanceGroupResourceData(d *schema.ResourceData, r *awx.InstanceGroup) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
if err := d.Set("is_container_group", r.IsContainerGroup); err != nil {
return d
fmt.Println("Error setting is_container_group", err)
}
if err := d.Set("pod_spec_override", normalizeJsonYaml(r.PodSpecOverride)); err != nil {
return d
fmt.Println("Error setting pod_spec_override", err)
}

d.SetId(strconv.Itoa(r.ID))
Expand Down
12 changes: 6 additions & 6 deletions internal/awx/resource_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,22 @@ func resourceInventoryDelete(ctx context.Context, d *schema.ResourceData, m inte

func setInventoryResourceData(d *schema.ResourceData, r *awx.Inventory) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
if err := d.Set("organization_id", strconv.Itoa(r.Organization)); err != nil {
return d
fmt.Println("Error setting organization_id", err)
}
if err := d.Set("description", r.Description); err != nil {
return d
fmt.Println("Error setting description", err)
}
if err := d.Set("kind", r.Kind); err != nil {
return d
fmt.Println("Error setting kind", err)
}
if err := d.Set("host_filter", r.HostFilter); err != nil {
return d
fmt.Println("Error setting host_filter", err)
}
if err := d.Set("variables", normalizeJsonYaml(r.Variables)); err != nil {
return d
fmt.Println("Error setting variables", err)
}
d.SetId(strconv.Itoa(r.ID))
return d
Expand Down
8 changes: 4 additions & 4 deletions internal/awx/resource_inventory_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ func resourceInventoryGroupRead(ctx context.Context, d *schema.ResourceData, m i

func setInventoryGroupResourceData(d *schema.ResourceData, r *awx.Group) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
if err := d.Set("description", r.Description); err != nil {
return d
fmt.Println("Error setting description", err)
}
if err := d.Set("inventory_id", r.Inventory); err != nil {
return d
fmt.Println("Error setting inventory_id", err)
}
if err := d.Set("variables", normalizeJsonYaml(r.Variables)); err != nil {
return d
fmt.Println("Error setting variables", err)
}

d.SetId(strconv.Itoa(r.ID))
Expand Down
42 changes: 21 additions & 21 deletions internal/awx/resource_inventory_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,69 +251,69 @@ func resourceInventorySourceRead(ctx context.Context, d *schema.ResourceData, m

func setInventorySourceResourceData(d *schema.ResourceData, r *awx.InventorySource) *schema.ResourceData {
if err := d.Set("name", r.Name); err != nil {
return d
fmt.Println("Error setting name", err)
}
if err := d.Set("description", r.Description); err != nil {
return d
fmt.Println("Error setting description", err)
}
if err := d.Set("enabled_var", r.EnabledVar); err != nil {
return d
fmt.Println("Error setting enabled_var", err)
}
if err := d.Set("enabled_value", r.EnabledValue); err != nil {
return d
fmt.Println("Error setting enabled_value", err)
}
if err := d.Set("overwrite", r.Overwrite); err != nil {
return d
fmt.Println("Error setting overwrite", err)
}
if err := d.Set("overwrite_vars", r.OverwriteVars); err != nil {
return d
fmt.Println("Error setting overwrite_vars", err)
}
if err := d.Set("update_on_launch", r.UpdateOnLaunch); err != nil {
return d
fmt.Println("Error setting update_on_launch", err)
}
if err := d.Set("inventory_id", r.Inventory); err != nil {
return d
fmt.Println("Error setting inventory_id", err)
}
if err := d.Set("credential_id", r.Credential); err != nil {
return d
fmt.Println("Error setting credential_id", err)
}
if err := d.Set("source", r.Source); err != nil {
return d
fmt.Println("Error setting source", err)
}
if err := d.Set("source_vars", normalizeJsonYaml(r.SourceVars)); err != nil {
return d
fmt.Println("Error setting source_vars", err)
}
if err := d.Set("host_filter", r.HostFilter); err != nil {
return d
fmt.Println("Error setting host_filter", err)
}
if err := d.Set("update_cache_timeout", r.UpdateCacheTimeout); err != nil {
return d
fmt.Println("Error setting update_cache_timeout", err)
}
if err := d.Set("verbosity", r.Verbosity); err != nil {
return d
fmt.Println("Error setting verbosity", err)
}
if err := d.Set("source_project_id", r.SourceProject); err != nil {
return d
fmt.Println("Error setting source_project_id", err)
}
if err := d.Set("source_path", r.SourcePath); err != nil {
return d
fmt.Println("Error setting source_path", err)
}
// obsolete schema added so terraform doesn't break
// these don't do anything in later versions of AWX! Update your code.
if err := d.Set("source_regions", r.SourceRegions); err != nil {
return d
fmt.Println("Error setting source_regions", err)
}
if err := d.Set("instance_filters", r.InstanceFilters); err != nil {
return d
fmt.Println("Error setting instance_filters", err)
}
if err := d.Set("group_by", r.GroupBy); err != nil {
return d
fmt.Println("Error setting group_by", err)
}
if err := d.Set("source_project_id", r.SourceProject); err != nil {
return d
fmt.Println("Error setting source_project_id", err)
}
if err := d.Set("source_path", r.SourcePath); err != nil {
return d
fmt.Println("Error setting source_path", err)
}

return d
Expand Down
Loading

0 comments on commit e31d87b

Please sign in to comment.