Skip to content

Commit

Permalink
d/virtual_cluster, r/virtual_cluster: Migrate to AWS SDK v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattburgess committed Jul 11, 2024
1 parent 9abd10a commit d2901cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
48 changes: 21 additions & 27 deletions internal/service/emrcontainers/virtual_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/emrcontainers"
awstypes "github.com/aws/aws-sdk-go-v2/service/emrcontainers/types"
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -89,10 +88,10 @@ func ResourceVirtualCluster() *schema.Resource {
},
},
names.AttrType: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: enum.Validate[awstypes.ContainerProviderType](),
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateDiagFunc: enum.Validate[awstypes.ContainerProviderType](),
},
},
},
Expand Down Expand Up @@ -192,12 +191,12 @@ func resourceVirtualClusterDelete(ctx context.Context, d *schema.ResourceData, m
}

// Not actually a validation exception
if tfawserr.ErrMessageContains(err, awstypes.ErrCodeValidationException, "not found") {
if errs.IsAErrorMessageContains[*awstypes.ValidationException](err, "not found") {
return diags
}

// Not actually a validation exception
if tfawserr.ErrMessageContains(err, awstypes.ErrCodeValidationException, "already terminated") {
if errs.IsAErrorMessageContains[*awstypes.ValidationException](err, "already terminated") {
return diags
}

Expand Down Expand Up @@ -228,32 +227,28 @@ func expandContainerProvider(tfMap map[string]interface{}) *awstypes.ContainerPr
}

if v, ok := tfMap[names.AttrType].(string); ok && v != "" {
apiObject.Type = aws.String(v)
apiObject.Type = awstypes.ContainerProviderType(v)
}

return apiObject
}

func expandContainerInfo(tfMap map[string]interface{}) *awstypes.ContainerInfo {
func expandContainerInfo(tfMap map[string]interface{}) awstypes.ContainerInfo {
if tfMap == nil {
return nil
}

apiObject := &awstypes.ContainerInfo{}
apiObject := &awstypes.ContainerInfoMemberEksInfo{}

if v, ok := tfMap["eks_info"].([]interface{}); ok && len(v) > 0 {
apiObject.EksInfo = expandEKSInfo(v[0].(map[string]interface{}))
apiObject.Value = expandEKSInfo(v[0].(map[string]interface{}))
}

return apiObject
}

func expandEKSInfo(tfMap map[string]interface{}) *awstypes.EksInfo {
if tfMap == nil {
return nil
}

apiObject := &awstypes.EksInfo{}
func expandEKSInfo(tfMap map[string]interface{}) awstypes.EksInfo {
apiObject := awstypes.EksInfo{}

if v, ok := tfMap[names.AttrNamespace].(string); ok && v != "" {
apiObject.Namespace = aws.String(v)
Expand All @@ -277,22 +272,21 @@ func flattenContainerProvider(apiObject *awstypes.ContainerProvider) map[string]
tfMap["info"] = []interface{}{flattenContainerInfo(v)}
}

if v := apiObject.Type; v != nil {
tfMap[names.AttrType] = aws.ToString(v)
}
tfMap[names.AttrType] = string(apiObject.Type)

return tfMap
}

func flattenContainerInfo(apiObject *awstypes.ContainerInfo) map[string]interface{} {
func flattenContainerInfo(apiObject awstypes.ContainerInfo) map[string]interface{} {
if apiObject == nil {
return nil
}

tfMap := map[string]interface{}{}

if v := apiObject.EksInfo; v != nil {
tfMap["eks_info"] = []interface{}{flattenEKSInfo(v)}
switch v := apiObject.(type) {
case *awstypes.ContainerInfoMemberEksInfo:
tfMap["eks_info"] = []interface{}{flattenEKSInfo(&v.Value)}
}

return tfMap
Expand Down Expand Up @@ -344,9 +338,9 @@ func FindVirtualClusterByID(ctx context.Context, conn *emrcontainers.Client, id
return nil, err
}

if state := aws.ToString(output.State); state == awstypes.VirtualClusterStateTerminated {
if output.State == awstypes.VirtualClusterStateTerminated {
return nil, &retry.NotFoundError{
Message: state,
Message: string(output.State),
LastRequest: input,
}
}
Expand All @@ -366,13 +360,13 @@ func statusVirtualCluster(ctx context.Context, conn *emrcontainers.Client, id st
return nil, "", err
}

return output, aws.ToString(output.State), nil
return output, string(output.State), nil
}
}

func waitVirtualClusterDeleted(ctx context.Context, conn *emrcontainers.Client, id string, timeout time.Duration) (*awstypes.VirtualCluster, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{awstypes.VirtualClusterStateTerminating},
Pending: enum.Slice(awstypes.VirtualClusterStateTerminating),
Target: []string{},
Refresh: statusVirtualCluster(ctx, conn, id),
Timeout: timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func dataSourceVirtualClusterRead(ctx context.Context, d *schema.ResourceData, m
} else {
d.Set("container_provider", nil)
}
d.Set(names.AttrCreatedAt, aws.TimeValue(vc.CreatedAt).String())
d.Set(names.AttrCreatedAt, aws.ToTime(vc.CreatedAt).String())
d.Set(names.AttrName, vc.Name)
d.Set(names.AttrState, vc.State)
d.Set("virtual_cluster_id", vc.Id)
Expand Down
1 change: 0 additions & 1 deletion internal/service/emrcontainers/virtual_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/service/emrcontainers"
awstypes "github.com/aws/aws-sdk-go-v2/service/emrcontainers/types"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down

0 comments on commit d2901cf

Please sign in to comment.