-
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: r/aws_config_aggregator #4262
Conversation
30122c0
to
d89a04f
Compare
d89a04f
to
62833ba
Compare
62833ba
to
a3b5a6d
Compare
Any sign of this being merged? 4263 as well? |
@gazoakley Done, cheers! |
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 looks really good @gazoakley! Passes acceptance testing in our special Organizations testing account. 🚀 There are a few minor things similar to #4263 which I'll adjust post-merge that are noted below. Thanks!
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccConfigAggregator_import(t *testing.T) { |
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.
Minor nitpick: we're going to move away from separate import test files and tests (#4705). We can simply add the final TestStep the existing _basic
test 👍
@@ -303,6 +303,7 @@ func Provider() terraform.ResourceProvider { | |||
"aws_cloudwatch_log_resource_policy": resourceAwsCloudWatchLogResourcePolicy(), | |||
"aws_cloudwatch_log_stream": resourceAwsCloudWatchLogStream(), | |||
"aws_cloudwatch_log_subscription_filter": resourceAwsCloudwatchLogSubscriptionFilter(), | |||
"aws_config_aggregator": resourceAwsConfigAggregator(), |
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.
Similar to #4263 we should prefer to clarify that this is a "configuration" aggregator to match the API, especially if they later introduce some other type of aggregator:
"aws_config_configuration_aggregator": resourceAwsConfigConfigurationAggregator(),
}, | ||
|
||
CustomizeDiff: customdiff.Sequence( | ||
customdiff.ForceNewIfChange("account_aggregation_source", func(old, new, meta interface{}) 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.
I believe we can just set ForceNew: true
on the root attributes instead of implementing CustomizeDiff
here.
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 was trying to minimise delete/recreate operations - it's OK to call PutConfigurationAggregatorInput
to make changes to an existing aggregator as long as you aren't switching between organization or account aggregation sources.
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.
Ah: its because of this behavior (seemingly buggy as ForceNew:
doesn't necessarily apply to all nested attributes anymore):
All fields are ForceNew or Computed w/out Optional, Update is superfluous
I'll add this in a comment in there.
return err | ||
} | ||
|
||
if len(res.ConfigurationAggregators) == 0 { |
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.
While trying to prevent panics here, we should check res == nil
as well 👍
d.Set("name", aggregator.ConfigurationAggregatorName) | ||
|
||
if aggregator.AccountAggregationSources != nil { | ||
d.Set("account_aggregation_source", flattenConfigAccountAggregationSources(aggregator.AccountAggregationSources)) |
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.
Two notes:
- The flatten function should handle
nil
input and return a zero length slice so we do not need to wrap this with a conditional - When setting non-scalar attributes in the Terraform state, we prefer to perform error checking:
if err := d.Set("account_aggregation_source", flattenConfigAccountAggregationSources(aggregator.AccountAggregationSources)); err != nil {
return fmt.Errorf("error setting account_aggregation_source: %s", err)
}
return err | ||
} | ||
|
||
d.SetId("") |
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.
d.SetId("")
is extraneous in delete functions
} | ||
conn := client.(*AWSClient).configconn | ||
|
||
resp, err := conn.DescribeConfigurationAggregators(&configservice.DescribeConfigurationAggregatorsInput{}) |
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 call is not currently handling NextToken
so it can miss resources in large or separate API responses.
var result []interface{} | ||
m := make(map[string]interface{}) | ||
m["account_ids"] = flattenStringList(source.AccountIds) | ||
m["all_regions"] = *source.AllAwsRegions |
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.
To prevent potential panics we should prefer to use the SDK functions for dereferencing values here and below, e.g. aws.BoolValue(source.AllAwsRegions)
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: |
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're in the process of updating all these for clarity (#4685): In addition to all arguments above, the following attributes are exported:
|
||
name = "tf-%s" | ||
|
||
organization_aggregation_source { |
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.
MAINTAINERS NOTE: This will currently create an AWS Organizations organization, enable service control policy on it, and leave it dangling after the test. Will need to add the Terraform aws_organizations_organization
resource to this test configuration and serialize with the rest of the AWS Organizations testing.
…back === RUN TestAccConfigAggregator_account --- PASS: TestAccConfigAggregator_account (36.87s) === RUN TestAccConfigAggregator_organization --- PASS: TestAccConfigAggregator_organization (39.71s) === RUN TestAccConfigAggregator_switch --- PASS: TestAccConfigAggregator_switch (59.08s)
This has been released in version 1.22.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
Somehow the Can somebody else verify this? EDIT: Looks like a state import worked. |
Same problem here. Terraform apply keeps creating the resource but doesn't add to the state file. |
@bflad I believe there is a bug in terraform as the aws_config_configuration_aggregator is not storing the details in the state file |
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! |
Partially implements #4067
New Resources:
aws_config_aggregator