iac-eval-v2/iac-eval-v2 huggingface dataset:
# Task 361


Generate an AWS Lightsail instance with auto snapshots enabled in the `eu-west-1` region (use availability zone `eu-west-1a`).

## Intent

have one "aws_lightsail_instance" resource
with "name" argument
with "availability_zone" argument
with "blueprint_id" argument
with "bundle_id" argument
with "add_on" argument
    with type = "AutoSnapshot"
    with snapshot_time argument
    with status = "Enabled"

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region     = "eu-west-1"
}

resource "aws_lightsail_instance" "test" {
  name              = "custom_instance"
  availability_zone = "eu-west-1a"
  blueprint_id      = "amazon_linux_2"
  bundle_id         = "nano_2_0"
  add_on {
    type          = "AutoSnapshot"
    snapshot_time = "06:00"
    status        = "Enabled"
  }
  tags = {
    foo = "bar"
  }
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default is_valid_lightsail_instance = false

is_valid_lightsail_instance if {
    resource := input.planned_values.root_module.resources[_]
    resource.type == "aws_lightsail_instance"
    has_required_arguments(resource.values)
    has_valid_add_on(resource.values.add_on)
}

has_required_arguments(values) if {
    values.name
    values.availability_zone
    values.blueprint_id
    values.bundle_id
}

has_valid_add_on(add_ons) if {
    add_on := add_ons[_]
    add_on.type == "AutoSnapshot"
    add_on.snapshot_time
    add_on.status == "Enabled"
}

main if {
    is_valid_lightsail_instance
}
# Task 362


Create an AWS Lightsail instance with default blueprint in the `eu-west-1` region (use availability zone `eu-west-1a`).

## Intent

have one "aws_lightsail_instance" resource
with "name" argument
with "availability_zone" argument
with "blueprint_id" argument
with "bundle_id" argument

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region     = "eu-west-1"
}

resource "aws_lightsail_instance" "gitlab_test" {
  name              = "custom_gitlab"
  availability_zone = "eu-west-1a"
  blueprint_id      = "amazon_linux_2"
  bundle_id         = "nano_2_0"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default is_valid_lightsail_instance = false

is_valid_lightsail_instance if {
    resource := input.planned_values.root_module.resources[_]
    resource.type == "aws_lightsail_instance"
    has_required_arguments(resource.values)
}

has_required_arguments(values) if {
    values.name
    values.availability_zone
    values.blueprint_id
    values.bundle_id
}

main if {
    is_valid_lightsail_instance
}
# Task 363


Create an AWS Lightsail instance with WordPress blueprint in the `eu-west-1` region (use availability zone `eu-west-1a`).

## Intent

have one "aws_lightsail_instance" resource
with "name" argument
with "availability_zone" argument
with "blueprint_id" = wordpress
with "bundle_id" argument

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region     = "eu-west-1"
}

resource "aws_lightsail_instance" "custom" {
  name              = "custom"
  availability_zone = "eu-west-1a"
  blueprint_id      = "wordpress"
  bundle_id         = "nano_2_0"
 }


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_instance = false

# Main rule to check for a valid aws_lightsail_instance
has_valid_lightsail_instance if {
    resource := input.planned_values.root_module.resources[_]
    resource.type == "aws_lightsail_instance"
    resource.values.name
    resource.values.availability_zone
    resource.values.blueprint_id == "wordpress"
    resource.values.bundle_id
}

main if {
    has_valid_lightsail_instance
}
# Task 365


Create an Amazon Lightsail instance with dualstack IP in the `eu-west-1` region (use availability zone `eu-west-1a`).

## Intent

have one "aws_lightsail_instance" resource
    with "name" argument
    with "availability_zone" argument
    with "blueprint_id" argument
    with "bundle_id" argument
    with "ip_address_type" = "dualstack"

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region = "eu-west-1"
}

resource "aws_lightsail_instance" "custom" {
  name              = "custom"
  availability_zone = "eu-west-1a"
  blueprint_id      = "wordpress"
  bundle_id         = "nano_2_0"
  ip_address_type = "dualstack"
 }


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_instance = false

# Main rule to check for a valid aws_lightsail_instance with specific arguments
has_valid_lightsail_instance if {
    resource := input.planned_values.root_module.resources[_]
    resource.type == "aws_lightsail_instance"
    resource.values.name
    resource.values.availability_zone
    resource.values.blueprint_id
    resource.values.bundle_id
    resource.values.ip_address_type == "dualstack"
}

main if {
    has_valid_lightsail_instance
}
# Task 366


Create an Amazon Lightsail instance with a separate SSH key pair in the `eu-west-1` region (use availability zone `eu-west-1a`). Provide the public key inline as a string (do not use `file()` to read from a local path).

## Intent

have one "aws_lightsail_instance" resource
    with "name" argument
    with "availability_zone" argument
    with "blueprint_id" argument
    with "bundle_id" argument
    with key_pair_name argument

have one "aws_lightsail_key_pair" resource
    with "name" argument
    with "public_key" argument

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region = "eu-west-1"
}

resource "aws_lightsail_key_pair" "lg_key_pair" {
  name       = "importing"
  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDExample1234567890 example@localhost"
}

resource "aws_lightsail_instance" "custom" {
  name              = "custom"
  availability_zone = "eu-west-1a"
  blueprint_id      = "wordpress"
  bundle_id         = "nano_2_0"
  key_pair_name     = aws_lightsail_key_pair.lg_key_pair.name
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_all_required_resources = false

# Rule for aws_lightsail_instance resource with specific arguments
has_valid_lightsail_instance if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_instance"
    resource.values.name
    resource.values.availability_zone
    resource.values.blueprint_id
    resource.values.bundle_id
    resource.values.key_pair_name
}

# Rule for aws_lightsail_key_pair resource with specific arguments
has_valid_lightsail_key_pair if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_key_pair"
    resource.values.name
    resource.values.public_key
}

# Combined rule to ensure both resources meet their respective conditions
has_all_required_resources if {
    has_valid_lightsail_instance
    has_valid_lightsail_key_pair
}

main if {
    has_valid_lightsail_instance
    has_valid_lightsail_key_pair
}
# Task 367


create AWS Lightsail that creates a managed database

## Intent

have one "aws_lightsail_database" resource
    with relational_database_name argument
    with master_database_name 
    with master_password
    with master_username
    with blueprint_id
    with bundle_id

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

resource "aws_lightsail_database" "test" {
  relational_database_name = "test"
  availability_zone        = "us-east-1a"
  master_database_name     = "testdatabasename"
  master_password          = "testdatabasepassword"
  master_username          = "test"
  blueprint_id             = "mysql_8_0"
  bundle_id                = "micro_1_0"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_database = false

# Rule for aws_lightsail_database resource with specific arguments
has_valid_lightsail_database if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_database"
    resource.values.relational_database_name
    resource.values.master_database_name
    resource.values.master_password
    resource.values.master_username
    resource.values.blueprint_id
    resource.values.bundle_id
}

main if {
    has_valid_lightsail_database
}
# Task 368


create an AWS Lightsail instance that creates a mysql database

## Intent

have one "aws_lightsail_database" resource
    with relational_database_name argument
    with master_database_name 
    with master_password
    with master_username
    with blueprint_id = mysql_8_0
    with bundle_id

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

resource "aws_lightsail_database" "test" {
  relational_database_name = "test"
  availability_zone        = "us-east-1a"
  master_database_name     = "testdatabasename"
  master_password          = "testdatabasepassword"
  master_username          = "test"
  blueprint_id             = "mysql_8_0"
  bundle_id                = "micro_1_0"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_database = false

# Rule for aws_lightsail_database resource with specific arguments
has_valid_lightsail_database if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_database"
    resource.values.relational_database_name
    resource.values.master_database_name
    resource.values.master_password
    resource.values.master_username
    resource.values.blueprint_id == "mysql_8_0"
    resource.values.bundle_id
}

main if {
    has_valid_lightsail_database
}
# Task 369


create AWS Lightsail that creates a mysql database. It should allow daily backups to take place between 16:00 and 16:30 each day and  requires any maintiance tasks (anything that would cause an outage, including changing some attributes) to take place on Tuesdays between 17:00 and 17:30

## Intent

have one "aws_lightsail_database" resource
    with relational_database_name argument
    with master_database_name 
    with master_password
    with master_username
    with blueprint_id
    with bundle_id
    with  preferred_backup_window    = "16:00-16:30"
  preferred_maintenance_window = "Tue:17:00-Tue:17:30"

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

resource "aws_lightsail_database" "test" {
  relational_database_name     = "test"
  availability_zone            = "us-east-1a"
  master_database_name         = "testdatabasename"
  master_password              = "testdatabasepassword"
  master_username              = "test"
  blueprint_id                 = "mysql_8_0"
  bundle_id                    = "micro_1_0"
  preferred_backup_window      = "16:00-16:30"
  preferred_maintenance_window = "Tue:17:00-Tue:17:30"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_database = false

# Rule for aws_lightsail_database resource with specific arguments
has_valid_lightsail_database if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_database"
    resource.values.relational_database_name
    resource.values.master_database_name
    resource.values.master_password
    resource.values.master_username
    resource.values.bundle_id
    resource.values.preferred_backup_window == "16:00-16:30"
    resource.values.preferred_maintenance_window == "Tue:17:00-Tue:17:30"
    
}

