-
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
[logs][archives] Add Resource #544
[logs][archives] Add Resource #544
Conversation
f80b036
to
3b4779d
Compare
Hi, Thanks for this PR. Any reasons why we have to use your mocking system instead of the one already in place ? |
96dd85d
to
3f4dd0e
Compare
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.
Great job! This is pretty solid already. I added comments for some nitpic and common practices.
|
||
func buildAzureMap(destination datadogV2.LogsArchiveDestinationAzure) map[string]interface{} { | ||
result := make(map[string]interface{}) | ||
result["client_id"] = destination.Integration.ClientId |
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.
Could we use Getter instead? (here and similar places)
} | ||
|
||
//Map to model | ||
func buildDatadogArchiveCreateReq(d *schema.ResourceData) (datadogV2.LogsArchiveCreateRequest, error) { |
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.
Let's return pointers whenever possible
} | ||
|
||
func buildCreateReqDestination(d *schema.ResourceData) (datadogV2.LogsArchiveCreateRequestDestination, error) { | ||
emptyDestination := datadogV2.LogsArchiveCreateRequestDestination{} |
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.
Would it be possible to use datadogV2.New...
methods instead (here and similar places)
return defined | ||
} | ||
|
||
var buildCreateReqDestinationByTypeFunctions = map[string]func(map[string]interface{}) (datadogV2.LogsArchiveCreateRequestDestination, error){ |
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 variable is only used in one place. Do we need to keep this as a variable?
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 agree, we don't need it. I'll move that back to the only place where it is called.
if !ok { | ||
return &datadogV2.LogsArchiveDestinationAzure{}, fmt.Errorf("tenant_id is not defined") | ||
} | ||
integration := datadogV2.LogsArchiveIntegrationAzure{ |
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.
Let try to use New
methods as much as possible
httpClient := &http.Client{Transport: logging.NewTransport("Datadog", rec)} | ||
datadogClientV1 := buildDatadogClientV1(httpClient) | ||
datadogClientV1.GetConfig().Debug = true | ||
authV1, err := buildAuthV1(os.Getenv("DD_API_KEY"), os.Getenv("DD_APP_KEY"), os.Getenv("DD_HOST")) | ||
if err != nil { | ||
t.Fatalf("Error creating Datadog Client context: %s", err) | ||
} | ||
var testAzureAcct = datadogV1.AzureAccount{ | ||
ClientId: datadogV1.PtrString("testc7f6-1234-5678-9101-3fcbf464test"), | ||
ClientSecret: datadogV1.PtrString("testingx./Sw*g/Y33t..R1cH+hScMDt"), | ||
TenantName: datadogV1.PtrString("my-tenant-id"), | ||
} | ||
_, _, err = datadogClientV1.AzureIntegrationApi.CreateAzureIntegration(authV1).Body(testAzureAcct).Execute() | ||
if err != nil { | ||
t.Fatalf("Error creating Azure Account: Response %s: %v", err.(datadogV1.GenericOpenAPIError).Body(), err) | ||
} | ||
defer deleteAzureIntegration(t, datadogClientV1, authV1, testAzureAcct) | ||
|
||
accProviders := testAccProvidersWithHttpClient(t, httpClient) | ||
accProvider := testAccProvider(t, accProviders) |
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.
Let's add comments here in order to explain what we are doing here and why
} | ||
|
||
// readFixture opens the file at path and returns the contents as a string | ||
func readFixture(t *testing.T, path string) string { |
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.
Do we still need fixture now?
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.
You're right, this is no longer required. I will clean it up.
func buildAzureDestination(d map[string]interface{}) (*datadogV2.LogsArchiveDestinationAzure, error) { | ||
clientId, ok := d["client_id"] | ||
if !ok { | ||
return &datadogV2.LogsArchiveDestinationAzure{}, fmt.Errorf("client_id is not defined") |
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 just return nil instead of an object here and below?
func buildGCSDestination(d map[string]interface{}) (*datadogV2.LogsArchiveDestinationGCS, error) { | ||
clientEmail, ok := d["client_email"] | ||
if !ok { | ||
return &datadogV2.LogsArchiveDestinationGCS{}, fmt.Errorf("client_email is not defined") |
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 as above
rec := initRecorder(t) | ||
defer rec.Stop() | ||
httpClient := &http.Client{Transport: logging.NewTransport("Datadog", rec)} | ||
// At the moment there's no azure integration in tf so we manually: |
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 wait for https://github.com/terraform-providers/terraform-provider-datadog/pull/556 ?
name = "my first gcs archive" | ||
query = "service:tata" | ||
gcs = { | ||
bucket = "dd-logs-test-datadog-api-client-go" |
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.
Let's clean the indentation
name = "my first s3 archive" | ||
query = "service:tutu" | ||
s3 = { | ||
bucket = "my-bucket" |
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
* `client_email` - (Required) Your client email. | ||
* `project_id` - (Required) Your project id. | ||
* `azure` - (Optional) Definition of an azure archive. | ||
storage_account = "storageAccount" |
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.
is this intended?
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.
Not really, I will fix it.
name = "my first s3 archive after update" | ||
query = "service:tutu" | ||
s3 = { | ||
bucket = "my-bucket" |
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.
indentation
878a143
to
1463897
Compare
Related to https://github.com/terraform-providers/terraform-provider-datadog/issues/466