-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate lacework_integration_aws_cfg to use v2 api (#361)
* refactor: migrate lacework_integration_aws_cfg to use v2 api
- Loading branch information
1 parent
e2d2a1f
commit f182648
Showing
12 changed files
with
380 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package integration | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
) | ||
|
||
type awsCredentialsFile struct { | ||
RoleArn string `json:"role_arn"` | ||
ExternalID string `json:"external_id"` | ||
} | ||
|
||
func awsLoadDefaultCredentials() (awsCredentialsFile, error) { | ||
return awsLoadCredentials("AWS_CREDS") | ||
} | ||
|
||
func awsLoadCredentials(envVar string) (c awsCredentialsFile, err error) { | ||
err = json.Unmarshal([]byte(os.Getenv(envVar)), &c) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestIntegrationAwsCfg applies integration terraform: | ||
// => '../examples/resource_lacework_integration_aws_cfg' | ||
// | ||
// It uses the go-sdk to verify the created integration, | ||
// applies an update with new integration name and destroys it | ||
// nolint | ||
func TestIntegrationAwsCfg(t *testing.T) { | ||
awsCreds, err := awsLoadDefaultCredentials() | ||
if assert.Nil(t, err, "this test requires you to set AWS_ECR_IAM environment variable") { | ||
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | ||
TerraformDir: "../examples/resource_lacework_integration_aws_cfg", | ||
Vars: map[string]interface{}{ | ||
"name": "AwsCfg created by terraform", | ||
"role_arn": awsCreds.RoleArn, | ||
"external_id": awsCreds.ExternalID, | ||
}, | ||
}) | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// Create new AwsCfg Integration | ||
create := terraform.InitAndApplyAndIdempotent(t, terraformOptions) | ||
createData := GetCloudAccountAgentlessScanningResponse(create) | ||
actualName := terraform.Output(t, terraformOptions, "name") | ||
assert.Equal( | ||
t, | ||
"AwsCfg created by terraform", | ||
GetCloudAccountIntegrationName(create), | ||
) | ||
assert.Equal(t, "AwsCfg created by terraform", createData.Data.Name) | ||
assert.Equal(t, "AwsCfg created by terraform", actualName) | ||
|
||
// Update AwsCfg Integration | ||
terraformOptions.Vars = map[string]interface{}{ | ||
"name": "AwsCfg updated by terraform", | ||
"role_arn": awsCreds.RoleArn, | ||
"external_id": awsCreds.ExternalID, | ||
} | ||
|
||
update := terraform.ApplyAndIdempotent(t, terraformOptions) | ||
updateData := GetCloudAccountAgentlessScanningResponse(update) | ||
assert.Equal( | ||
t, | ||
"AwsCfg updated", | ||
GetCloudAccountIntegrationName(update), | ||
) | ||
assert.Equal(t, "AwsCfg updated by terraform", updateData.Data.Name) | ||
assert.Equal(t, "AwsCfg updated by terraform", actualName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.