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

Update AWS Terraform Modules to configure consolidated CT #32

Closed
afiune opened this issue Jun 17, 2020 · 0 comments · Fixed by #45
Closed

Update AWS Terraform Modules to configure consolidated CT #32

afiune opened this issue Jun 17, 2020 · 0 comments · Fixed by #45

Comments

@afiune
Copy link
Contributor

afiune commented Jun 17, 2020

Useful information to accomplish this task:

https://www.padok.fr/en/blog/terraform-aws-accounts#:~:text=You%20can%20now%20apply%20the,actions%20on%20the%20others%20accounts!

padok.frApply the same Terraform on multiple AWS accountsYou want to apply the same terraform code to several Amazon Web Services (AWS) accounts? Learn how to use IAM to change the terraform provider parameter

https://www.terraform.io/docs/configuration/providers.html#alias-multiple-provider-instances

Terraform by HashiCorp

Providers - Configuration Language - Terraform by HashiCorp

Providers are responsible in Terraform for managing the lifecycle of a resource: create, read, update, delete.

https://www.terraform.io/docs/providers/aws/index.html

Terraform by HashiCorpProvider: AWS - Terraform by HashiCorpThe Amazon Web Services (AWS) provider is used to interact with the many resources supported by AWS. The provider needs to be configured with the proper credentials before it can be used.

Solution Example

provider "aws" {}

provider "lacework" {}

module "aws_config" {
	source = "./modules/config"
}

module "aws_cloudtrail_main" {
	source                = "./modules/cloudtrail"
	bucket_force_destroy  = true
	use_existing_iam_role = true
	iam_role_name         = module.aws_config.iam_role_name
	iam_role_external_id  = module.aws_config.external_id
}

# Additional provider configuration for sub-account 1
provider "aws" {
	alias  = "sub-acocunt-1"
	# Add sub-account 1 creds
}

module "aws_cloudtrail_sub_account_1" {
	provider              = "sub-account-1"
	source                = "./modules/cloudtrail"

	# Use previous cloudtrail S3 bucket and SNS topic
	# but DO create a cloudtrail pointing to those resources
	sub_cloudtrail   = true
	bucket_name      = module.aws_cloudtrail_main.bucket_name
	sns_topic_name   = module.aws_cloudtrail_main.sns_topic_name
}

JIRA: ALLY-90

afiune added a commit that referenced this issue Jun 29, 2020
Closes #32

Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
afiune added a commit that referenced this issue Jun 29, 2020
Closes #32

Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
afiune added a commit that referenced this issue Jun 30, 2020
Closes #32

Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
afiune added a commit that referenced this issue Jun 30, 2020
Closes #32

*Enable New Consolidated CloudTrail Configuration*
This example enables a new Consolidated CloudTrail and IAM Role for Lacework, then configures both integrations with Lacework,
finally, it configures a new CloudTrail in an AWS sub-account that points to the main CloudTrail.

```hcl
provider "lacework" {
  alias = "main"
}

provider "aws" {
  alias = "main"
}

module "main_cloudtrail" {
  source    = "github.com/lacework/terraform-provisioning/aws/modules/cloudtrail"
  providers = {
    aws      = aws.main
    lacework = lacework.main
  }
  consolidated_trail = true
}

provider "aws" {
  alias = "sub_account"
}

resource "aws_cloudtrail" "lw_sub_account_cloudtrail" {
  provider              = aws.sub_account
  name                  = "lacework-sub-trail"
  is_multi_region_trail = true
  s3_bucket_name        = module.main_cloudtrail.bucket_name
  sns_topic_name        = module.main_cloudtrail.sns_arn
}
```

Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
afiune added a commit that referenced this issue Jun 30, 2020
Closes #32

**Enable New Consolidated CloudTrail Configuration**
This example enables a new Consolidated CloudTrail and IAM Role for Lacework,
then configures both integrations with Lacework, finally, it configures a new
CloudTrail in an AWS sub-account that points to the main CloudTrail.

```hcl
provider "lacework" {
  alias = "main"
}

provider "aws" {
  alias = "main"
}

module "main_cloudtrail" {
  source    = "github.com/lacework/terraform-provisioning/aws/modules/cloudtrail"
  providers = {
    aws      = aws.main
    lacework = lacework.main
  }
  consolidated_trail = true
}

provider "aws" {
  alias = "sub_account"
}

resource "aws_cloudtrail" "lw_sub_account_cloudtrail" {
  provider              = aws.sub_account
  name                  = "lacework-sub-trail"
  is_multi_region_trail = true
  s3_bucket_name        = module.main_cloudtrail.bucket_name
  sns_topic_name        = module.main_cloudtrail.sns_arn
}
```

Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
afiune added a commit that referenced this issue Jun 30, 2020
Closes #32

**Enable New Consolidated CloudTrail Configuration**
This example enables a new Consolidated CloudTrail and IAM Role for Lacework,
then configures both integrations with Lacework, finally, it configures a new
CloudTrail in an AWS sub-account that points to the main CloudTrail.

```hcl
provider "lacework" {
  alias = "main"
}

provider "aws" {
  alias = "main"
}

module "main_cloudtrail" {
  source    = "github.com/lacework/terraform-provisioning/aws/modules/cloudtrail"
  providers = {
    aws      = aws.main
    lacework = lacework.main
  }
  consolidated_trail = true
}

provider "aws" {
  alias = "sub_account"
}

resource "aws_cloudtrail" "lw_sub_account_cloudtrail" {
  provider              = aws.sub_account
  name                  = "lacework-sub-trail"
  is_multi_region_trail = true
  s3_bucket_name        = module.main_cloudtrail.bucket_name
  sns_topic_name        = module.main_cloudtrail.sns_arn
}
```

Signed-off-by: Salim Afiune Maya <afiune@lacework.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant