Skip to content

Commit

Permalink
feat: add new parameter 'ignore_missing' to prevent creating errors i…
Browse files Browse the repository at this point in the history
…f a requested resource does not exist
  • Loading branch information
srevinsaju committed Mar 9, 2024
1 parent 80ce7b1 commit 30236b8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion terraform/data_source_infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func dataSourceInfraRead(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}

if len(metadata) == 0 {
if len(metadata) == 0 && d.Get("ignore_missing").(bool) {
d.SetId(id)
return diags
} else if len(metadata) == 0 {
return diag.FromErr(fmt.Errorf("no resource with id '%s' exists", id))
} else if len(metadata) > 1 {
return diag.FromErr(fmt.Errorf("more than one resource was returned when '%s' id was requested which is not supported yet", id))
Expand Down Expand Up @@ -58,6 +61,11 @@ func dataSourceInfra() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"ignore_missing": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down

0 comments on commit 30236b8

Please sign in to comment.