VSChina / magic-modules

Magic Modules: Automagically generate Google Cloud Platform support for OSS
Apache License 2.0
1 stars 4 forks source link

Incorrect Checking for present of existing resource in `CreateUpdate` function. #57

Closed hund030 closed 4 years ago

hund030 commented 4 years ago

Current:

if features.ShouldResourcesBeImported() && d.IsNewResource() {
    resp, err := client.Get(ctx, resourceGroup, name, "")
    if err != nil {
        if !utils.ResponseWasNotFound(resp.Response) {
            return fmt.Errorf("Error checking for present of existing Private Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err)
        }
    }
    if !utils.ResponseWasNotFound(resp.Response) {
                return tf.ImportAsExistsError("azurerm_private_link_endpoint", *resp.ID)
    }
}

Should be:

if features.ShouldResourcesBeImported() && d.IsNewResource() {
    existing, err := client.Get(ctx, resourceGroup, name, "")
    if err != nil {
        if !utils.ResponseWasNotFound(existing.Response) {
            return fmt.Errorf("Error checking for present of existing Private Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err)
        }
    }
    if existing.ID != nil && *existing.ID != "" {
        return tf.ImportAsExistsError("azurerm_private_link_endpoint", *existing.ID)
    }
}
houkms commented 4 years ago

Expected to be solved in #65