Skip to content

Commit

Permalink
WIP moar work
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Feb 6, 2024
1 parent 1c3f922 commit 5f859e4
Show file tree
Hide file tree
Showing 148 changed files with 2,348 additions and 1,641 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ require (

go 1.21

replace github.com/hashicorp/go-azure-sdk/sdk => /Users/tom/git/hashicorp/go-azure-sdk/sdk
replace github.com/hashicorp/go-azure-sdk/sdk => /Users/tom/git/hashicorp/go-azure-sdk/sdk
replace github.com/tombuildsstuff/giovanni => /Users/tom/git/tombuildsstuff/giovanni
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (r ArcKubernetesFluxConfigurationResource) Arguments() map[string]*pluginsd
"container_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: storageValidate.StorageContainerDataPlaneID,
ValidateFunc: storageValidate.StorageContainerDataPlaneIDForDomainSuffix(""), // TODO need to know the storage domain suffix at schema time!
},

"account_key": {
Expand Down Expand Up @@ -570,7 +570,7 @@ func (r ArcKubernetesFluxConfigurationResource) Create() sdk.ResourceFunc {
properties.Properties.Bucket, properties.Properties.ConfigurationProtectedSettings = expandBucketDefinitionModel(model.Bucket)
} else if _, exists = metadata.ResourceData.GetOk("blob_storage"); exists {
properties.Properties.SourceKind = pointer.To(fluxconfiguration.SourceKindTypeAzureBlob)
azureBlob, err := expandArcAzureBlobDefinitionModel(model.BlobStorage)
azureBlob, err := expandArcAzureBlobDefinitionModel(model.BlobStorage, metadata.Client.Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("expanding `blob_storage`: %+v", err)
}
Expand Down Expand Up @@ -624,7 +624,7 @@ func (r ArcKubernetesFluxConfigurationResource) Update() sdk.ResourceFunc {

properties.Properties.ConfigurationProtectedSettings = nil
if metadata.ResourceData.HasChange("blob_storage") {
azureBlob, err := expandArcAzureBlobDefinitionModel(model.BlobStorage)
azureBlob, err := expandArcAzureBlobDefinitionModel(model.BlobStorage, metadata.Client.Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("expanding `blob_storage`: %+v", err)
}
Expand Down Expand Up @@ -717,7 +717,7 @@ func (r ArcKubernetesFluxConfigurationResource) Read() sdk.ResourceFunc {

if model := resp.Model; model != nil {
if properties := model.Properties; properties != nil {
blobStorage, err := flattenArcAzureBlobDefinitionModel(properties.AzureBlob, configModel.BlobStorage)
blobStorage, err := flattenArcAzureBlobDefinitionModel(properties.AzureBlob, configModel.BlobStorage, metadata.Client.Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("flattening `blob_storage`: %+v", err)
}
Expand Down Expand Up @@ -762,7 +762,7 @@ func (r ArcKubernetesFluxConfigurationResource) Delete() sdk.ResourceFunc {
}
}

func expandArcAzureBlobDefinitionModel(inputList []AzureBlobDefinitionModel) (*fluxconfiguration.AzureBlobDefinition, error) {
func expandArcAzureBlobDefinitionModel(inputList []AzureBlobDefinitionModel, storageDomainSuffix string) (*fluxconfiguration.AzureBlobDefinition, error) {
if len(inputList) == 0 {
return nil, nil
}
Expand All @@ -778,7 +778,7 @@ func expandArcAzureBlobDefinitionModel(inputList []AzureBlobDefinitionModel) (*f
}

if input.ContainerID != "" {
id, err := parse.StorageContainerDataPlaneID(input.ContainerID)
id, err := parse.StorageContainerDataPlaneID(input.ContainerID, storageDomainSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -969,13 +969,13 @@ func expandRepositoryRefDefinitionModel(referenceType string, referenceValue str
return &output, nil
}

func flattenArcAzureBlobDefinitionModel(input *fluxconfiguration.AzureBlobDefinition, azureBlob []AzureBlobDefinitionModel) ([]AzureBlobDefinitionModel, error) {
func flattenArcAzureBlobDefinitionModel(input *fluxconfiguration.AzureBlobDefinition, azureBlob []AzureBlobDefinitionModel, storageDomainSuffix string) ([]AzureBlobDefinitionModel, error) {
outputList := make([]AzureBlobDefinitionModel, 0)
if input == nil {
return outputList, nil
}

id, err := parse.StorageContainerDataPlaneID(fmt.Sprintf("%s/%s", pointer.From(input.Url), pointer.From(input.ContainerName)))
id, err := parse.StorageContainerDataPlaneID(fmt.Sprintf("%s/%s", pointer.From(input.Url), pointer.From(input.ContainerName)), storageDomainSuffix)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (r KubernetesFluxConfigurationResource) Arguments() map[string]*pluginsdk.S
"container_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: storageValidate.StorageContainerDataPlaneID,
ValidateFunc: storageValidate.StorageContainerDataPlaneIDForDomainSuffix(""), // TODO need to know the storage domain suffix at schema time!
},

"account_key": {
Expand Down Expand Up @@ -589,7 +589,7 @@ func (r KubernetesFluxConfigurationResource) Create() sdk.ResourceFunc {
properties.Properties.Bucket, properties.Properties.ConfigurationProtectedSettings = expandBucketDefinitionModel(model.Bucket)
} else if _, exists = metadata.ResourceData.GetOk("blob_storage"); exists {
properties.Properties.SourceKind = pointer.To(fluxconfiguration.SourceKindTypeAzureBlob)
azureBlob, err := expandAzureBlobDefinitionModel(model.BlobStorage)
azureBlob, err := expandAzureBlobDefinitionModel(model.BlobStorage, metadata.Client.Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("expanding `blob_storage`: %+v", err)
}
Expand Down Expand Up @@ -643,7 +643,7 @@ func (r KubernetesFluxConfigurationResource) Update() sdk.ResourceFunc {

properties.Properties.ConfigurationProtectedSettings = nil
if metadata.ResourceData.HasChange("blob_storage") {
azureBlob, err := expandAzureBlobDefinitionModel(model.BlobStorage)
azureBlob, err := expandAzureBlobDefinitionModel(model.BlobStorage, metadata.Client.Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("expanding `blob_storage`: %+v", err)
}
Expand Down Expand Up @@ -735,7 +735,7 @@ func (r KubernetesFluxConfigurationResource) Read() sdk.ResourceFunc {

if model := resp.Model; model != nil {
if properties := model.Properties; properties != nil {
blobStorage, err := flattenAzureBlobDefinitionModel(properties.AzureBlob, configModel.BlobStorage)
blobStorage, err := flattenAzureBlobDefinitionModel(properties.AzureBlob, configModel.BlobStorage, metadata.Client.Storage.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("flattening `blob_storage`: %+v", err)
}
Expand Down Expand Up @@ -780,7 +780,7 @@ func (r KubernetesFluxConfigurationResource) Delete() sdk.ResourceFunc {
}
}

func expandAzureBlobDefinitionModel(inputList []AzureBlobDefinitionModel) (*fluxconfiguration.AzureBlobDefinition, error) {
func expandAzureBlobDefinitionModel(inputList []AzureBlobDefinitionModel, storageDomainSuffix string) (*fluxconfiguration.AzureBlobDefinition, error) {
if len(inputList) == 0 {
return nil, nil
}
Expand All @@ -797,7 +797,7 @@ func expandAzureBlobDefinitionModel(inputList []AzureBlobDefinitionModel) (*flux
}

if input.ContainerID != "" {
id, err := parse.StorageContainerDataPlaneID(input.ContainerID)
id, err := parse.StorageContainerDataPlaneID(input.ContainerID, storageDomainSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1002,13 +1002,13 @@ func expandRepositoryRefDefinitionModel(referenceType string, referenceValue str
return &output, nil
}

func flattenAzureBlobDefinitionModel(input *fluxconfiguration.AzureBlobDefinition, azureBlob []AzureBlobDefinitionModel) ([]AzureBlobDefinitionModel, error) {
func flattenAzureBlobDefinitionModel(input *fluxconfiguration.AzureBlobDefinition, azureBlob []AzureBlobDefinitionModel, storageDomainSuffix string) ([]AzureBlobDefinitionModel, error) {
outputList := make([]AzureBlobDefinitionModel, 0)
if input == nil {
return outputList, nil
}

id, err := parse.StorageContainerDataPlaneID(fmt.Sprintf("%s/%s", pointer.From(input.Url), pointer.From(input.ContainerName)))
id, err := parse.StorageContainerDataPlaneID(fmt.Sprintf("%s/%s", pointer.From(input.Url), pointer.From(input.ContainerName)), storageDomainSuffix)
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions internal/services/legacy/virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/blob/blobs"
"github.com/tombuildsstuff/giovanni/storage/2023-11-03/blob/blobs"
"github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute"
"github.com/tombuildsstuff/kermit/sdk/network/2022-07-01/network"
)
Expand Down Expand Up @@ -1033,33 +1033,33 @@ func resourceVirtualMachineDeleteVhd(ctx context.Context, storageClient *intStor
}

uri := *vhd.URI
id, err := blobs.ParseResourceID(uri)
id, err := blobs.ParseBlobID(uri, storageClient.StorageDomainSuffix)
if err != nil {
return fmt.Errorf("parsing %q: %s", uri, err)
}

account, err := storageClient.FindAccount(ctx, id.AccountName)
account, err := storageClient.FindAccount(ctx, id.AccountId.AccountName)
if err != nil {
return fmt.Errorf("retrieving Account %q for Blob %q (Container %q): %s", id.AccountName, id.BlobName, id.ContainerName, err)
return fmt.Errorf("retrieving Account %q for Blob %q (Container %q): %s", id.AccountId.AccountName, id.BlobName, id.ContainerName, err)
}
if account == nil {
return fmt.Errorf("Unable to locate Storage Account %q (Disk %q)!", id.AccountName, uri)
return fmt.Errorf("Unable to locate Storage Account %q (Disk %q)!", id.AccountId.AccountName, uri)
}

if err != nil {
return fmt.Errorf("building Blobs Client: %s", err)
}

blobsClient, err := storageClient.BlobsClient(ctx, *account)
blobsClient, err := storageClient.BlobsDataPlaneClient(ctx, *account)
if err != nil {
return fmt.Errorf("building Blobs Client: %s", err)
}

input := blobs.DeleteInput{
DeleteSnapshots: false,
}
if _, err := blobsClient.Delete(ctx, id.AccountName, id.ContainerName, id.BlobName, input); err != nil {
return fmt.Errorf("deleting Blob %q (Container %q / Account %q / Resource Group %q): %s", id.BlobName, id.ContainerName, id.AccountName, account.ResourceGroup, err)
if _, err := blobsClient.Delete(ctx, id.ContainerName, id.BlobName, input); err != nil {
return fmt.Errorf("deleting Blob %q (Container %q / Account %q / Resource Group %q): %s", id.BlobName, id.ContainerName, id.AccountId.AccountName, account.ResourceGroup, err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/services/legacy/virtual_machine_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (VirtualMachineResource) unmanagedDiskExistsInContainer(blobName string, sh
return fmt.Errorf("Unable to locate Storage Account %q!", accountName)
}

client, err := clients.Storage.BlobsClient(ctx, *account)
client, err := clients.Storage.BlobsDataPlaneClient(ctx, *account)
if err != nil {
return fmt.Errorf("building Blobs Client: %s", err)
}
Expand Down
Loading

0 comments on commit 5f859e4

Please sign in to comment.