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

refactor: remove last usages of v1 api #397

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions lacework/cloud_account_importer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lacework

import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/lacework/go-sdk/api"
)

func importLaceworkCloudAccount(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
lacework := meta.(*api.Client)
var response api.CloudAccountResponse

log.Printf("[INFO] Importing Lacework Cloud Account with guid: %s\n", d.Id())
err := lacework.V2.CloudAccounts.Get(d.Id(), &response)
if err != nil {
return nil, err
}

if response.Data.IntgGuid == d.Id() {
log.Printf("[INFO] Cloud Account integration found using APIv2 with guid: %v\n", response.Data.IntgGuid)
return []*schema.ResourceData{d}, nil
}

log.Printf("[INFO] Raw APIv2 Cloud Account response: %v\n", response)
return []*schema.ResourceData{d}, nil
}
29 changes: 29 additions & 0 deletions lacework/container_registry_importer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package lacework

import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/lacework/go-sdk/api"
)

func importLaceworkContainerRegistry(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
lacework := meta.(*api.Client)
var response api.ContainerRegistryResponse

log.Printf("[INFO] Importing Lacework Container Registry with guid: %s\n", d.Id())
err := lacework.V2.CloudAccounts.Get(d.Id(), &response)
if err != nil {
return nil, err
}

if response.Data.IntgGuid == d.Id() {
log.Printf("[INFO] Container Registry found using APIv2 with guid: %v\n", response.Data.IntgGuid)
return []*schema.ResourceData{d}, nil
}

log.Printf("[INFO] Raw APIv2 Container Registry response: %v\n", response)

return []*schema.ResourceData{d}, nil
}
41 changes: 0 additions & 41 deletions lacework/integration_importer.go

This file was deleted.

16 changes: 7 additions & 9 deletions lacework/resource_lacework_agent_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,19 @@ func importLaceworkAgentAccessToken(d *schema.ResourceData, meta interface{}) ([
lacework := meta.(*api.Client)

log.Printf("[INFO] Importing agent access token.")
response, err := lacework.Agents.GetToken(d.Id())
response, err := lacework.V2.AgentAccessTokens.Get(d.Id())
if err != nil {
return nil, err
}

for _, token := range response.Data {
if token.AccessToken == d.Id() {
log.Printf("[INFO] agent access token found. name=%s, description=%s, enabled=%t",
token.TokenAlias, token.Props.Description, token.Status())
if response.Data.AccessToken == d.Id() {
log.Printf("[INFO] agent access token found. name=%s, description=%s, enabled=%t",
response.Data.TokenAlias, response.Data.Props.Description, response.Data.State())

d.Set("token", token.AccessToken)
d.SetId(token.TokenAlias)
d.Set("token", response.Data.AccessToken)
d.SetId(response.Data.TokenAlias)

return []*schema.ResourceData{d}, nil
}
return []*schema.ResourceData{d}, nil
}

log.Printf("[INFO] Raw response: %v\n", response)
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_aws_cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceLaceworkAlertChannelAwsCloudWatch() *schema.Resource {
Delete: resourceLaceworkAlertChannelAwsCloudWatchDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_aws_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func resourceLaceworkAlertChannelAwsS3() *schema.Resource {
Delete: resourceLaceworkAlertChannelAwsS3Delete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},
Schema: map[string]*schema.Schema{
"name": {
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_cisco_webex.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func resourceLaceworkAlertChannelCiscoWebex() *schema.Resource {
Delete: resourceLaceworkAlertChannelCiscoWebexDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func resourceLaceworkAlertChannelDatadog() *schema.Resource {
Delete: resourceLaceworkAlertChannelDatadogDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceLaceworkAlertChannelEmail() *schema.Resource {
Delete: resourceLaceworkAlertChannelEmailDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func resourceLaceworkAlertChannelSlack() *schema.Resource {
Delete: resourceLaceworkAlertChannelSlackDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_victorops.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func resourceLaceworkAlertChannelVictorOps() *schema.Resource {
Delete: resourceLaceworkAlertChannelVictorOpsDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_alert_channel_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func resourceLaceworkAlertChannelWebhook() *schema.Resource {
Delete: resourceLaceworkAlertChannelWebhookDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkAlertChannel,
},

Schema: map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func resourceLaceworkIntegrationAwsAgentlessScanning() *schema.Resource {
Update: resourceLaceworkIntegrationAwsAgentlessScanningUpdate,
Delete: resourceLaceworkIntegrationAwsAgentlessScanningDelete,
Schema: awsAgentlessScanningIntegrationSchema,
Importer: &schema.ResourceImporter{State: importLaceworkIntegration},
Importer: &schema.ResourceImporter{State: importLaceworkCloudAccount},
}
}

Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_aws_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationAwsCfg() *schema.Resource {
Delete: resourceLaceworkIntegrationAwsCfgDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkCloudAccount,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_aws_ct.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationAwsCloudTrail() *schema.Resource {
Update: resourceLaceworkIntegrationAwsCloudTrailUpdate,
Delete: resourceLaceworkIntegrationAwsCloudTrailDelete,
Schema: awsCloudTrailIntegrationSchema,
Importer: &schema.ResourceImporter{State: importLaceworkIntegration},
Importer: &schema.ResourceImporter{State: importLaceworkCloudAccount},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func resourceLaceworkIntegrationAwsEksAuditLog() *schema.Resource {
Update: resourceLaceworkIntegrationAwsEksAuditLogUpdate,
Delete: resourceLaceworkIntegrationAwsEksAuditLogDelete,
Schema: awsEksAuditLogIntegrationSchema,
Importer: &schema.ResourceImporter{State: importLaceworkIntegration},
Importer: &schema.ResourceImporter{State: importLaceworkCloudAccount},
}
}

Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_aws_govcloud_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationAwsGovCloudCfg() *schema.Resource {
Delete: resourceLaceworkIntegrationAwsGovCloudCfgDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkCloudAccount,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_aws_govcloud_ct.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationAwsGovCloudCT() *schema.Resource {
Delete: resourceLaceworkIntegrationAwsGovCloudCTDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkCloudAccount,
},

Schema: map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationAwsOrgAgentlessScanning() *schema.Resource {
Update: resourceLaceworkIntegrationAwsOrgAgentlessScanningUpdate,
Delete: resourceLaceworkIntegrationAwsOrgAgentlessScanningDelete,
Schema: awsOrgAgentlessScanningIntegrationSchema,
Importer: &schema.ResourceImporter{State: importLaceworkIntegration},
Importer: &schema.ResourceImporter{State: importLaceworkCloudAccount},
}
}

Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_azure_al.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationAzureActivityLog() *schema.Resource {
Delete: resourceLaceworkIntegrationAzureActivityLogDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkCloudAccount,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_azure_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationAzureCfg() *schema.Resource {
Delete: resourceLaceworkIntegrationAzureCfgDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkCloudAccount,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_docker_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceLaceworkIntegrationDockerHub() *schema.Resource {
Delete: resourceLaceworkIntegrationDockerHubDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkContainerRegistry,
},

Schema: map[string]*schema.Schema{
Expand Down
4 changes: 2 additions & 2 deletions lacework/resource_lacework_integration_docker_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceLaceworkIntegrationDockerV2() *schema.Resource {
Delete: resourceLaceworkIntegrationDockerV2Delete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkContainerRegistry,
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -240,7 +240,7 @@ func resourceLaceworkIntegrationDockerV2Delete(d *schema.ResourceData, meta inte

log.Printf("[INFO] Deleting %s registry type with guid: %v\n", api.DockerhubV2ContainerRegistry.String(), d.Id())

_, err := lacework.Integrations.Delete(d.Id())
err := lacework.V2.ContainerRegistries.Delete(d.Id())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions lacework/resource_lacework_integration_ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func resourceLaceworkIntegrationEcrUpdate(d *schema.ResourceData, meta interface
log.Println("[WARN] Change of authentication method detected. Need destroy and recreation")
log.Printf("[INFO] Deleting %s integration %s registry type with guid: %v\n",
api.ContainerRegistryIntegration.String(), api.EcrRegistry.String(), d.Id())
_, err := lacework.Integrations.Delete(d.Id())
err := lacework.V2.ContainerRegistries.Delete(d.Id())
if err != nil {
return err
}
Expand All @@ -284,7 +284,7 @@ func resourceLaceworkIntegrationEcrUpdate(d *schema.ResourceData, meta interface
log.Println("[WARN] Change of authentication method detected. Need destroy and recreation")
log.Printf("[INFO] Deleting %s integration %s registry type with guid: %v\n",
api.ContainerRegistryIntegration.String(), api.EcrRegistry.String(), d.Id())
_, err := lacework.Integrations.Delete(d.Id())
err := lacework.V2.ContainerRegistries.Delete(d.Id())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_gar.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func resourceLaceworkIntegrationGar() *schema.Resource {
Delete: resourceLaceworkIntegrationGarDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkContainerRegistry,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_gcp_at.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func resourceLaceworkIntegrationGcpAt() *schema.Resource {
Delete: resourceLaceworkIntegrationGcpAtDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkCloudAccount,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_gcp_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func resourceLaceworkIntegrationGcpCfg() *schema.Resource {
Delete: resourceLaceworkIntegrationGcpCfgDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkCloudAccount,
},

Schema: map[string]*schema.Schema{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceLaceworkIntegrationGcpGkeAuditLog() *schema.Resource {
Update: resourceLaceworkIntegrationGcpGkeAuditLogUpdate,
Delete: resourceLaceworkIntegrationGcpGkeAuditLogDelete,
Schema: gcpGkeAuditLogIntegrationSchema,
Importer: &schema.ResourceImporter{State: importLaceworkIntegration},
Importer: &schema.ResourceImporter{State: importLaceworkCloudAccount},
}
}

Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_gcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func resourceLaceworkIntegrationGcr() *schema.Resource {
Delete: resourceLaceworkIntegrationGcrDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkContainerRegistry,
},

Schema: map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion lacework/resource_lacework_integration_ghcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceLaceworkIntegrationGhcr() *schema.Resource {
Delete: resourceLaceworkIntegrationGhcrDelete,

Importer: &schema.ResourceImporter{
State: importLaceworkIntegration,
State: importLaceworkContainerRegistry,
},

Schema: map[string]*schema.Schema{
Expand Down