DimensionDataResearch / terraform-provider-ddcloud

Terraform provider for Dimension Data cloud compute.
MIT License
16 stars 13 forks source link

How to get tags #134

Open oidz1234 opened 5 years ago

oidz1234 commented 5 years ago

Hello,

I am trying to edit the resource_server.go file to skip server backup if a certain tag is set. This is because if your DD cloud instance does not support backups then terraform fails.

MY questions is is how to I actually read the tags, I have tried many things but the closest I have gotten is:

tags := data.Get(resourceKeyTag) 

This does not seem to work.

Can anyone help me or point me in the right direction ?

Thanks very much :)

hasanhakkaev commented 5 years ago

Hi,

I had the same issue.I fixed it by adding OS names to "readServerBackupClientDownloadURLs" function. Tags would work also, but I just wanted it to work, didn't care about rest.See below for my kind of solution for this:

// Capture summary information for server backup. func readServerBackupClientDownloadURLs(serverID string, data schema.ResourceData, apiClient compute.Client) error { log.Printf("Read backup details for server '%s'.", serverID)

// Skip backup details as backup is not supported in appliances, a.k.a. otherunix.
os := strings.ToUpper(data.Get(resourceKeyServerOSType).(string))

if strings.Contains(os, "OTHER") || strings.Contains(os, "UN") || strings.Contains(os, "WIN") || strings.Contains(os, "LIN") || strings.Contains(os, "CEN") || os == "" {
    log.Printf("Backup is not supported for server '%s'.", serverID)
    data.Set(resourceKeyServerBackupEnabled, false)
    data.Set(resourceKeyServerBackupClientDownloadURLs, nil)
    return nil
}

backupDetails, err := apiClient.GetServerBackupDetails(serverID)

if err != nil {
    return err
}
if backupDetails == nil {
    log.Printf("Backup is not enabled for server '%s'.", serverID)

    data.Set(resourceKeyServerBackupEnabled, false)
    data.Set(resourceKeyServerBackupClientDownloadURLs, nil)

    return nil
}

data.Set(resourceKeyServerBackupEnabled, true)

clientDownloadURLs := make(map[string]interface{})
for _, clientDetail := range backupDetails.Clients {
    clientType := strings.Replace(clientDetail.Type, ".", "_", -1)
    clientDownloadURLs[clientType] = clientDetail.DownloadURL
}
data.Set(resourceKeyServerBackupClientDownloadURLs, clientDownloadURLs)

return nil

}

oidz1234 commented 5 years ago

Thanks, that is actually my current work around as well ! I was more looking for something that was configurable and then could be added to extend the current program.