Skip to content
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

Merged
merged 1 commit into from Jun 3, 2018

Conversation

gazoakley
Copy link
Contributor

@gazoakley gazoakley commented Apr 19, 2018

Partially implements #4067

New Resources:

  • aws_config_aggregator
$ make testacc TESTARGS='-run=TestAccConfigAggregator'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -run=TestAccConfigAggregator -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccConfigAggregator_import
--- PASS: TestAccConfigAggregator_import (25.42s)
=== RUN   TestAccConfigAggregator_account
--- PASS: TestAccConfigAggregator_account (28.26s)
=== RUN   TestAccConfigAggregator_organization
--- PASS: TestAccConfigAggregator_organization (28.64s)
=== RUN   TestAccConfigAggregator_switch
--- PASS: TestAccConfigAggregator_switch (44.97s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	127.344s

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Apr 19, 2018
@bflad bflad added new-resource Introduces a new resource. service/configservice Issues and PRs that pertain to the configservice service. labels Apr 20, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Apr 22, 2018
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Apr 22, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Apr 22, 2018
@gazoakley gazoakley changed the title [WIP] New Resource: r/aws_config_aggregator New Resource: r/aws_config_aggregator Apr 22, 2018
@djk
Copy link

djk commented May 22, 2018

Any sign of this being merged? 4263 as well?

@gazoakley
Copy link
Contributor Author

@djk can you thumbs up the original post here please: #4067 (I think they use thumbs to prioritise reviews)

@djk
Copy link

djk commented May 22, 2018

@gazoakley Done, cheers!

@bflad bflad added this to the v1.22.0 milestone Jun 3, 2018
Copy link
Member

@bflad bflad left a 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) {
Copy link
Member

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(),
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 {
Copy link
Member

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))
Copy link
Member

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("")
Copy link
Member

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{})
Copy link
Member

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
Copy link
Member

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:
Copy link
Member

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 {
Copy link
Member

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.

@bflad bflad merged commit a3b5a6d into hashicorp:master Jun 3, 2018
bflad added a commit that referenced this pull request Jun 3, 2018
…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)
bflad added a commit that referenced this pull request Jun 3, 2018
@bflad
Copy link
Member

bflad commented Jun 5, 2018

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.

@msvechla
Copy link

msvechla commented Apr 8, 2019

Somehow the aws_config_configuration_aggregator is not persisted in terraform state for me. Terraform creates this ressource during every run.

Can somebody else verify this?

EDIT: Looks like a state import worked.

@guipaivanz
Copy link

Same problem here. Terraform apply keeps creating the resource but doesn't add to the state file.
After running terraform import it worked

@guipaivanz
Copy link

@bflad I believe there is a bug in terraform as the aws_config_configuration_aggregator is not storing the details in the state file

@ghost
Copy link

ghost commented Mar 30, 2020

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!

@hashicorp hashicorp locked and limited conversation to collaborators Mar 30, 2020
@gazoakley gazoakley deleted the f-config-aggregator branch April 7, 2020 16:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/configservice Issues and PRs that pertain to the configservice service. size/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants