Deploy with Terraform
These instructions help you deploy our AWS Observability Solution using a Terraform script.
To set up the AWS Observability solution using Terraform, complete the following steps described in this documentation.
Additional parameter overrides are available in an appendix section for Source and App Content.
Prerequisites
If you are already collecting AWS metrics, logs, and/or events, we recommend that you override the default settings. By overriding the configuration sources, we prevent them from being re-created in the AWS infrastructure or Sumo Logic.
If you've previously set up our AWS Observability Solution with CloudFormation and want to move to Terraform, we recommend following these instructions (click to expand).
- Start with an existing AWS account and region combination (preferably a non-production dev/test account), delete the AWS Observability CloudFormation stack associated with it, then on-board that account-region combination using Terraform scripts.
- Once you confirm that the solution has been deployed successfully, you can then repeat the process for additional AWS accounts and regions.
- By default, the AWS Observability Apps folder will be available in the personal library and will be shared with the Sumo org of the user that the Sumo Logic access keys belong to.
For this setup, complete the following:
- Set up the AWS CLI.
- Configure AWS CLI to use AWS profiles.
- To use multiple AWS accounts, configure AWS account profiles for each AWS account you want to deploy the AWS Observability solution. The AWS account profile names you create will be used in Step 3: Determine which AWS Account/Regions to Deploy.
- Install Git.
AWS Observability Solution script
The AWS Observability solution script is organized into the following groups of files and folders:
- Main Configuration file: main.auto.tfvars
- The Resource Creation file main.tf internally invokes two modules:
- app-module: This module provides a mechanism to set up all the AWS Observability apps and associated content like Fields, Field Extraction Rules, Metric Rules, apps, monitors and the explore hierarchy in your Sumo Logic account.
- source-module: This module sets up the hosted collector, sources (for logs and metrics) and associated tags to Sumo logic sources as required for the solution.
Using main.tf, only apps can be installed with the "sumo-module" module by keeping the "collection-module" module commented.
System Files:
- versions.tf: Provides the Terraform block that specifies the required provider version and required Terraform version for this configuration. See Lock and Upgrade Provider Versions for more information.
- providers.tf: Provides Terraform configurations to declare the providers they require to have Terraform install and use them. See Providers Configuration Language for more information.
- variables.tf: Provides parameters for a Terraform module, allowing aspects of the module to be customized without altering the module's own source code, and allowing modules to be shared between different configurations. See Input Variables for more information.
- output.tf: Provides specific return values for a Terraform module. See Output Values for more information.
- field.tf: creates fields and FERs in the Sumo Logic field schema
- fields.sh: This script imports the existing fields and FERs (required by AWS Observability Solution) already present in your Sumo Logic account.
Step 1: Set up the Terraform environment
Before you run the Terraform script, perform the following actions on a server machine of your choice:
- Install Terraform version 0.13.0 or later. To check the installed Terraform version, run the following command:
$ terraform --version
- Install the latest version of curl. To check the installed curl version, run the following command:
curl --version
- Install Python version 3.11 or later.
- Install the latest version of jq command-line JSON parser. This is required for running the
fields.sh
batch file. To check the installed jq version, run the following command:jq --version
- Install Sumo Logic Python SDK using the following command. Click here to learn more.
pip install sumologic-sdk
Step 2: Configure the Terraform script
- Clone the repository https://github.com/SumoLogic/sumologic-solution-templates:
$ git clone https://github.com/SumoLogic/sumologic-solution-templates
- Initialize the Terraform working directory by navigating to the directory sumologic-solution-templates/aws-observability-terraform and running:
This will install the required Terraform providers, including Null, Sumo Logic Terraform Provider, AWS Provider, Time Provider, Random Provider.
$ terraform init
noteNote that templates located at sumologic-solution-templates/aws-observability-terraform directory contain references to files from the [sumologic-solution-templates/aws-observability] (https://github.com/SumoLogic/sumologic-solution-templates/tree/master/aws-observability) directory.
- Configure the following mandatory parameters in the main.auto.tfvars file.
sumologic_environment
: This input specifies the Sumo Logic deployment that you want to use. Refer to the Sumo Logic Deployment guide for a list of available deployments. Possible values includeau
,ca
,de
,eu
,jp
,us2
,in
,fed
,kr
, orus1
.sumologic_access_id
: This input specifies the Sumo Logic access ID that you want to use. For more information on how to obtain an access ID, refer to the Access Keys documentation.sumologic_access_key
: Sumo Logic Access Key is used for Sumo Logic API calls.sumologic_organization_id
: Sumo Logic Organization ID You can find your org on the Preferences page in the Sumo Logic UI. For more information, see Preferences Page. Your org ID will be used to configure the IAM Role for Sumo Logic AWS Sources.aws_account_alias
: The Name/Alias for the AWS environment from which you are collecting data. This name will appear in the metrics and and logs. Please leave this blank if you are going to deploy the solution in multiple AWS accounts. Do not include special characters in the alias.
noteSee the variables.tf file and README in that folder for configuration information with permissible values for these variables.
- As part of configuring the AWS Observability solution, we need to create fields and FERs in Sumo Logic org. To import any fields and or FERs that are already present in the Sumo Logic org into our Terraform state, we need to run a script. To do so, navigate to the sumologic-solution-templates/aws-observability-terraform folder and do the following:
- Set the following environment variables using the commands below:
Provide your Sumo Logic deployment for the SUMOLOGIC_ENV variable. For example: au, ca, de, eu, jp, us2, in, fed, kr, or us1. For more information on Sumo Logic deployments, see Sumo Logic Endpoints and Firewall Security.export SUMOLOGIC_ENV="YOUR_SUMOLOGIC_DEPLOYMENT"
export SUMOLOGIC_ACCESSID="YOUR_SUMOLOGIC_ACCESS_ID"
export SUMOLOGIC_ACCESSKEY="YOUR_SUMOLOGIC_ACCESS_KEY"- Run fields.sh using this command:
$ sh fields.sh
Going forward, do not modify these fields outside of Terraform.
Step 3: Determine which AWS Account/Regions to Deploy
You have three options to configure the AWS Account/Region:
- Option 1: Deploy to a single AWS account and region
- Option 2: Deploy to Multiple Regions within an AWS account
- Option 3: Deploy to multiple AWS accounts and regions
This section details how to connect the AWS account profile(s) you set up in your AWS account(s) in a providers.tf file, which will be used to authenticate with your AWS account(s).
Option 1: Deploy to a single AWS account and region
To deploy the AWS Observability Solution for one AWS account and region combination based on an AWS account profile defined in the AWS CLI, configure providers in the providers.tf file.
In the providers.tf file, create a provider for the AWS region you want to monitor AWS services for. This provider will be associated with a profile from the AWS CLI that is associated with an AWS account.
The Terraform script uses "us-east-1" and the active AWS CLI profile by default. If you want to use a different region or another AWS CLI profile, change the providers.tf file as shown in the below. Provide an alias that tells Terraform how to identify this account-region combination.
Task: Example collection setup for the us-east-2 region and for the production AWS account profile.
# Region us-east-2, for AWS Account profile production
provider "aws" {
profile = "production"
region = "us-east-2"
alias = "production-us-east-2"
}
Option 2: Deploy to Multiple Regions within an AWS account
Use this option to install the AWS Observability Solution for multiple regions within a given AWS account. To do so, add providers for each AWS region in the providers.tf as shown below.
Provide alias for account-region
Given that we have multiple providers, we need to provide an alias that tells Terraform how to identify each account-region combination.
-
Comment out the existing provider information in providers.tf.
Comment out using ##provider "aws" {
# region = "us-east-1"
#
# Below properties should be added when you would like to onboard more than one region and account
# More Information regarding AWS Profile can be found at -
#
# Access configuration
#
# profile = <Provide a profile as setup in AWS CLI>
#
# Terraform alias
#
# alias = <Provide a terraform alias for the aws provider. For eg :- production-us-east-1>
#}noteDo not change or remove the provider "sumologic" section:
provider "sumologic" {
environment = var.sumologic_environment
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
admin_mode = var.sumologic_folder_installation_location == "Personal Folder" ? false : true
}admin_mode
with true value will install the app under Admin Recommended folder, and admin_mode with false value will install app in Personal folderadmin_mode
value is automatically set based on the variable "sumologic_folder_installation_location
" which can be overridden at main.tf -
Add a provider for each region, replacing the placeholder content that matches your AWS CLI account profile, AWS region of choice and an alias that tells Terraform how to identify this account-region combination.
noteThe AWS CLI Account profile will be the same across all regions.
Add provider per region# AWS Account profile <AWS_PROFILE_NAME>, Region <REGION>, Alias <ALIAS>
provider "aws" {
profile = "<AWS_PROFILE_NAME>"
region = "<REGION>"
alias = "<ALIAS>"
}Example: Example provider configuration for a production AWS account profile in us-east-1 and us-east-2 regions with the appropriate aliases.
Example configuration# AWS Account profile production, Region us-east-1, Alias production-us-east-1
provider "aws" {
profile = "production"
region = "us-east-1"
alias = "production-us-east-1"
}
# AWS Account profile production, Region us-east-2, Alias production-us-east-2
provider "aws" {
profile = "production"
region = "us-east-2"
alias = "production-us-east-2"
}
Add output code to output.tf
To see the output messages showing you the deployment process, add output code in the output.tf file for each module you added in the later step (Step 4) in the main.tf.
Do not change the output "Apps" section.
output "Apps" {
value = module.sumo-module
description = "All outputs related to apps."
}
-
Add this output code for each module added in the earlier step at the main.tf file, replacing the placeholder module name:
Output code for each moduleoutput "<ALIAS>" {
value = module.<ALIAS>
description = "All outputs related to collection and sources."
}Example: Example output configuration for modules with module names production-us-east-1 and production-us-east-2:
Example out configurationoutput "production-us-east-1" {
value = module.production-us-east-1
description = "All outputs related to collection and sources."
}
output "production-us-east-2" {
value = module.production-us-east-2
description = "All outputs related to collection and sources."
}
Option 3: Deploy to multiple AWS accounts and regions
Use this option to install the AWS Observability Solution for multiple accounts and regions.
Add providers for each AWS account/region combination and configure outputs as shown in the following sections.
Provide Alias each account-region
Given that we have multiple providers, we need to provide an alias that tells Terraform how to identify each account-region combination.
-
Comment out the existing provider information in providers.tf.
Comment out the following using ##provider "aws" {
# region = "us-east-1"
#
# Below properties should be added when you would like to onboard more than one region and account
# More Information regarding AWS Profile can be found at -
#
# Access configuration
#
# profile = <Provide a profile as setup in AWS CLI>
#
# Terraform alias
#
# alias = <Provide a terraform alias for the aws provider. For eg :- production-us-east-1>
#}noteDo not change the output "sumologic" section.
Output sumologicprovider "sumologic" {
environment = var.sumologic_environment
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
admin_mode = var.sumologic_folder_installation_location == "Personal Folder" ? false : true
}admin_mode
with true value will install the app under Admin Recommended folder, and admin_mode with false value will install app in Personal folderadmin_mode
value is automatically set based on the variable "sumologic_folder_installation_location
" which can be overridden at main.tf. -
Add a provider code sample for each account-region combination, replacing the placeholder content for your AWS CLI account profile, AWS region of choice, and an alias that tells Terraform how to identify this account-region combination:
noteThe AWS CLI Account profile has to be the same across all regions.
Add provider for each account-region# Region <REGION>, AWS Account profile <AWS_PROFILE_NAME>, Alias <ALIAS>
provider "aws" {
profile = "<AWS_PROFILE_NAME>"
region = "<REGION>"
alias = "<ALIAS>"
}Example: Example provider configuration for the production AWS account profile in the us-east-1 and us-east-2 regions and a development AWS account profile in the us-west-1 region with the appropriate aliases.
Example out configuration# Region us-east-1, AWS Account profile production
provider "aws" {
profile = "production"
region = "us-east-1"
alias = "production-us-east-1"
}
# Region us-east-2, AWS Account profile production
provider "aws" {
profile = "production"
region = "us-east-2"
alias = "production-us-east-2"
}
# Region us-west-1, AWS Account profile development
provider "aws" {
profile = "development"
region = "us-west-1"
alias = "development-us-west-1"
}
Add collection of output code in output.tf
To see the output messages showing you the provisioning process, add a collection of output code in the output.tf file for each module you added in the later step (Step 4) in the main.tf.
Do not change the output "Apps" section.
output "Apps" {
value = module.sumo-module
description = "All outputs related to apps."
}
-
Add this output code for each module added in the earlier step at the main.tf file, replacing the placeholder module name.
Add Alias per moduleoutput "<ALIAS>" {
value = module.<ALIAS>
description = "All outputs related to collection and sources."
}Example: Example output configuration for modules with module names production-us-east-1, production-us-east-2 and development-us-west-1.
Example out configurationoutput "production-us-east-1" {
value = module.production-us-east-1
description = "All outputs related to collection and sources."
}
output "production-us-east-2" {
value = module.production-us-east-2
description = "All outputs related to collection and sources."
}
output "development-us-west-1" {
value = module.development-us-west-1
description = "All outputs related to collection and sources."
}
Step 4: Configure Providers in the main.tf file
Configure providers for collection using the Terraform source-module.
-
Comment out the existing module "collection-module" section present in the main.tf.
Comment out the following code with #:
#module "collection-module" {
# source = "./source-module"
# aws_account_alias = var.aws_account_alias
# sumologic_organization_id = var.sumologic_organization_id
# access_id = var.sumologic_access_id
# access_key = var.sumologic_access_key
# environment = var.sumologic_environment
#}noteDo not change the module "sumo-module" section unless you want to override.
module "sumo-module" {
source = "./app-modules"
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
environment = var.sumologic_environment
JSON_file_directory_path = dirname(path.cwd)
folder_installation_location = var.sumologic_folder_installation_location
folder_share_with_org = var.sumologic_folder_share_with_org
sumologic_organization_id = var.sumologic_organization_id
} -
Add this module code sample in the main.tf file for the first region provider configured in the providers.tf file, replacing the placeholder content with provider aliases.
The
aws_account_alias
differs depending on Single Account or Multiple Accounts. See the following examples.module "<ALIAS>" {
source = "./source-module"
providers = { aws = aws.<ALIAS> }
aws_account_alias = <var.aws_account_alias OR "account alias">
sumologic_organization_id = var.sumologic_organization_id
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
environment = var.sumologic_environment
}
Single Account
Example module configuration for single account and multiple region config:
Here we have a production AWS account profile in us-east-1 and us-east-2 regions with the provider aliases production-us-east-1 and production-us-east-2.
- Since this is a single account, we can use the global account alias which is defined in var.aws_account_alias.
- A hosted collector is created per AWS account. If you deploy the solution for multiple regions in the same AWS account, you should use the same collector that was created for the first region of the AWS account and for each subsequent region module as shown in the code.
module "production-us-east-1" {
source = "./source-module"
providers = { aws = aws.production-us-east-1 }
aws_account_alias = var.aws_account_alias
sumologic_organization_id = var.sumologic_organization_id
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
environment = var.sumologic_environment
}
module "production-us-east-2" {
source = "./source-module"
providers = { aws = aws.production-us-east-2 }
aws_account_alias = var.aws_account_alias
sumologic_organization_id = var.sumologic_organization_id
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
environment = var.sumologic_environment
# Use the same collector created for the first region of the production account.
sumologic_existing_collector_details = {
create_collector = false
collector_id = module.production-us-east-1.sumologic_collector["collector"].id
}
}
Multiple Accounts
Example module configuration for configuring multiple accounts in multiple regions:
Here we have a production AWS account profile in us-east-1 and us-east-2 regions with the provider aliases production-us-east-1 and production-us-east-2 and a development AWS account profile in us-west-1 with the provider alias development-us-west-1.
- In this case the AWS Account alias for each account/region module needs to be specified within the module via the parameter aws_account_alias. The variable var.aws_account_alias is not used in this case.
- A hosted collector is created per AWS account. If you deploy the solution for multiple regions in the same account, you should use the same collector that was created for the first region of the account for each subsequent region module as shown in the code.
- For each new AWS account, ensure you create a new hosted collector for first region and then reuse the same collector created within given AWS account for subsequent regions.
module "production-us-east-1" {
source = "./source-module"
providers = { aws = aws.production-us-east-1 }
aws_account_alias = "production-us-east-1"
sumologic_organization_id = var.sumologic_organization_id
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
environment = var.sumologic_environment
}
module "production-us-east-2" {
source = "./source-module"
providers = { aws = aws.production-us-east-2 }
aws_account_alias = "production-us-east-1"
sumologic_organization_id = var.sumologic_organization_id
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
environment = var.sumologic_environment
# Use the same collector created for the first region of the production account.
sumologic_existing_collector_details = {
create_collector = false
collector_id = module.production-us-east-1.sumologic_collector["collector"].id
}
}
module "development-us-west-1" {
source = "./source-module"
providers = { aws = aws.development-us-west-1}
aws_account_alias = "development-us-west-1"
sumologic_organization_id = var.sumologic_organization_id
access_id = var.sumologic_access_id
access_key = var.sumologic_access_key
environment = var.sumologic_environment
}
Step 5: Override Default Parameter Values
By default, all other parameters are set up to automatically collect logs, metrics, install apps and monitors. If you need to override parameters, you can configure or override additional parameters in the sumologic-solution-templates/aws-observability-terraform/main.tf file for Collection and app parameters. To perform overrides, see Override Collection Parameters and Override Content Parameters.
Step 6: Deploy the AWS Observability Solution
Deploy the AWS Observability Solution using the Sumo Logic Terraform Script.
Navigate to the directory sumologic-solution-templates/aws-observability-terraform and execute the following commands:
Before you run these commands, make sure you have configured your AWS profiles on your system as mentioned in the Prerequisites.
$ terraform validate
$ terraform plan
$ terraform apply
Uninstalling the Solution
To uninstall the AWS Observability solution deployed using Terraform, navigate to the directory sumologic-solution-templates/aws-observability-terraform and execute the command:
$ terraform destroy
This will destroy all resources and configuration previously set up.
Migration Strategy from CloudWatch Source to Kinesis Firehose Source using Terraform
To migrate CloudWatch Source to Kinesis Firehose Source using Terraform, refer to Migration Strategy using Terraform.