main if {
    has_valid_lightsail_database
}
# Task 370


AWS Lightsail that creates a postgres database, which enable creating a final snapshot of your database on deletion

## Intent

"have one ""aws_lightsail_database"" resource
    with relational_database_name argument
    with master_database_name 
    with master_password
    with master_username
    with blueprint_id = postgres_12
    with bundle_id
    with final_snapshot_name

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

resource "aws_lightsail_database" "test" {
  relational_database_name     = "test"
  availability_zone            = "us-east-1a"
  master_database_name         = "testdatabasename"
  master_password              = "testdatabasepassword"
  master_username              = "test"
  blueprint_id                 = "postgres_12"
  bundle_id                    = "micro_1_0"
  final_snapshot_name          = "MyFinalSnapshot"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_database = false

# Rule for aws_lightsail_database resource with specific arguments
has_valid_lightsail_database if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_database"
    resource.values.relational_database_name
    resource.values.master_database_name
    resource.values.master_password
    resource.values.master_username
    resource.values.blueprint_id == "postgres_12"
    resource.values.bundle_id
    resource.values.final_snapshot_name
}

main if {
    has_valid_lightsail_database
}
# Task 371


AWS Lightsail that creates a postgres database, which enable applying changes immediately instead of waiting for a maintiance window

## Intent

"have one ""aws_lightsail_database"" resource
    with relational_database_name argument
    with master_database_name 
    with master_password
    with master_username
    with blueprint_id = postgres_12
    with bundle_id
    apply_immediately  = true

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

resource "aws_lightsail_database" "test" {
  relational_database_name = "test"
  availability_zone        = "us-east-1a"
  master_database_name     = "testdatabasename"
  master_password          = "testdatabasepassword"
  master_username          = "test"
  blueprint_id             = "postgres_12"
  bundle_id                = "micro_1_0"
  apply_immediately        = true
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_database = false

# Rule for aws_lightsail_database resource with specific arguments
has_valid_lightsail_database if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_database"
    resource.values.relational_database_name
    resource.values.master_database_name
    resource.values.master_password
    resource.values.master_username
    resource.values.blueprint_id == "postgres_12"
    resource.values.bundle_id
    resource.values.apply_immediately == true
}

main if {
    has_valid_lightsail_database
}
# Task 372


create a Lightsail Disk resource

## Intent

have one aws_lightsail_disk resource
    with name
    with size_in_gb
    with availability_zone

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region     = "us-east-1"
}

data "aws_availability_zones" "available" {
  state = "available"

  filter {
    name   = "opt-in-status"
    values = ["opt-in-not-required"]
  }
}

resource "aws_lightsail_disk" "test" {
  name              = "test"
  size_in_gb        = 8
  availability_zone = data.aws_availability_zones.available.names[0]
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_disk = false

# Rule for aws_lightsail_disk resource with specific arguments
has_valid_lightsail_disk if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_disk"
    resource.values.name
    resource.values.size_in_gb
    resource.values.availability_zone
}

main if {
    has_valid_lightsail_disk
}
# Task 373


Create a Lightsail Disk resource and attaches the Lightsail disk to a Lightsail Instance

## Intent

have one aws_lightsail_disk resource
    with name
    with size_in_gb
    with availability_zone

have one aws_lightsail_disk_attachment
    with disk_name
    with instance_name
    with disk_path

have one "aws_lightsail_instance" resource
    with "name" argument
    with "availability_zone" argument
    with "blueprint_id" argument
    with "bundle_id" argument

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

data "aws_availability_zones" "available" {
  state = "available"

  filter {
    name   = "opt-in-status"
    values = ["opt-in-not-required"]
  }
}

resource "aws_lightsail_disk" "test" {
  name              = "test-disk"
  size_in_gb        = 8
  availability_zone = data.aws_availability_zones.available.names[0]
}

resource "aws_lightsail_instance" "test" {
  name              = "test-instance"
  availability_zone = data.aws_availability_zones.available.names[0]
  blueprint_id      = "amazon_linux_2"
  bundle_id         = "nano_1_0"
}

resource "aws_lightsail_disk_attachment" "test" {
  disk_name     = aws_lightsail_disk.test.name
  instance_name = aws_lightsail_instance.test.name
  disk_path     = "/dev/xvdf"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_disk = false

# Rule for aws_lightsail_disk resource with specific arguments
has_valid_lightsail_disk if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_disk"
    resource.values.name
    resource.values.size_in_gb
    resource.values.availability_zone
}

