-
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
feature(config): manage AWS Config Remediation Configuration #9348
Conversation
I'm starting to write acceptance tests ATM (and just saw Travis' failure, which I will fix ASAP) |
f6d4338
to
be57a6c
Compare
9f9bd41
to
1e4269b
Compare
6f9a501
to
1e4269b
Compare
I've read through https://github.com/terraform-providers/terraform-provider-aws/blob/master/.github/CONTRIBUTING.md#common-review-items , and aside from points |
Note for the maintainers : |
Answering hashicorp#7972 This is my 1st go development ever, so please feel free to tell me if I did something in a bad way, which is most probable :) feat(go): learn pointers usage feat(config): parse all simple fields chore(naming): replace ConfigRule by RemediationConfiguration feat(config): add read flatten function feat(config): add delete function feat(config): use TypeSet instead of TypeList, & parse ResourceValue feat(config): parse StaticValue feat(config) flatten remediation config parameters to nil, just to get the function signature right feat(config): flatten remediation config parameters
chore(tidy): remove unused import comments test(config): copy-paste config rule test to start from something feat(test): add shredder feat(config): add a remediation configuration exemple feat(test): add getter check feat(config): add 1st finished acc test feat(test): remove unadapted commented tests & add a second true test feat(test): add static values tests chore(fmt): format the file with make fmt fixup! chore(fmt): format the file with make fmt fix(test): add required on fields chore(lint): proceed with linter results chore(lint): use correct configuration
1e4269b
to
9ce9044
Compare
(force pushed because of a rebase on upstream) |
I see you just added the code to support Organizations in AWS Config, @bflad . |
Hey @andy-b-84 👋 Thank you for contributing this! We will certainly want to get support for this new resource added at some point. I can provide you a quick review (a few minutes behind this comment) and potentially try and help troubleshoot your local Go environment here, but unfortunately at this time the maintainers are pretty backlogged. We would prefer that contributors can appropriately run their own acceptance testing if possible as it saves a lot of small back-and-forth GitHub interactions for troubleshooting and reviews. 😅 We can certainly try to answer specific questions when time permits though. It would be super helpful to know what operating system you are using, how Go was installed, which version of Go, and what errors you are seeing when running For general assistance just beyond folks who may be able to help you on GitHub here, there are also other potentially helpful resources for Terraform Provider/Go development including the community forums or Slack workspaces such as the Gophers Slack. |
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 @andy-b-84 👋 As promised, here is an initial review of the submitted code. Please reach out with any questions or if you do not have time to implement the feedback items.
Please also let us know about your testing issues or if you would prefer to discuss them in another forum. Thanks.
Thanks for the extensive review and proposed help for my dev environment @bflad , and sorry to answer only now : as you may have guessed I was on vacation :) |
I started a thread on gophers#newbies : https://gophers.slack.com/archives/C02A8LZKT/p1566895456146900 in order to get help getting my environment working. |
d523162
to
519662f
Compare
519662f
to
70be653
Compare
4165150
to
d55268f
Compare
I'd like to add |
What happened with this? Would love to see this implemented. |
Would love to see this in a release. |
Would awesome to have this feature |
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 @andy-b-84, thanks for the contribution! And thanks for your patience with our delay in getting back to you.
In the time since you made the PR, we've changed a number of things internally in our code. One major change is that the schema and resource definitions have move to their own SDK. The best approach would be to rebase your code onto the current provider and use the updated plugin SDK.
I've made a number of other suggestions if you want to continue working on this or if you'd like us to complete it. If not, we understand. Let us know in a reply here. I'll check back by 24 June
func expandConfigRemediationConfigurationParameters(configured *schema.Set) map[string]*configservice.RemediationParameterValue { | ||
var staticValues []*string | ||
results := make(map[string]*configservice.RemediationParameterValue) | ||
|
||
emptyString := "" | ||
|
||
for _, item := range configured.List() { | ||
detail := item.(map[string]interface{}) | ||
rpv := configservice.RemediationParameterValue{} | ||
|
||
if resourceValue, ok := detail["resource_value"].(string); ok { | ||
rv := configservice.ResourceValue{ | ||
Value: &emptyString, | ||
} | ||
rpv.ResourceValue = &rv | ||
results[resourceValue] = &rpv | ||
} | ||
if staticValue, ok := detail["static_value"].(map[string]string); ok { | ||
value := staticValue["value"] | ||
staticValues = make([]*string, 0) | ||
staticValues = append(staticValues, &value) | ||
sv := configservice.StaticValue{ | ||
Values: staticValues, | ||
} | ||
rpv.StaticValue = &sv | ||
results[staticValue["key"]] = &rpv | ||
} | ||
} | ||
|
||
return results | ||
} | ||
|
||
func flattenRemediationConfigurations(c []*configservice.RemediationConfiguration) []map[string]interface{} { | ||
configurations := make([]map[string]interface{}, 0) | ||
|
||
for _, bd := range c { | ||
if bd.ConfigRuleName != nil && bd.Parameters != nil { | ||
configuration := make(map[string]interface{}) | ||
configuration["config_rule_name"] = *bd.ConfigRuleName | ||
configuration["parameters"] = flattenRemediationConfigurationParameters(bd.Parameters) | ||
configuration["resource_type"] = *bd.ResourceType | ||
configuration["target_id"] = *bd.TargetId | ||
configuration["target_type"] = *bd.TargetType | ||
configuration["target_version"] = *bd.TargetVersion | ||
|
||
configurations = append(configurations, configuration) | ||
} | ||
} | ||
|
||
if len(configurations) > 0 { | ||
return configurations | ||
} | ||
|
||
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.
We prefer that the resource schema function (i.e. resourceAwsConfigRemediationConfiguration()
) is at the top of the file
RemediationConfigurations: []*configservice.RemediationConfiguration{&remediationConfigurationInput}, | ||
} | ||
log.Printf("[DEBUG] Creating AWSConfig remediation configuration: %s", input) | ||
err := resource.Retry(2*time.Minute, func() *resource.RetryError { |
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 prefer named constants for timeout values
|
||
return nil | ||
}) | ||
if 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.
We've started adding one last try after resource.Retry()
in case of a timeout.
if isResourceTimeoutError(err) {
_, err = conn.PutRemediationConfigurations(&input)
}
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" |
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've separated the resource and schema functions into their own package, github.com/hashicorp/terraform-plugin-sdk/helper/*
. Please update to use those packages.
value := staticValue["value"] | ||
staticValues = make([]*string, 0) | ||
staticValues = append(staticValues, &value) | ||
sv := configservice.StaticValue{ | ||
Values: staticValues, | ||
} | ||
rpv.StaticValue = &sv | ||
results[staticValue["key"]] = &rpv |
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 could be inlined, something like
results[staticValue["key"]] = &configservice.RemediationParameterValue{
StaticValue: &configservice.StaticValue{
Values: []*string{aws.String(staticValue["value"])},
},
}
* `config_rule_name` - (Required) The name of the AWS Config rule | ||
* `resource_type` - (Optional) The type of a resource | ||
* `target_id` - (Required) Target ID is the name of the public document | ||
* `target_type` - (Required) The type of the target. Target executes remediation. For example, SSM document |
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 field only accepts a specific list of values, we should list the valid values. In this case, there's only one valid value, so it could read "The only current valid value is SSM_DOCUMENT
"
* `target_id` - (Required) Target ID is the name of the public document | ||
* `target_type` - (Required) The type of the target. Target executes remediation. For example, SSM document | ||
* `target_version` - (Required) Version of the target. For example, version of the SSM document | ||
|
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 should add an entry for parameters
here at the top level, and have a description like "Up to 25 parameter blocks. Parameters are documented below."
* `target_type` - (Required) The type of the target. Target executes remediation. For example, SSM document | ||
* `target_version` - (Required) Version of the target. For example, version of the SSM document | ||
|
||
### `parameters` |
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 heading should read "A parameters
block supports the following arguments:"
|
||
AWS managed rules can be used by setting the source owner to `AWS` and the source identifier to the name of the managed rule. More information about AWS managed rules can be found in the [AWS Config Developer Guide](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_use-managed-rules.html). | ||
|
||
```hcl |
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.
For examples in the documentation, it's better for them to be short so that the essential parts are more obvious. In this case, we'd be ok to remove the IAM resources, or possibly leave the definition but remove the attributes. It does have the trade-off that these long examples aren't executable as-is.
|
||
Provides an AWS Config Remediation Configuration. | ||
|
||
~> **Note:** Config Remediation Configuration requires an existing [Config Rule](/docs/providers/aws/r/config_config_rule.html) to be present. Use of `depends_on` is recommended (as shown below) to avoid race conditions. |
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.
If we set the config_rule_name
of the remediation to the name
valueof the rule, then we can get the built-in Terraform dependency management without using
depends_on`
I'm open to picking up the torch if necessary here. |
Hello. I had to get this rolling quick for my org. This is rebased and added too. This is everything squashed (I figured there may be an issue with signing Andy's rebased commits with my key). Feel free to merge either, or cherry-pick changes over to this PR, or just use my changes as refs. Thank you and looking forward to easily creating remediation configs :) |
This work was completed in #13884. Thanks, @andy-b-84 and @cgetzen! |
This has been released in version 3.7.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! |
Answering #7972
This is my 1st go development ever, so please feel free to tell me if I
did something in a bad way, which is most probable :)
Community Note
Fixes #7972
Release note for CHANGELOG:
Output from acceptance testing: (ran on a docker container with image
golang:1.12.9-buster
)