resource "aws_codepipeline" "deploy" {
  name="deploy-integreat-${var.stage}"
  role_arn = "arn:aws:codepipeline:us-east-1:679918342773:deploy-app-s3"

   artifact_store {
    location = "${aws_s3_bucket.codepipeline_bucket.bucket}"
    type     = "S3"
  }

  stage {
    name = "Source"
    action {
      name="Source"
      category = "Source"
      configuration {
        BranchName = "master"
        PollForSourcChanges = false
        RepositoryName = "integreat"
      }
      provider = "CodeCommit"
      run_order = 1
      owner = "AWS"
      version = 1

      output_artifacts = ["SourceArtifact"]
    }
  }

  stage {
    name = "build"
    action {
      name="build"
      category = "Build"
      configuration {
        ProjectName = "build-integreat-app"
      }
      input_artifacts = ["SourceArtifact"]
      output_artifacts = ["jar", "web"]
      owner = "AWS"
      provider = "CodeBuild"
      version = 1

    }
  }
}

resource "aws_s3_bucket" "codepipeline_bucket" {
  bucket = "integreat-codepipeline-${var.stage}"
  acl    = "private"
}

