Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datadog_integration_aws] Properly handle missing resource when importing #1657

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions datadog/resource_datadog_integration_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,16 @@ func resourceDatadogIntegrationAwsDelete(ctx context.Context, d *schema.Resource
}

func resourceDatadogIntegrationAwsImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
originalId := d.Id()
if diagErr := resourceDatadogIntegrationAwsRead(ctx, d, meta); diagErr != nil {
return nil, fmt.Errorf(diagErr[0].Summary)
}

// We can assume resource was not found for import when `id` is set to nil in the read step
if d.Id() == "" {
return nil, fmt.Errorf("error importing aws integration resource. Resource with id `%s` does not exist", originalId)
}

d.Set("external_id", os.Getenv("EXTERNAL_ID"))
return []*schema.ResourceData{d}, nil
}