LogoLogo
  • Welcome to Firefly Documentation
  • Introduction
    • What is Firefly?
    • Who is Firefly for?
    • Why use Firefly?
    • Terminology (Glossary)
  • Key Features
    • Infrastructure-as-Code Automation
    • Cloud Asset Inventory
    • Drift Detection & Remediation
    • Policy-as-Code for Compliance & Governance
    • Cost Visibility & Optimization
    • AI Assistant
    • ChatOps Integration
  • Getting Started
    • Account Setup & Onboarding
    • Connecting Cloud Accounts
    • UI Walkthrough & Navigation
    • First Steps in Firefly
  • Detailed Guides
    • Dashboard Overview
    • Cloud Asset Inventory
      • Remediating Drifts
      • Deleting Assets
      • Creating IaC-Ignore Rules
      • Creating Exclude-Drift Rules
    • Policy & Governance
      • Creating Policy-as-Code Governance Rules
      • Remediating Policy Violations
    • Workflows & Guardrails
      • Creating Workflows
      • Creating Guardrail Rules
    • Codification
    • Self-Service
    • IaC Explorer
    • Event Center
    • Backup and Disaster Recovery
    • Notifications
    • User Management
    • SSO Configuration
  • Integrations
    • Integrations Overview
    • Integrating Data Sources
      • AWS
      • Azure
      • Google Cloud
      • Kubernetes
      • Akamai
      • Datadog
      • New Relic
      • Okta
      • GitHub
      • Cloudflare
      • NS1
      • PagerDuty
      • MongoDB Atlas
      • HashiCorp Vault
    • Integrating IaC Remote State
      • Terraform Cloud
      • Google Cloud Storage
      • env0
      • HashiCorp Consul
      • Firefly States Redactor
    • Integrating Version Control
      • GitHub
      • GitLab
      • Azure DevOps
      • CodeCommit
      • Bitbucket
    • Integrating Notifications
      • Slack
      • Microsoft Teams
      • PagerDuty
      • Opsgenie
      • Torq
      • Webex
      • Google Chat
      • Webhook
    • Integrating Project Management
      • Jira
      • ServiceNow
    • Integrating Workflows with CI/CD
    • Integrating Backstage
    • Integrating MCP
  • Use Cases & Best Practices
    • Cloud Governance & Visibility
    • Cost Optimization Strategies
    • Compliance and Security Best Practices
    • Infrastructure Automation & Self-Service
    • Best Practices and Implementation Tips
  • Analytics & Reporting
    • Analytics Dashboard Overview
    • Using Analytics for Improvement
    • Exporting and Sharing Reports
    • Analytics Security and Privacy
  • Code Snippets & Examples
    • Terraform Snippet for an AWS EC2 Instance (Codified via Firefly)
    • Example Rego Policy (OPA) for a Custom Rule
    • GitHub Actions Workflow YAML for Firefly Integration
    • JSON Output Example: Exporting Inventory
  • Troubleshooting & FAQs
    • Common Issues and Solutions
    • FAQs
  • General Information
    • Firefly API
      • Authentication
      • Inventory
      • Codification
      • Workflows
      • Self-Service
      • Policy & Governance
      • IaC Explorer
      • Event Center
      • Backup & Disaster Recovery
      • Notifications
      • Integrations
      • Identity & Access Management
    • Security & Compliance
    • Pricing Tiers & Add-ons
    • Contacting Support
Powered by GitBook
On this page

Was this helpful?

  1. Code Snippets & Examples

Terraform Snippet for an AWS EC2 Instance (Codified via Firefly)

Let's say Firefly identified an unmanaged EC2 instance that you want to codify. Firefly's Codify feature can generate a Terraform snippet for it. Here's an example of what that Terraform code might look like, and how to use it:

resource "aws_instance" "example_server" {
  ami           = "ami-0abcdef1234567890"    # Amazon Linux 2 AMI in region us-east-1 (example)
  instance_type = "t3.micro"
  vpc_security_group_ids = [aws_security_group.example_sg.id]
  subnet_id              = "subnet-1234abcd"
  tags = {
    Name        = "ExampleServer"
    Environment = "Dev"
    Owner       = "team-alpha"
  }
}

Explanation: This Terraform snippet defines an EC2 instance:

  • ami: the machine image ID. Firefly picks the one the instance was using.

  • instance_type: the size (Firefly will use whatever the instance currently is).

  • vpc_security_group_ids and subnet_id: Firefly includes these to place the instance in the correct network. In this example, it references a security group by Terraform resource (assuming you codified that SG too, else Firefly might put the actual SG ID directly or generate a separate aws_security_group resource).

  • tags: Firefly copies any tags from the live instance into code (here Name, Environment, Owner). This ensures continuity of metadata.

How to use it:

  1. Copy this snippet into your Terraform files (possibly into a relevant module or directory).

  2. Add any missing pieces: e.g., in this snippet aws_security_group.example_sg is referenced. You would also codify the security group via Firefly, getting a snippet for it like:

resource "aws_security_group" "example_sg" {
   name        = "example_sg"
   description = "Security group for ExampleServer"
   vpc_id      = "vpc-5678efgh"
   ingress = [ ... ]  # (Firefly will list the current ingress rules)
   egress  = [ ... ]  # (Firefly will list the current egress rules)
   tags = {
      Name = "ExampleServer SG"
   }
}
  1. Place that in the code as well.

  2. Run terraform plan. Terraform should now detect no changes for that instance (since you codified to match reality) or at most minor ones that you might adjust. If everything is good,

  3. Import the existing instance into state: terraform import aws_instance.example_server i-0abcd1234efgh5678. Do the same for security group (and any other dependencies).

  4. After import, run terraform plan again. It should say everything is in sync.

Now your previously unmanaged EC2 is under Terraform control. Firefly will henceforth mark it as Codified.

This process shows how a snippet generated by Firefly is practically used in your workflow. Firefly basically jump-starts your Terraform code, saving manual writing.

PreviousAnalytics Security and PrivacyNextExample Rego Policy (OPA) for a Custom Rule

Last updated 1 month ago

Was this helpful?