-
Notifications
You must be signed in to change notification settings - Fork 389
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
[datadog_integration_gcp_sts] Add Account tags, ResourceCollectionEnabled and IsSecurityCommandCenterEnabled support to gcp tf module #2134
Conversation
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.
Nothing really blocking, but we should talk about some of these comments. 👍
Also, are there no tests in the terraform stuff? 🤔
@@ -240,6 +249,12 @@ func (r *integrationGcpStsResource) buildIntegrationGcpStsRequestBody(ctx contex | |||
diags := diag.Diagnostics{} | |||
attributes := datadogV2.NewGCPSTSServiceAccountAttributesWithDefaults() | |||
|
|||
accountTags := make([]string, 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.
This is not idiomatic Go. Typically, you initialize slices to nil
. nil
slices are valid for just about anything (i.e. iteration, appending, etc).
var accountTags []string
But not familiar enough with this terraform stuff to know if that'll make a difference.
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.
Guess this is a copy paste from the code for host_filters
(same type)
if !state.AccountTags.IsNull() { | ||
diags.Append(state.AccountTags.ElementsAs(ctx, &accountTags, false)...) | ||
} | ||
attributes.SetAccountTags(accountTags) |
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.
Feels weird to include account_tags=[]
in the REST call when it's an optional field.
if !state.AccountTags.IsNull() { | ||
diags.Append(state.AccountTags.ElementsAs(ctx, &accountTags, false)...) | ||
} | ||
attributes.SetAccountTags(accountTags) |
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 comments apply 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.
Should we be doing something like the IsUnknown()
for AccountTags
(like we're doing below) since it's also a new field? Not familiar enough with terraform to know what's right here.
diags.Append(state.AccountTags.ElementsAs(ctx, &accountTags, false)...) | ||
} | ||
attributes.SetAccountTags(accountTags) | ||
|
||
if !state.Automute.IsNull() { | ||
attributes.SetAutomute(state.Automute.ValueBool()) | ||
} |
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.
All this stuff is super duplicative. Is it worth refactoring like this?
func (r *integrationGcpStsResource) buildIntegrationGcpStsCreateRequest(ctx context.Context, state *integrationGcpStsModel) (*datadogV2.GCPSTSServiceAccountCreateRequest, diag.Diagnostics) {
attrs, diags := r.buildIntegrationGcpStsAccountAttributes(ctx, state)
req := datadogV2.NewGCPSTSServiceAccountCreateRequestWithDefaults()
req.Data = datadogV2.NewGCPSTSServiceAccountDataWithDefaults()
req.Data.SetAttributes(*attrs)
return req, diags
}
func (r *integrationGcpStsResource) buildIntegrationGcpStsUpdateRequest(ctx context.Context, state *integrationGcpStsModel) (*datadogV2.GCPSTSServiceAccountUpdateRequest, diag.Diagnostics) {
attrs, diags := r.buildIntegrationGcpStsAccountAttributes(ctx, state)
req := datadogV2.NewGCPSTSServiceAccountUpdateRequestWithDefaults()
req.Data = datadogV2.NewGCPSTSServiceAccountUpdateRequestDataWithDefaults()
req.Data.SetAttributes(*attrs)
return req, diags
}
func (r *integrationGcpStsResource) buildIntegrationGcpStsAccountAttributes(ctx context.Context, state *integrationGcpStsModel) (*datadogV2.GCPSTSServiceAccountAttributes, diag.Diagnostics) {
diags := diag.Diagnostics{}
attributes := datadogV2.NewGCPSTSServiceAccountAttributesWithDefaults()
accountTags := make([]string, 0)
if !state.AccountTags.IsNull() {
diags.Append(state.AccountTags.ElementsAs(ctx, &accountTags, false)...)
}
attributes.SetAccountTags(accountTags)
if !state.Automute.IsNull() {
attributes.SetAutomute(state.Automute.ValueBool())
}
if !state.ClientEmail.IsNull() {
attributes.SetClientEmail(state.ClientEmail.ValueString())
}
if !state.IsCspmEnabled.IsNull() {
attributes.SetIsCspmEnabled(state.IsCspmEnabled.ValueBool())
}
hostFilters := make([]string, 0)
if !state.HostFilters.IsNull() {
diags.Append(state.HostFilters.ElementsAs(ctx, &hostFilters, false)...)
}
attributes.SetHostFilters(hostFilters)
return attributes, diags
}
Weird thing is that I'm pretty sure that the update
API does not support updating ClientEmail
, but it was already in the update
body before these changes 🥴 .
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.
IMO that's pertinent but maybe an a separated PR?
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.
Looks like we mostly took this (thanks), but still we have ClientEmail
in the update
API when that's not supported. Not blocking, but could confuse someone in the future.
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.
Agreed.. But didn't want to make functionally different changes (removal of ClientEmail in the Update call) in a PR that is essentially additive changes.
ba594e9
to
9186396
Compare
Hey @ash-ddog and @dtru-ddog, do you have any updates on this PR? I was about to hand in my own PR for this missing field when I saw that this one already exists. We rely on setting the account tags in one of our configurations that we provision from Terraform. Anything I can do to help this thing be merged? |
I would also like to see that merged, may I help? For the automated tests we can recycle my closed PR #2248 |
…urityCommandCenterEnabled fields, add tests, update docs
"automute": schema.BoolAttribute{ | ||
Optional: true, | ||
Computed: true, | ||
Description: "Silence monitors for expected GCE instance shutdowns.", | ||
Default: booldefault.StaticBool(false), |
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.
Whats the reasoning for this change? This can potentially break existing customers if they set automute
to true in the UI.
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.
Fair enough. Hadn't really considered the case where customers were using both terraform and the UI to manage their configuration. Will remove.
"is_cspm_enabled": schema.BoolAttribute{ | ||
Optional: true, | ||
Computed: true, | ||
Description: "When enabled, Datadog performs configuration checks across your Google Cloud environment by continuously scanning every resource, which may incur additional charges.", | ||
Description: "Whether Datadog collects cloud security posture management resources from your GCP project. If enabled, requires `resource_collection_enabled` to also be enabled.", | ||
Default: booldefault.StaticBool(false), |
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 question here about new default value on TF side. Can we rely on the backend to handle defaults properly since it is already computed-optional field on terraform side?
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 as above
req := datadogV2.NewGCPSTSServiceAccountUpdateRequestWithDefaults() | ||
req.Data = datadogV2.NewGCPSTSServiceAccountUpdateRequestDataWithDefaults() | ||
req.Data.SetAttributes(attributes) | ||
if !state.IsSecurityCommandCenterEnabled.IsNull() { |
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 !state.IsSecurityCommandCenterEnabled.IsNull() { | |
if !state.IsSecurityCommandCenterEnabled.IsUnknown() { |
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.
Nothing blocking but most notable comments
- Do we want to add
CloudRunRevisionFilters
? - Do we need to do
IsUnknown()
forAccountTags
HostFilters types.Set `tfsdk:"host_filters"` | ||
IsCspmEnabled types.Bool `tfsdk:"is_cspm_enabled"` | ||
IsSecurityCommandCenterEnabled types.Bool `tfsdk:"is_security_command_center_enabled"` | ||
ResourceCollectionEnabled types.Bool `tfsdk:"resource_collection_enabled"` |
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.
- What is
DelegateAccountEmail
vsClientEmail
? My guess isDelegateAccountEmail == client_id
andClientEmail == client_email
- Update: read the descriptions below, but still, not sure how
DelegateAccountEmail
can have any affect on the API call we make since it's not a request parameter?
- Update: read the descriptions below, but still, not sure how
- We're missing
cloud_run_revision_filters
here, not sure if that's on purpose or not.
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.
Oh I'm sorry, thought this PR was for our V1 API but it's V2.
But still the comments above are valid.
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.
DelegateAccountEmail is the STS delegate. (Basically, the principal that needs the token creator role on the client Email).
In this schema, it's a computed value that this provider returns (and not as input), mainly to allow setup purely through terraform.
Basically:
- terraform to create GCP service account (including permissions)
- terraform using this module to configure the datadog gcp sts integration (using output from previous)
- terraform to give output of integration (second bullet) the token creator role to the service account in first bullet
Let me know if you have questions
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 have an upcoming task to add cloud_run_revision_filters
.
@@ -71,17 +81,27 @@ func (r *integrationGcpStsResource) Schema(_ context.Context, _ resource.SchemaR | |||
stringplanmodifier.UseStateForUnknown(), | |||
}, | |||
}, | |||
"host_filters": schema.SetAttribute{ | |||
Optional: true, | |||
Description: "Your Host Filters.", |
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.
Kinda nit: might want to be more specific about what this actually is? maybe Filters to be applied for GCE instance resources
or something?
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 just shuffled it (to be ordered alphabetically).. I didn't actually add this description (It exists currently: https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/integration_gcp_sts#host_filters)
We can update it, but can tackle in a separate PR
diags.Append(state.AccountTags.ElementsAs(ctx, &accountTags, false)...) | ||
} | ||
attributes.SetAccountTags(accountTags) | ||
|
||
if !state.Automute.IsNull() { | ||
attributes.SetAutomute(state.Automute.ValueBool()) | ||
} |
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.
Looks like we mostly took this (thanks), but still we have ClientEmail
in the update
API when that's not supported. Not blocking, but could confuse someone in the future.
if !state.AccountTags.IsNull() { | ||
diags.Append(state.AccountTags.ElementsAs(ctx, &accountTags, false)...) | ||
} | ||
attributes.SetAccountTags(accountTags) |
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.
Should we be doing something like the IsUnknown()
for AccountTags
(like we're doing below) since it's also a new field? Not familiar enough with terraform to know what's right here.
Purpose
Attempting to add new fields for gcp sts tf module to utilize and set account tags for customer accounts.