2 years ago

#58223

test-img

Alex Kuzminov

How can I use both resource.RetryError and diag.Diagnostics when developing a TF Provider Plugin SDK v2?

Context: I'm developing a TF Provider Plugin SDK v2.

Recently I've found this doc that describes how to setup retries but it uses just error as a return type vs recommended diag.Diagnostics.

How can I use those 2 together? So far I'm thinking I could use:

func resourceFooCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

    var diags diag.Diagnostics
    client := m.(*Client)

    // read params

    err := resource.RetryContext(ctx, ..., func() *resource.RetryError {
        resp, err := client.CreateFoo(params)
        if err != nil {
            switch err.(type) {
            case ServerError || 429Error:
                return resource.RetryableError(err)
            default:
                return resource.NonRetryableError(err)
            }
        }
        return nil
    })
    return diag.FromErr(err)
}

Did I get it right?

terraform

terraform0.12+

0 Answers

Your Answer

Accepted video resources