Skip to content

Commit

Permalink
feat(AwsEksAudit): Add support for AwsEksAudit apiv2 cloud account in…
Browse files Browse the repository at this point in the history
…tegration (#292)

* feat(AwsEksAudit): Add support for AwsEksAudit apiv2 cloud account integration

Signed-off-by: Ross <[email protected]>
  • Loading branch information
rmoles authored Apr 1, 2022
1 parent b6f3297 commit 4db5abe
Show file tree
Hide file tree
Showing 51 changed files with 635 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.16.0
1.18.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Further [usage documentation is available on the Terraform website](https://www.
Developing the Provider
---------------------------

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.18+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.

To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.

Expand Down
53 changes: 53 additions & 0 deletions examples/resource_lacework_integration_aws_eks_audit_log/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
terraform {
required_providers {
lacework = {
source = "lacework/lacework"
}
}
}

variable "name" {
type = string
default = "AWS EKS audit log integration example"
}

variable "sns_arn" {
type = string
default = "arn:aws:sns:us-west-2:123456789123:foo-lacework-eks"
}

variable "external_id" {
type = string
default = "12345"
}

variable "role_arn" {
type = string
default = "arn:aws:iam::249446771485:role/lacework-iam-example-role"
}

resource "lacework_integration_aws_eks_audit_log" "example" {
name = var.name
sns_arn = var.sns_arn
credentials {
role_arn = var.role_arn
external_id = var.external_id
}
retries = 10
}

output "name" {
value = lacework_integration_aws_eks_audit_log.example.name
}

output "sns_arn" {
value = lacework_integration_aws_eks_audit_log.example.sns_arn
}

output "role_arn" {
value = lacework_integration_aws_eks_audit_log.example.credentials[0].role_arn
}

output "external_id" {
value = lacework_integration_aws_eks_audit_log.example.credentials[0].external_id
}
23 changes: 23 additions & 0 deletions integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ func lwOrgTestClient() (lw *api.Client) {
return
}

func GetCloudAccountIntegrationName(result string) string {
var res api.CloudAccountResponse
id := GetIDFromTerraResults(result)

err := LwClient.V2.CloudAccounts.Get(id, &res)
if err != nil {
log.Fatalf("Unable to find integration id: %s\n Response: %v", id, res)
}

return res.Data.Name
}

func GetCloudAccountEksAuditLogData(result string) api.AwsEksAuditData {
id := GetIDFromTerraResults(result)

response, err := LwClient.V2.CloudAccounts.GetAwsEksAudit(id)
if err != nil {
log.Fatalf("Unable to find eks audit log id: %s\n Response: %v", id, response)
}

return response.Data.Data
}

func GetIntegrationName(result string, integration string) string {
var res api.V2CommonIntegration
id := GetIDFromTerraResults(result)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package integration

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)

// TestIntegrationAwsEksAuditLog applies integration terraform:
// => '../examples/resource_lacework_integration_aws_eks_audit_log'
//
// It uses the go-sdk to verify the created integration,
// applies an update with new integration name and destroys it
func TestIntegrationAwsEksAuditLog(t *testing.T) {
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples/resource_lacework_integration_aws_eks_audit_log",
Vars: map[string]interface{}{
"role_arn": "arn:aws:iam::249446771485:role/lacework-iam-example-role",
"external_id": "12345",
"sns_arn": "arn:aws:sns:us-west-2:123456789123:foo-lacework-eks",
},
})
defer terraform.Destroy(t, terraformOptions)

// Create new AwsEksAudit Integration
create := terraform.InitAndApplyAndIdempotent(t, terraformOptions)
createData := GetCloudAccountEksAuditLogData(create)
actualRoleArn := terraform.Output(t, terraformOptions, "role_arn")
actualExternalId := terraform.Output(t, terraformOptions, "external_id")
actualSnsArn := terraform.Output(t, terraformOptions, "sns_arn")
assert.Equal(
t,
"AWS EKS audit log integration example",
GetCloudAccountIntegrationName(create),
)
assert.Equal(t, "arn:aws:iam::249446771485:role/lacework-iam-example-role", createData.Credentials.RoleArn)
assert.Equal(t, "12345", createData.Credentials.ExternalID)
assert.Equal(t, "arn:aws:sns:us-west-2:123456789123:foo-lacework-eks", createData.SnsArn)
assert.Equal(t, "arn:aws:iam::249446771485:role/lacework-iam-example-role", actualRoleArn)
assert.Equal(t, "12345", actualExternalId)
assert.Equal(t, "arn:aws:sns:us-west-2:123456789123:foo-lacework-eks", actualSnsArn)

// Update AwsEksAudit Integration
terraformOptions.Vars = map[string]interface{}{
"name": "AwsEksAudit log integration updated",
"role_arn": "arn:aws:iam::249446771485:role/lacework-iam-example-role",
"external_id": "12345",
"sns_arn": "arn:aws:sns:us-west-2:123456789123:foo-lacework-eks",
}

update := terraform.ApplyAndIdempotent(t, terraformOptions)
updateData := GetCloudAccountEksAuditLogData(update)
actualRoleArn = terraform.Output(t, terraformOptions, "role_arn")
actualExternalId = terraform.Output(t, terraformOptions, "external_id")
actualSnsArn = terraform.Output(t, terraformOptions, "sns_arn")
assert.Equal(
t,
"AwsEksAudit log integration updated",
GetCloudAccountIntegrationName(update),
)
assert.Equal(t, "arn:aws:iam::249446771485:role/lacework-iam-example-role", updateData.Credentials.RoleArn)
assert.Equal(t, "12345", updateData.Credentials.ExternalID)
assert.Equal(t, "arn:aws:sns:us-west-2:123456789123:foo-lacework-eks", updateData.SnsArn)
assert.Equal(t, "arn:aws:iam::249446771485:role/lacework-iam-example-role", actualRoleArn)
assert.Equal(t, "12345", actualExternalId)
assert.Equal(t, "arn:aws:sns:us-west-2:123456789123:foo-lacework-eks", actualSnsArn)
}
1 change: 1 addition & 0 deletions lacework/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func Provider() *schema.Provider {
"lacework_alert_rule": resourceLaceworkAlertRule(),
"lacework_integration_aws_cfg": resourceLaceworkIntegrationAwsCfg(),
"lacework_integration_aws_ct": resourceLaceworkIntegrationAwsCloudTrail(),
"lacework_integration_aws_eks_audit_log": resourceLaceworkIntegrationAwsEksAuditLog(),
"lacework_integration_aws_govcloud_cfg": resourceLaceworkIntegrationAwsGovCloudCfg(),
"lacework_integration_aws_govcloud_ct": resourceLaceworkIntegrationAwsGovCloudCT(),
"lacework_integration_azure_cfg": resourceLaceworkIntegrationAzureCfg(),
Expand Down
22 changes: 11 additions & 11 deletions lacework/resource_lacework_integration_aws_ct.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import (
"github.com/lacework/go-sdk/api"
)

func resourceLaceworkIntegrationAwsCloudTrail() *schema.Resource {
return &schema.Resource{
Create: resourceLaceworkIntegrationAwsCloudTrailCreate,
Read: resourceLaceworkIntegrationAwsCloudTrailRead,
Update: resourceLaceworkIntegrationAwsCloudTrailUpdate,
Delete: resourceLaceworkIntegrationAwsCloudTrailDelete,
Schema: awsCloudTrailIntegrationSchema,
Importer: &schema.ResourceImporter{State: importLaceworkIntegration},
}
}

var awsCloudTrailIntegrationSchema = map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -111,17 +122,6 @@ var awsCloudTrailIntegrationSchema = map[string]*schema.Schema{
},
}

func resourceLaceworkIntegrationAwsCloudTrail() *schema.Resource {
return &schema.Resource{
Create: resourceLaceworkIntegrationAwsCloudTrailCreate,
Read: resourceLaceworkIntegrationAwsCloudTrailRead,
Update: resourceLaceworkIntegrationAwsCloudTrailUpdate,
Delete: resourceLaceworkIntegrationAwsCloudTrailDelete,
Schema: awsCloudTrailIntegrationSchema,
Importer: &schema.ResourceImporter{State: importLaceworkIntegration},
}
}

func resourceLaceworkIntegrationAwsCloudTrailCreate(d *schema.ResourceData, meta interface{}) error {
var (
lacework = meta.(*api.Client)
Expand Down
Loading

0 comments on commit 4db5abe

Please sign in to comment.