Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/glue_schema - new resource #16612

Merged
merged 11 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions aws/internal/service/glue/finder/finder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package finder

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/glue"
tfglue "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/glue"
)
Expand All @@ -18,3 +19,34 @@ func RegistryByID(conn *glue.Glue, id string) (*glue.GetRegistryOutput, error) {

return output, nil
}

// SchemaByID returns the Schema corresponding to the specified ID.
func SchemaByID(conn *glue.Glue, id string) (*glue.GetSchemaOutput, error) {
input := &glue.GetSchemaInput{
SchemaId: tfglue.CreateAwsGlueSchemaID(id),
}

output, err := conn.GetSchema(input)
if err != nil {
return nil, err
}

return output, nil
}

// SchemaVersionByID returns the Schema corresponding to the specified ID.
func SchemaVersionByID(conn *glue.Glue, id string) (*glue.GetSchemaVersionOutput, error) {
input := &glue.GetSchemaVersionInput{
SchemaId: tfglue.CreateAwsGlueSchemaID(id),
SchemaVersionNumber: &glue.SchemaVersionNumber{
LatestVersion: aws.Bool(true),
},
}

output, err := conn.GetSchemaVersion(input)
if err != nil {
return nil, err
}

return output, nil
}
6 changes: 6 additions & 0 deletions aws/internal/service/glue/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ func CreateAwsGlueRegistryID(id string) *glue.RegistryId {
RegistryArn: aws.String(id),
}
}

func CreateAwsGlueSchemaID(id string) *glue.SchemaId {
return &glue.SchemaId{
SchemaArn: aws.String(id),
}
}
40 changes: 37 additions & 3 deletions aws/internal/service/glue/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
)

const (
MLTransformStatusUnknown = "Unknown"
RegistryStatusUnknown = "Unknown"
TriggerStatusUnknown = "Unknown"
MLTransformStatusUnknown = "Unknown"
RegistryStatusUnknown = "Unknown"
SchemaStatusUnknown = "Unknown"
SchemaVersionStatusUnknown = "Unknown"
TriggerStatusUnknown = "Unknown"
)

// MLTransformStatus fetches the MLTransform and its Status
Expand Down Expand Up @@ -53,6 +55,38 @@ func RegistryStatus(conn *glue.Glue, id string) resource.StateRefreshFunc {
}
}

// SchemaStatus fetches the Schema and its Status
func SchemaStatus(conn *glue.Glue, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.SchemaByID(conn, id)
if err != nil {
return nil, SchemaStatusUnknown, err
}

if output == nil {
return output, SchemaStatusUnknown, nil
}

return output, aws.StringValue(output.SchemaStatus), nil
}
}

// SchemaVersionStatus fetches the Schema Version and its Status
func SchemaVersionStatus(conn *glue.Glue, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.SchemaVersionByID(conn, id)
if err != nil {
return nil, SchemaVersionStatusUnknown, err
}

if output == nil {
return output, SchemaVersionStatusUnknown, nil
}

return output, aws.StringValue(output.Status), nil
}
}

// TriggerStatus fetches the Trigger and its Status
func TriggerStatus(conn *glue.Glue, triggerName string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
Expand Down
65 changes: 61 additions & 4 deletions aws/internal/service/glue/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (

const (
// Maximum amount of time to wait for an Operation to return Deleted
MLTransformDeleteTimeout = 2 * time.Minute
RegistryDeleteTimeout = 2 * time.Minute
TriggerCreateTimeout = 2 * time.Minute
TriggerDeleteTimeout = 2 * time.Minute
MLTransformDeleteTimeout = 2 * time.Minute
RegistryDeleteTimeout = 2 * time.Minute
SchemaAvailableTimeout = 2 * time.Minute
SchemaDeleteTimeout = 2 * time.Minute
SchemaVersionAvailableTimeout = 2 * time.Minute
TriggerCreateTimeout = 2 * time.Minute
TriggerDeleteTimeout = 2 * time.Minute
)

// MLTransformDeleted waits for an MLTransform to return Deleted
Expand Down Expand Up @@ -51,6 +54,60 @@ func RegistryDeleted(conn *glue.Glue, registryID string) (*glue.GetRegistryOutpu
return nil, err
}

// SchemaAvailable waits for a Schema to return Available
func SchemaAvailable(conn *glue.Glue, registryID string) (*glue.GetSchemaOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{glue.SchemaStatusPending},
Target: []string{glue.SchemaStatusAvailable},
Refresh: SchemaStatus(conn, registryID),
Timeout: SchemaAvailableTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*glue.GetSchemaOutput); ok {
return output, err
}

return nil, err
}

// SchemaDeleted waits for a Schema to return Deleted
func SchemaDeleted(conn *glue.Glue, registryID string) (*glue.GetSchemaOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{glue.SchemaStatusDeleting},
Target: []string{},
Refresh: SchemaStatus(conn, registryID),
Timeout: SchemaDeleteTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*glue.GetSchemaOutput); ok {
return output, err
}

return nil, err
}

// SchemaVersionAvailable waits for a Schema to return Available
func SchemaVersionAvailable(conn *glue.Glue, registryID string) (*glue.GetSchemaVersionOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{glue.SchemaVersionStatusPending},
Target: []string{glue.SchemaVersionStatusAvailable},
Refresh: SchemaVersionStatus(conn, registryID),
Timeout: SchemaVersionAvailableTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*glue.GetSchemaVersionOutput); ok {
return output, err
}

return nil, err
}

// TriggerCreated waits for a Trigger to return Created
func TriggerCreated(conn *glue.Glue, triggerName string) (*glue.GetTriggerOutput, error) {
stateConf := &resource.StateChangeConf{
Expand Down
3 changes: 2 additions & 1 deletion aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,12 @@ func Provider() *schema.Provider {
"aws_glue_ml_transform": resourceAwsGlueMLTransform(),
"aws_glue_partition": resourceAwsGluePartition(),
"aws_glue_registry": resourceAwsGlueRegistry(),
"aws_glue_resource_policy": resourceAwsGlueResourcePolicy(),
"aws_glue_schema": resourceAwsGlueSchema(),
"aws_glue_security_configuration": resourceAwsGlueSecurityConfiguration(),
"aws_glue_trigger": resourceAwsGlueTrigger(),
"aws_glue_user_defined_function": resourceAwsGlueUserDefinedFunction(),
"aws_glue_workflow": resourceAwsGlueWorkflow(),
"aws_glue_resource_policy": resourceAwsGlueResourcePolicy(),
"aws_guardduty_detector": resourceAwsGuardDutyDetector(),
"aws_guardduty_filter": resourceAwsGuardDutyFilter(),
"aws_guardduty_invite_accepter": resourceAwsGuardDutyInviteAccepter(),
Expand Down
Loading