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

Add excluded_regions to datadog_integration_aws #549

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 98 additions & 98 deletions datadog/cassettes/TestAccDatadogIntegrationAWS.yaml

Large diffs are not rendered by default.

188 changes: 94 additions & 94 deletions datadog/cassettes/TestAccDatadogIntegrationAWSLambdaArn.yaml

Large diffs are not rendered by default.

186 changes: 93 additions & 93 deletions datadog/cassettes/TestAccDatadogIntegrationAWSLogCollection.yaml

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions datadog/resource_datadog_integration_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func resourceDatadogIntegrationAws() *schema.Resource {
Optional: true,
Elem: schema.TypeBool,
},
"excluded_regions": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"external_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -92,7 +97,6 @@ func buildDatadogIntegrationAwsStruct(d *schema.ResourceData, accountID string,
iaws.SetRoleName(roleName)

filterTags := make([]string, 0)

if attr, ok := d.GetOk("filter_tags"); ok {
for _, s := range attr.([]interface{}) {
filterTags = append(filterTags, s.(string))
Expand All @@ -101,7 +105,6 @@ func buildDatadogIntegrationAwsStruct(d *schema.ResourceData, accountID string,
}

hostTags := make([]string, 0)

if attr, ok := d.GetOk("host_tags"); ok {
for _, s := range attr.([]interface{}) {
hostTags = append(hostTags, s.(string))
Expand All @@ -110,7 +113,6 @@ func buildDatadogIntegrationAwsStruct(d *schema.ResourceData, accountID string,
}

accountSpecificNamespaceRules := make(map[string]bool)

if attr, ok := d.GetOk("account_specific_namespace_rules"); ok {
// TODO: this is not very defensive, test if we can fail on non bool input
for k, v := range attr.(map[string]interface{}) {
Expand All @@ -119,6 +121,14 @@ func buildDatadogIntegrationAwsStruct(d *schema.ResourceData, accountID string,
iaws.SetAccountSpecificNamespaceRules(accountSpecificNamespaceRules)
}

excludedRegions := make([]string, 0)
if attr, ok := d.GetOk("excluded_regions"); ok {
for _, s := range attr.([]interface{}) {
excludedRegions = append(excludedRegions, s.(string))
}
iaws.SetExcludedRegions(excludedRegions)
}

return iaws
}

Expand Down Expand Up @@ -166,7 +176,8 @@ func resourceDatadogIntegrationAwsRead(d *schema.ResourceData, meta interface{})
d.Set("role_name", integration.GetRoleName())
d.Set("filter_tags", integration.GetFilterTags())
d.Set("host_tags", integration.GetHostTags())
d.Set("account_specific_namespace_rules", integration.AccountSpecificNamespaceRules)
d.Set("account_specific_namespace_rules", integration.GetAccountSpecificNamespaceRules())
d.Set("excluded_regions", integration.GetExcludedRegions())
return nil
}
}
Expand Down
27 changes: 17 additions & 10 deletions datadog/resource_datadog_integration_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,22 @@ func TestAccountAndRoleFromID(t *testing.T) {

const testAccDatadogIntegrationAWSConfig = `
resource "datadog_integration_aws" "account" {
account_id = "001234567888"
role_name = "testacc-datadog-integration-role"
account_id = "001234567888"
role_name = "testacc-datadog-integration-role"
}
`

const testAccDatadogIntegrationAWSUpdateConfig = `
resource "datadog_integration_aws" "account" {
account_id = "001234567889"
role_name = "testacc-datadog-integration-role"
filter_tags = ["key:value"]
host_tags = ["key:value", "key2:value2"]
account_specific_namespace_rules = {
auto_scaling = false
opsworks = true
}
account_id = "001234567889"
role_name = "testacc-datadog-integration-role"
filter_tags = ["key:value"]
host_tags = ["key:value", "key2:value2"]
account_specific_namespace_rules = {
auto_scaling = false
opsworks = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small indent issue here.

}
gzussa marked this conversation as resolved.
Show resolved Hide resolved
excluded_regions = ["us-east-1", "us-west-2"]
}
`

Expand Down Expand Up @@ -108,6 +109,12 @@ func TestAccDatadogIntegrationAWS(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_integration_aws.account",
"account_specific_namespace_rules.opsworks", "true"),
resource.TestCheckResourceAttr(
"datadog_integration_aws.account",
"excluded_regions.0", "us-east-1"),
resource.TestCheckResourceAttr(
"datadog_integration_aws.account",
"excluded_regions.1", "us-west-2"),
),
},
},
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/integration_aws.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ resource "datadog_integration_aws" "sandbox" {
auto_scaling = false
opsworks = false
}
excluded_regions = ["us-east-1", "us-west-2"]
}
```

Expand All @@ -40,6 +41,7 @@ The following arguments are supported:

* `host_tags` - (Optional) Array of tags (in the form key:value) to add to all hosts and metrics reporting through this integration.
* `account_specific_namespace_rules` - (Optional) Enables or disables metric collection for specific AWS namespaces for this AWS account only. A list of namespaces can be found at the [available namespace rules API endpoint](https://docs.datadoghq.com/api/v1/aws-integration/#list-namespace-rules).
* `excluded_regions` - (Optional) An array of AWS regions to exclude from metrics collection.

### See also
* [Datadog API Reference > Integrations > AWS](https://docs.datadoghq.com/api/v1/aws-integration/)
Expand Down