-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
New Resource: aws_ssm_resource_data_sync #1895
Conversation
|
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.
Thanks for the PR @atsushi-ishibashi
I left you some comments in the code. Let me know if anything's unclear.
if aerr, ok := err.(awserr.Error); ok { | ||
switch aerr.Code() { | ||
case ssm.ErrCodeResourceDataSyncAlreadyExistsException: | ||
if err := resourceAwsSsmResourceDataSyncDeleteAndCreate(meta, input); err != nil { |
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.
Can you please explain why we should ever recreate the resource? The common convention (and user's expectations) is to just error out in case there's a conflict.
Required: true, | ||
ForceNew: true, | ||
}, | ||
"destination": { |
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.
Is there any reason we should drift away from the API here? i.e. how do you feel about renaming this to s3_destination
?
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"bucket": { |
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.
As above - bucket_name
?
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"key": { |
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.
As above - kms_key_arn
?
|
||
input := &ssm.CreateResourceDataSyncInput{ | ||
S3Destination: &ssm.ResourceDataSyncS3Destination{ | ||
SyncFormat: aws.String(ssm.ResourceDataSyncS3FormatJsonSerDe), |
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.
Perhaps a nitpick, but how do you feel about exposing this argument via schema too? It would help us to be prepared for time when AWS introduces new sync format(s).
if found || nextToken == "" { | ||
break | ||
} | ||
} |
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.
Once you have decoupled the logic for finding the right data sync, it can also be reused here 😉
} | ||
} | ||
if found { | ||
return fmt.Errorf("[DELETE ERROR] Resource Data Sync found for SyncName: %s", rs.Primary.Attributes["name"]) |
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.
Nitpick, but there's no reason to prefix the message with [DELETE ERROR]
- it's already clear that it's error.
} | ||
|
||
resource "aws_ssm_resource_data_sync" "foo" { | ||
name = "foo" |
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.
Do you mind randomizing the name here?
if val, ok := m["prefix"]; ok { | ||
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(val.(string)))) | ||
} | ||
return hashcode.String(buf.String()) |
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.
Can you please explain why do we need to lowercase all the values here? It seems unnecessary to me. 🤔
ForceNew: true, | ||
}, | ||
"destination": { | ||
Type: schema.TypeSet, |
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.
Since this is a singleton I think we can just make it TypeList
as there's no value in computing the hash and it would also complicate referencing. TypeList can be referenced as s3_destination.0.key
etc., whereas TypeSet is non-trivial to reference because the address is s3_destination.<computed-idx>.key
.
@radeksimko I absolutely agree with your feedback. I'm sorry for bothering you with trivial mistakes because I couldn't understand the behaivour when I submitted this PR 🙇
|
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.
Hi @atsushi-ishibashi
thanks for implementing the feedback promptly.
There's no need to apologise! 😃
I just left you a few last comments - then I think we're ready to ship it 🚀
} else { | ||
d.SetId("") | ||
return nil | ||
} |
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.
I'm slightly worried about this conditional here, because we may add more errors to findResourceDataSyncItem
in the future which aren't awserr
and those may have nothing to do with "resource not found".
How do you feel about tweaking findResourceDataSyncItem
to return nil, nil
if no resource was found and then checking the nil
here, instead of checking the error isn't awserr.Error?
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.
Sure👍 I'll apply that idea!
return err | ||
} else { | ||
return nil | ||
} |
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.
^ I share the same concerns here as above
return fmt.Sprintf(` | ||
resource "aws_s3_bucket" "hoge" { | ||
bucket = "tf-test-bucket-%d" | ||
region = "us-east-1" |
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.
Any particular reason why this bucket should be in us-east-1
? It's certainly no big deal, just that our primary test region is us-west-2
.
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.
👋
There's a few compilation errors to address:
aws/resource_aws_ssm_resource_data_sync.go:4:2: imported and not used: "fmt"
aws/resource_aws_ssm_resource_data_sync.go:7:2: imported and not used: "github.com/terraform-providers/terraform-provider-aws/vendor/github.com/aws/aws-sdk-go/aws/awserr"
😉
@atsushi-ishibashi I just added retry logic to work around the eventually consistent nature of S3 which emerged in the acceptance test:
Let me know if you have any questions in regards to that patch, otherwise I'm happy to merge this. |
@radeksimko I missed that point... Of course, I appreciate the patch👍 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
#1259
In my local environment, I got error like below. But all checks have passed in travis-ci...