Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.65k stars 844 forks source link

[DataFactory] RepoConfiguration validation failure #2445

Closed hbuckle closed 6 years ago

hbuckle commented 6 years ago

Bug Report

Trying to create a data factory with a repo configuration produces the following error

accountName := "xxx"
collaborationBranch := "master"
projectName := "dftest"
repositoryName := "dftest"
rootFolder := "/"
tenantID := "xxx"
location := "northeurope"

dataFactory := datafactory.Factory{
    Location: &location,
    FactoryProperties: &datafactory.FactoryProperties{
        RepoConfiguration: datafactory.FactoryVSTSConfiguration{
            AccountName:         &accountName,
            CollaborationBranch: &collaborationBranch,
            ProjectName:         &projectName,
            RepositoryName:      &repositoryName,
            RootFolder:          &rootFolder,
            TenantID:            &tenantID,
        },
    },
}

_, err := client.CreateOrUpdate(ctx, resourceGroup, name, dataFactory, "")
if err != nil {
    return err
}
azurerm_data_factory.data_factory: datafactory.FactoriesClient#CreateOrUpdate: Invalid input: autorest/validation: validation failed: parameter=factory.FactoryProperties.RepoConfiguration constraint=Null value=datafactory.FactoryVSTSConfiguration{ProjectName:(*string)(0xc042078750), TenantID:(*string)(0xc042078780), AccountName:(*string)(0xc042078720), RepositoryName:(*string)(0xc042078760), CollaborationBranch:(*string)(0xc042078730), RootFolder:(*string)(0xc042078770), LastCommitID:(*string)(nil), Type:""} details: field "factory.FactoryProperties.RepoConfiguration" doesn't exist

If I remove the factory.FactoryProperties.RepoConfiguration validation from CreateOrUpdate then the factory is created succesfully

marstr commented 6 years ago

Created an executable repro here: https://gist.github.com/marstr/943cded4740104dd3a9747090bc6622c

marstr commented 6 years ago

@hbuckle, thanks for filing this. You definitely found a rough edge we should grind down.

By updating your RepoConfiguration to be a pointer as so:

RepoConfiguration: &datafactory.FactoryVSTSConfiguration{

What's tripping things up is that the methods AsFactoryVSTSConfiguration, AsFactoryGitHubConfiguration, and AsFactoryRepoConfiguration found here, are dangled off of FactoryVSTSConfiguration instead of type *FactoryVSTSConfiguration. This means that our validation checks to see if something non-nil-able is nil, causing this failure.

I'm going to open a generic issue that mentions this problem, and credit you for finding it. But I'll close this issue out since we have a simple work-around.