diff --git a/.github/workflows/terr_check.yml b/.github/workflows/terr_check.yml new file mode 100644 index 0000000..d7ca52f --- /dev/null +++ b/.github/workflows/terr_check.yml @@ -0,0 +1,42 @@ +name: "Terraform-infra" + +on: + push: + branches: + - infra_branch + - main + workflow_dispatch: + +jobs: + terraform: + name: "Terraform" + runs-on: Ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + REGION: 'us-east-1' + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Terraform setup + uses: hashicorp/setup-terraform@v1 + + - name: Terraform init + id: init + run: terraform init + + - name: Terraform plan + id: plan + if: github.event_name == 'push' + run: terraform plan -no-color + + - name: Terraform plan status + if: steps.plan.outcome == 'failure' + run: exit 1 + + - name: Terraform apply + id: apply + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + run: terraform apply -auto-approve \ No newline at end of file diff --git a/ifra.tf b/ifra.tf new file mode 100644 index 0000000..3916894 --- /dev/null +++ b/ifra.tf @@ -0,0 +1,23 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } +} + +# Configure the AWS Provide +provider "aws" { + region = "us-east-1" +} + +resource "aws_instance" "toto" { + ami = "ami-0a0e5d9c7acc336f1" + instance_type = "t2.micro" + security_groups = ["SG-Jenkins"] + key_name = "my" +} +data "aws_vpc" "default" { + default = true +} \ No newline at end of file