main if {
    has_valid_lightsail_disk
}
# Task 374


Set up a storage unit in Lightsail and link it with a Lightsail compute service.

## Intent

have one aws_lightsail_disk resource
    with name
    with size_in_gb
    with availability_zone

have one aws_lightsail_disk_attachment
    with disk_name
    with instance_name
    with disk_path

have one "aws_lightsail_instance" resource
    with "name" argument
    with "availability_zone" argument
    with "blueprint_id" argument
    with "bundle_id" argument

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

data "aws_availability_zones" "available" {
  state = "available"

  filter {
    name   = "opt-in-status"
    values = ["opt-in-not-required"]
  }
}

resource "aws_lightsail_disk" "test" {
  name              = "test-disk"
  size_in_gb        = 8
  availability_zone = data.aws_availability_zones.available.names[0]
}

resource "aws_lightsail_instance" "test" {
  name              = "test-instance"
  availability_zone = data.aws_availability_zones.available.names[0]
  blueprint_id      = "amazon_linux_2"
  bundle_id         = "nano_1_0"
}

resource "aws_lightsail_disk_attachment" "test" {
  disk_name     = aws_lightsail_disk.test.name
  instance_name = aws_lightsail_instance.test.name
  disk_path     = "/dev/xvdf"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_lightsail_disk = false

# Rule for aws_lightsail_disk resource with specific arguments
has_valid_lightsail_disk if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_disk"
    resource.values.name
    resource.values.size_in_gb
    resource.values.availability_zone
}

main if {
    has_valid_lightsail_disk
}
# Task 375


Create a Lightsail instance with multiple attached disks

## Intent

have multiple aws_lightsail_disk resource
    with name
    with size_in_gb
    with availability_zone

have multiple aws_lightsail_disk_attachment
    with disk_name
    with instance_name
    with disk_path

have one "aws_lightsail_instance" resource
    with "name" argument
    with "availability_zone" argument
    with "blueprint_id" argument
    with "bundle_id" argument

## Reference Terraform solution

terraform {
  required_version = ">= 1.15.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

data "aws_availability_zones" "available" {
  state = "available"

  filter {
    name   = "opt-in-status"
    values = ["opt-in-not-required"]
  }
}

resource "aws_lightsail_disk" "test1" {
  name              = "test-disk-1"
  size_in_gb        = 8
  availability_zone = data.aws_availability_zones.available.names[0]
}

resource "aws_lightsail_disk" "test2" {
  name              = "test-disk-2"
  size_in_gb        = 8
  availability_zone = data.aws_availability_zones.available.names[0]
}

resource "aws_lightsail_instance" "test" {
  name              = "test-instance"
  availability_zone = data.aws_availability_zones.available.names[0]
  blueprint_id      = "amazon_linux_2"
  bundle_id         = "nano_1_0"
}

resource "aws_lightsail_disk_attachment" "test1" {
  disk_name     = aws_lightsail_disk.test1.name
  instance_name = aws_lightsail_instance.test.name
  disk_path     = "/dev/xvdf"
}

resource "aws_lightsail_disk_attachment" "test2" {
  disk_name     = aws_lightsail_disk.test2.name
  instance_name = aws_lightsail_instance.test.name
  disk_path     = "/dev/xvdg"
}


## OPA Rego validation policy

package terraform.policy

import rego.v1

default has_valid_resources = false

# Rule for multiple aws_lightsail_disk resources
has_valid_lightsail_disks if {
    count([disk | disk := input.planned_values.root_module.resources[_]; disk.type == "aws_lightsail_disk"; disk.values.name; disk.values.size_in_gb; disk.values.availability_zone]) > 0
}

# Rule for multiple aws_lightsail_disk_attachment resources
has_valid_lightsail_disk_attachments if {
    count([attachment | attachment := input.planned_values.root_module.resources[_]; attachment.type == "aws_lightsail_disk_attachment"; attachment.values.disk_name; attachment.values.instance_name; attachment.values.disk_path]) > 0
}

# Rule for aws_lightsail_instance resource with specific arguments
has_valid_lightsail_instance if {
    some i
    resource := input.planned_values.root_module.resources[i]
    resource.type == "aws_lightsail_instance"
    resource.values.name
    resource.values.availability_zone
    resource.values.blueprint_id
    resource.values.bundle_id
}

# Combined rule to ensure all conditions are met
has_valid_resources if {
    has_valid_lightsail_disks
    has_valid_lightsail_disk_attachments
    has_valid_lightsail_instance
}

main if {
    has_valid_lightsail_disks
    has_valid_lightsail_disk_attachments
    has_valid_lightsail_instance
    has_valid_resources
}