Easily analyze (emotional) sentiment of Tweets using Google Cloud and HashiCorp Terraform
This repository contains Terraform Resources to deploy a Google Workflow for Twitter Sentiment Analysis.
To use this code, clone the repository and initialize Terraform:
cd twitter-sentiment-analysis-with-terraform
terraform init
The init command will fetch all required Terraform Providers.
Next, execute a plan:
terraform plan
Note: The code is set up to use GCP Organization IDs. If your setup requires Folder IDs, change
maint.tf
andvariables.tf
in the appropriate locations.
If the preview looks good, you can deploy the resources using the apply command:
terraform apply
When Terraform finishes the apply
process, several Outputs will be displayed.
These Outputs contain URLs for the Google Cloud Console:
Outputs:
url_project_settings = "console.cloud.google.com/iam-admin/settings"
url_service_account_detail = "console.cloud.google.com/iam-admin/serviceaccounts/details"
url_service_account_overview = "console.cloud.google.com/iam-admin/serviceaccounts"
url_workflow_details = "console.cloud.google.com/workflows/workflow/us-central1/twitter-sentiment/executions"
url_workflow_execution = "console.cloud.google.com/workflows/workflow/us-central1/twitter-sentiment/create_execution"
url_workflows_overview = "console.cloud.google.com/workflows"
Note: The URLs will be specific to your account and will include Organization and Project IDs.
Find the Output with key url_workflow_execution
and open the generated URL in a browser to display the Workflow Execution interface:
In this interface, add the following configuration as Input:
{
"bearerToken": "AAA...2Ho",
"twitterHandle": "ksatirli",
"maxResults": "100"
}
Modify the Input payload to reflect your situation:
- Replace the value of
bearerToken
with an active Twitter App Bearer Token. - Replace the value of
twitterHandle
with a relevant Twitter Handle. - Adjust the value of
maxResults
, keeping in mind that the allowed range is 10 to 100.
Next, execute the Workflow by clicking the blue EXECUTE button at the bottom.
After the Workflow has completed, the Output will display the calculated values:
{
"averageSentiment": 0.25,
"minSentimentIndex": 2,
"minSentimentScore": -0.1,
"numberOfTweets": 5,
"totalSentimentScore": 1.5
}
-
For an overview of all input variables and output values, see docs/inputs-and-outputs.md.
-
The code in this repository is based on work done by Google Developer Advocates @meteatamel and @KrisBraun as part of a blog post highlighting new Workflow processing capabilities.
This repository is maintained by the contributors listed on GitHub.
Licensed under the Apache License, Version 2.0 (the "License").
You may obtain a copy of the License at apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, without WARRANTIES or conditions of any kind, either express or implied.
See the License for the specific language governing permissions and limitations under the License.