-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Add logs_config schema to aws_codebuild_project #7534
Add logs_config schema to aws_codebuild_project #7534
Conversation
Hi, curious if there’s any reason this hasn’t been merged yet? It’s been 2 months, and there have been new releases to this provider during that span. I’ve waited patiently during that time and have received zero feedback. Thanks, |
Any thoughts when it will be merged? |
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 @srhaber 👋 Thanks for this contribution and sorry for the delayed review. Please see the initial feedback and let us know if you have any questions or do not have time to implement the items.
Schema: map[string]*schema.Schema{ | ||
"status": { | ||
Type: schema.TypeString, | ||
Required: true, |
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.
Typically for these types of enabled/disabled flag arguments, we would prefer to make it optional and instead default to match the API default. Since the attribute is using DiffSuppressFunc
to ignore enabled configurations, it would be simpler to declare this attribute as:
"status": {
Type: schema.TypeString,
Optional: true,
Default: codebuild.LogsConfigStatusTypeEnabled,
ValidateFunc: validation.StringInSlice([]string{
codebuild.LogsConfigStatusTypeDisabled,
codebuild.LogsConfigStatusTypeEnabled,
}, false),
},
}, | ||
}, | ||
}, | ||
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { |
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.
This can be simplified with our helper function: DiffSuppressFunc: suppressMissingOptionalConfigurationBlock,
Optional: true, | ||
ValidateFunc: validateAwsCodeBuildProjectS3LogsLocation, | ||
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { | ||
return strings.TrimPrefix(new, "arn:aws:s3:::") == old |
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.
This particular difference suppression will only work in AWS Commercial (aws
partition) -- AWS supports many other partitions including AWS China (aws-cn
), AWS GovCloud US (aws-us-gov
), and some other non-public ones with their own ARN formats.
In general, we should avoid implementing our own logic on top of the API and instead validate the input to match the canonical form that is returned from the API. If the API always returns the value in the non-ARN format, we should validate that an ARN is not given and vice-versa. 👍
}, | ||
}, | ||
}, | ||
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { |
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.
Same here regarding suppressMissingOptionalConfigurationBlock
@@ -781,6 +949,10 @@ func resourceAwsCodeBuildProjectRead(d *schema.ResourceData, meta interface{}) e | |||
return err | |||
} | |||
|
|||
if err := d.Set("logs_config", flattenAwsCodeBuildLogsConfig(project.LogsConfig)); err != nil { | |||
return err |
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: The code around this isn't doing it (😖), but we should return context for operators and maintainers for errors like these, e.g.
return err | |
return fmt.Errorf("error setting logs_config: %s", err) |
|
||
func flattenAwsCodeBuildCloudWatchLogs(cloudWatchLogsConfig *codebuild.CloudWatchLogsConfig) []interface{} { | ||
if cloudWatchLogsConfig == nil { | ||
return []interface{}{} |
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.
We will likely need to return the default status value here if the API response is completely empty, so Terraform does not report an unexpected plan difference:
return []interface{}{} | |
return []interface{}{ | |
"status": codebuild.LogsConfigStatusTypeEnabled, | |
} |
|
||
func flattenAwsCodeBuildS3Logs(s3LogsConfig *codebuild.S3LogsConfig) []interface{} { | ||
if s3LogsConfig == nil { | ||
return []interface{}{} |
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.
Same here: We will likely need to return the default status value here if the API response is completely empty, so Terraform does not report an unexpected plan difference:
return []interface{}{} | |
return []interface{}{ | |
"status": codebuild.LogsConfigStatusTypeDisabled, | |
} |
|
||
s3_logs { | ||
status = "ENABLED" | ||
location = "${aws_s3_bucket.example.arn}/build-log" |
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.
Given the above changes for bucket name instead of ARN, this would be replaced with:
location = "${aws_s3_bucket.example.arn}/build-log" | |
location = "${aws_s3_bucket.example.bucket}/build-log" |
Thanks for the feedback @bflad! I'll have some updates pushed up shortly. |
2836980
to
52e2621
Compare
I implemented the suggested changes above. It required a rebase from master and corresponding force-push since there was a bit of code drift over the past few months. I also added the new Output from updated acceptance tests:
|
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 so much for the updates, @srhaber! Looks great. 🚀
--- PASS: TestAccAWSCodeBuildProject_Source_Auth (25.63s)
--- PASS: TestAccAWSCodeBuildProject_Source_Type_Bitbucket (25.63s)
--- PASS: TestAccAWSCodeBuildProject_basic (35.39s)
--- PASS: TestAccAWSCodeBuildProject_BuildTimeout (36.13s)
--- PASS: TestAccAWSCodeBuildProject_Source_GitCloneDepth (36.28s)
--- PASS: TestAccAWSCodeBuildProject_Source_Type_CodeCommit (37.27s)
--- PASS: TestAccAWSCodeBuildProject_BadgeEnabled (37.62s)
--- PASS: TestAccAWSCodeBuildProject_Source_ReportBuildStatus_GitHub (38.04s)
--- PASS: TestAccAWSCodeBuildProject_importBasic (38.59s)
--- PASS: TestAccAWSCodeBuildProject_Environment_Certificate (40.74s)
--- PASS: TestAccAWSCodeBuildProject_Description (47.64s)
--- PASS: TestAccAWSCodeBuildProject_LogsConfig_S3Logs (48.26s)
--- PASS: TestAWSCodeBuildProject_nameValidation (0.00s)
--- PASS: TestAccAWSCodeBuildProject_Source_ReportBuildStatus_Bitbucket (48.52s)
--- PASS: TestAccAWSCodeBuildProject_Environment_EnvironmentVariable_Type (48.79s)
--- PASS: TestAccAWSCodeBuildProject_Source_ReportBuildStatus_GitHubEnterprise (48.93s)
--- PASS: TestAccAWSCodeBuildProject_Source_InsecureSSL (48.97s)
--- PASS: TestAccAWSCodeBuildProject_Source_Type_NoSourceInvalid (15.11s)
--- PASS: TestAccAWSCodeBuildProject_LogsConfig_CloudWatchLogs (55.25s)
--- PASS: TestAccAWSCodeBuildProject_Source_Type_CodePipeline (31.04s)
--- PASS: TestAccAWSCodeBuildProject_EncryptionKey (57.18s)
--- PASS: TestAccAWSCodeBuildProject_Source_Type_GitHubEnterprise (31.32s)
--- PASS: TestAccAWSCodeBuildProject_Source_Type_NoSource (21.72s)
--- PASS: TestAccAWSCodeBuildProject_Source_Type_S3 (22.71s)
--- PASS: TestAccAWSCodeBuildProject_Environment_EnvironmentVariable (58.60s)
--- PASS: TestAccAWSCodeBuildProject_Artifacts_EncryptionDisabled (22.87s)
--- PASS: TestAccAWSCodeBuildProject_SecondaryArtifacts (22.35s)
--- PASS: TestAccAWSCodeBuildProject_WindowsContainer (29.36s)
--- PASS: TestAccAWSCodeBuildProject_Tags (37.58s)
--- PASS: TestAccAWSCodeBuildProject_SecondarySources_CodeCommit (27.80s)
--- PASS: TestAccAWSCodeBuildProject_Cache (76.38s)
--- PASS: TestAccAWSCodeBuildProject_Environment_RegistryCredential (27.86s)
@@ -826,31 +980,35 @@ func resourceAwsCodeBuildProjectRead(d *schema.ResourceData, meta interface{}) e | |||
project := resp.Projects[0] | |||
|
|||
if err := d.Set("artifacts", flattenAwsCodeBuildProjectArtifacts(project.Artifacts)); err != nil { | |||
return err | |||
return fmt.Errorf("error setting artifacts: %s", err) |
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.
😍 Thank you!
This has been released in version 2.19.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
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! |
Fixes #6312
Changes proposed in this pull request:
logs_config
parameter block toaws_codebuild_project
.Example:
Output from acceptance testing: