-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
r/glue_registry - new resource #16418
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package finder | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/service/glue" | ||
tfglue "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/glue" | ||
) | ||
|
||
// RegistryByID returns the Registry corresponding to the specified ID. | ||
func RegistryByID(conn *glue.Glue, id string) (*glue.GetRegistryOutput, error) { | ||
input := &glue.GetRegistryInput{ | ||
RegistryId: tfglue.CreateAwsGlueRegistryID(id), | ||
} | ||
|
||
output, err := conn.GetRegistry(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return output, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"regexp" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/glue" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" | ||
tfglue "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/glue" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/glue/finder" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/glue/waiter" | ||
) | ||
|
||
func resourceAwsGlueRegistry() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsGlueRegistryCreate, | ||
Read: resourceAwsGlueRegistryRead, | ||
Update: resourceAwsGlueRegistryUpdate, | ||
Delete: resourceAwsGlueRegistryDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringLenBetween(0, 2048), | ||
}, | ||
"registry_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.All( | ||
validation.StringLenBetween(1, 255), | ||
validation.StringMatch(regexp.MustCompile(`[a-zA-Z0-9-_$#]+$`), ""), | ||
), | ||
}, | ||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsGlueRegistryCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).glueconn | ||
|
||
input := &glue.CreateRegistryInput{ | ||
RegistryName: aws.String(d.Get("registry_name").(string)), | ||
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().GlueTags(), | ||
} | ||
|
||
if v, ok := d.GetOk("description"); ok { | ||
input.Description = aws.String(v.(string)) | ||
} | ||
|
||
log.Printf("[DEBUG] Creating Glue Registry: %s", input) | ||
output, err := conn.CreateRegistry(input) | ||
if err != nil { | ||
return fmt.Errorf("error creating Glue Registry: %w", err) | ||
} | ||
d.SetId(aws.StringValue(output.RegistryArn)) | ||
|
||
return resourceAwsGlueRegistryRead(d, meta) | ||
} | ||
|
||
func resourceAwsGlueRegistryRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).glueconn | ||
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig | ||
|
||
output, err := finder.RegistryByID(conn, d.Id()) | ||
if err != nil { | ||
if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") { | ||
log.Printf("[WARN] Glue Registry (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("error reading Glue Registry (%s): %w", d.Id(), err) | ||
} | ||
|
||
if output == nil { | ||
log.Printf("[WARN] Glue Registry (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
arn := aws.StringValue(output.RegistryArn) | ||
d.Set("arn", arn) | ||
d.Set("description", output.Description) | ||
d.Set("registry_name", output.RegistryName) | ||
|
||
tags, err := keyvaluetags.GlueListTags(conn, arn) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error listing tags for Glue Registry (%s): %w", arn, err) | ||
} | ||
|
||
if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
return fmt.Errorf("error setting tags: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsGlueRegistryUpdate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).glueconn | ||
|
||
if d.HasChanges("description") { | ||
input := &glue.UpdateRegistryInput{ | ||
RegistryId: tfglue.CreateAwsGlueRegistryID(d.Id()), | ||
} | ||
|
||
if v, ok := d.GetOk("description"); ok { | ||
input.Description = aws.String(v.(string)) | ||
} | ||
|
||
log.Printf("[DEBUG] Updating Glue Registry: %#v", input) | ||
_, err := conn.UpdateRegistry(input) | ||
if err != nil { | ||
return fmt.Errorf("error updating Glue Registry (%s): %w", d.Id(), err) | ||
} | ||
} | ||
|
||
if d.HasChange("tags") { | ||
o, n := d.GetChange("tags") | ||
if err := keyvaluetags.GlueUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { | ||
return fmt.Errorf("error updating tags: %s", err) | ||
} | ||
} | ||
|
||
return resourceAwsGlueRegistryRead(d, meta) | ||
} | ||
|
||
func resourceAwsGlueRegistryDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).glueconn | ||
|
||
log.Printf("[DEBUG] Deleting Glue Registry: %s", d.Id()) | ||
input := &glue.DeleteRegistryInput{ | ||
RegistryId: tfglue.CreateAwsGlueRegistryID(d.Id()), | ||
} | ||
|
||
_, err := conn.DeleteRegistry(input) | ||
if err != nil { | ||
if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") { | ||
return nil | ||
} | ||
return fmt.Errorf("error deleting Glue Registry (%s): %w", d.Id(), err) | ||
} | ||
|
||
_, err = waiter.RegistryDeleted(conn, d.Id()) | ||
if err != nil { | ||
if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") { | ||
return nil | ||
} | ||
return fmt.Errorf("error waiting for Glue Registry (%s) to be deleted: %w", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. My understanding is that
Create
andParse
ID functions are meant to work on strings only, so this functionality can just be moved intofinder.RegistryByID
.