<commit_before>package aws

import (
	"fmt"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/workspaces"
	"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
	"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

const (
	testAccWorkspaceConfig = `
data "aws_availability_zones" "available" {
  state = "available"
}

resource "aws_vpc" "test" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "test-a" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1a"
  cidr_block = "10.0.1.0/24"
}

resource "aws_subnet" "test-c" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1c"
  cidr_block = "10.0.2.0/24"
}

resource "aws_directory_service_directory" "test" {
  name = "tf-acctest.example.com"
  password = <PASSWORD>"
  size = "Small"
  vpc_settings {
    vpc_id = "${aws_vpc.test.id}"
    subnet_ids = ["${aws_subnet.test-a.id}","${aws_subnet.test-c.id}"]
  }
}

resource "aws_workspaces_directory" "test" {
  directory_id = "${aws_directory_service_directory.test.id}"
}
`

	testAccWorkspaceConfig_subnetIds = `
resource "aws_vpc" "test" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "test-a" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1a"
  cidr_block = "10.0.1.0/24"
}

resource "aws_subnet" "test-c" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1c"
  cidr_block = "10.0.2.0/24"
}

resource "aws_directory_service_directory" "test" {
  name = "tf-acctest.example.com"
  password = <PASSWORD>"
  size = "Small"
  vpc_settings {
    vpc_id = "${aws_vpc.test.id}"
    subnet_ids = ["${aws_subnet.test-a.id}","${aws_subnet.test-c.id}"]
  }
}

resource "aws_workspaces_directory" "test" {
  directory_id = "${aws_directory_service_directory.test.id}"
  subnet_ids = ["${aws_subnet.test-a.id}","${aws_subnet.test-c.id}"]
}
`
)

func TestAccAwsWorkspacesDirectory_basic(t *testing.T) {
	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },<commit_msg>@review Add workspaces_DefaultRole<commit_after>package aws

import (
	"fmt"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/workspaces"
	"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
	"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

const (
	testAccWorkspaceConfig = `
data "aws_availability_zones" "available" {
  state = "available"
}

resource "aws_vpc" "test" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "test-a" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1a"
  cidr_block = "10.0.1.0/24"
}

resource "aws_subnet" "test-c" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1c"
  cidr_block = "10.0.2.0/24"
}

resource "aws_directory_service_directory" "test" {
  name = "tf-acctest.example.com"
  password = <PASSWORD>"
  size = "Small"
  vpc_settings {
    vpc_id = "${aws_vpc.test.id}"
    subnet_ids = ["${aws_subnet.test-a.id}","${aws_subnet.test-c.id}"]
  }
}

data aws_iam_policy_document workspaces {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type        = "Service"
      identifiers = ["workspaces.amazonaws.com"]
    }
  }
}

resource aws_iam_role workspaces-default {
  name               = "workspaces_DefaultRole"
  assume_role_policy = data.aws_iam_policy_document.workspaces.json
}

resource aws_iam_role_policy_attachment workspaces-default-service-access {
  role       = aws_iam_role.workspaces-default.name
  policy_arn = "arn:aws:iam::aws:policy/AmazonWorkSpacesServiceAccess"
}

resource aws_iam_role_policy_attachment workspaces-default-self-service-access {
  role       = aws_iam_role.workspaces-default.name
  policy_arn = "arn:aws:iam::aws:policy/AmazonWorkSpacesSelfServiceAccess"
}

resource "aws_workspaces_directory" "test" {
  directory_id = "${aws_directory_service_directory.test.id}"
}
`

	testAccWorkspaceConfig_subnetIds = `
resource "aws_vpc" "test" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "test-a" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1a"
  cidr_block = "10.0.1.0/24"
}

resource "aws_subnet" "test-c" {
  vpc_id = "${aws_vpc.test.id}"
  availability_zone = "us-east-1c"
  cidr_block = "10.0.2.0/24"
}

resource "aws_directory_service_directory" "test" {
  name = "tf-acctest.example.com"
  password = <PASSWORD>"
  size = "Small"
  vpc_settings {
    vpc_id = "${aws_vpc.test.id}"
    subnet_ids = ["${aws_subnet.test-a.id}","${aws_subnet.test-c.id}"]
  }
}

data aws_iam_policy_document workspaces {
  statement {
    actions = ["sts:AssumeRole"]

    principals {
      type        = "Service"
      identifiers = ["workspaces.amazonaws.com"]
    }
  }
}

resource aws_iam_role workspaces-default {
  name               = "workspaces_DefaultRole"
  assume_role_policy = data.aws_iam_policy_document.workspaces.json
}

resource aws_iam_role_policy_attachment workspaces-default-service-access {
  role       = aws_iam_role.workspaces-default.name
  policy_arn = "arn:aws:iam::aws:policy/AmazonWorkSpacesServiceAccess"
}

resource aws_iam_role_policy_attachment workspaces-default-self-service-access {
  role       = aws_iam_role.workspaces-default.name
  policy_arn = "arn:aws:iam::aws:policy/AmazonWorkSpacesSelfServiceAccess"
}

resource "aws_workspaces_directory" "test" {
  directory_id = "${aws_directory_service_directory.test.id}"
  subnet_ids = ["${aws_subnet.test-a.id}","${aws_subnet.test-c.id}"]
}
`
)

func TestAccAwsWorkspacesDirectory_basic(t *testing.T) {
	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
{'fraction_non_alphanumeric': 0.153088630259624, 'fraction_numerical': 0.01647269471799463, 'mean_word_length': 4.20596458527493, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6604459', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2253, 'n_words': 288}