diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 1bcf52a..86490cf 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -6,6 +6,145 @@ on: pull_request: branches: [ "main" ] +env: + # Mock TF plan + TF_PLAN: > + { + "resource_changes": [ + { + "address": "aws_instance.ec2_instance", + "change": { + "actions": [ + "create" + ], + "after": { + "ami": "ami-051f8a213df8bc089", + "arn": "arn:aws:ec2:us-east-1:502240965697:instance/i-0189a83c43048101e", + "associate_public_ip_address": true, + "availability_zone": "us-east-1a", + "capacity_reservation_specification": [ + { + "capacity_reservation_preference": "open", + "capacity_reservation_target": [] + } + ], + "cpu_core_count": 1, + "cpu_options": [ + { + "amd_sev_snp": "", + "core_count": 1, + "threads_per_core": 1 + } + ], + "cpu_threads_per_core": 1, + "credit_specification": [ + { + "cpu_credits": "standard" + } + ], + "disable_api_stop": false, + "disable_api_termination": false, + "ebs_block_device": [], + "ebs_optimized": false, + "enclave_options": [ + { + "enabled": false + } + ], + "ephemeral_block_device": [], + "get_password_data": false, + "hibernation": false, + "host_id": "", + "host_resource_group_arn": null, + "iam_instance_profile": "", + "id": "i-0189a83c43048101e", + "instance_initiated_shutdown_behavior": "stop", + "instance_lifecycle": "", + "instance_market_options": [], + "instance_state": "running", + "instance_type": "t2.micro", + "ipv6_address_count": 0, + "ipv6_addresses": [], + "key_name": "", + "launch_template": [], + "maintenance_options": [ + { + "auto_recovery": "default" + } + ], + "metadata_options": [ + { + "http_endpoint": "enabled", + "http_protocol_ipv6": "disabled", + "http_put_response_hop_limit": 2, + "http_tokens": "required", + "instance_metadata_tags": "disabled" + } + ], + "monitoring": false, + "network_interface": [], + "outpost_arn": "", + "password_data": "", + "placement_group": "", + "placement_partition_number": 0, + "primary_network_interface_id": "eni-0a8f56ec84e42b4de", + "private_dns": "ip-172-31-84-78.ec2.internal", + "private_dns_name_options": [ + { + "enable_resource_name_dns_a_record": false, + "enable_resource_name_dns_aaaa_record": false, + "hostname_type": "ip-name" + } + ], + "private_ip": "172.31.84.78", + "public_dns": "ec2-3-90-43-110.compute-1.amazonaws.com", + "public_ip": "3.90.43.110", + "root_block_device": [ + { + "delete_on_termination": true, + "device_name": "/dev/xvda", + "encrypted": false, + "iops": 3000, + "kms_key_id": "", + "tags": {}, + "tags_all": {}, + "throughput": 125, + "volume_id": "vol-0513133239cbffe57", + "volume_size": 8, + "volume_type": "gp3" + } + ], + "secondary_private_ips": [], + "security_groups": [ + "default" + ], + "source_dest_check": true, + "spot_instance_request_id": "", + "subnet_id": "subnet-0b27901c38cb7b8ff", + "tags": null, + "tags_all": {}, + "tenancy": "default", + "timeouts": null, + "user_data": null, + "user_data_base64": null, + "user_data_replace_on_change": false, + "volume_tags": null, + "vpc_security_group_ids": [ + "sg-0b861685baed33704" + ] + }, + "before": null + }, + "mode": "managed", + "name": "ec2_instance", + "provider_name": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "type": "aws_instance" + } + ], + "version": 1.2 + } + + jobs: terraform: name: 'Terraform' @@ -18,25 +157,15 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Terraform uses: hashicorp/setup-terraform@v1 - - name: Terraform Init - run: terraform init - - - name: Terraform Plan - run: terraform plan -out=plan.raw - - - name: Convert the plan to JSON - id: planToJson - run: terraform show -json plan.raw - - name: Save JSON to a file uses: fishcharlie/CmdToFile@v1.0.0 with: - data: ${{ steps.planToJson.outputs.stdout }} + data: ${{ env.TF_PLAN }} output: plan.json - name: Upload Terraform Plan Output @@ -45,17 +174,13 @@ jobs: name: plan-file path: plan.json - - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - run: terraform apply -auto-approve -input=false - resourcely-ci: needs: terraform if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download Terraform Plan Output uses: actions/download-artifact@v2 @@ -67,5 +192,5 @@ jobs: uses: Resourcely-Inc/resourcely-action@main with: resourcely_api_token: ${{ secrets.RESOURCELY_API_TOKEN }} - resourcely_api_host: "https://api.resourcely.io" + resourcely_api_host: "https://funny-bunny.ngrok.dev" tf_plan_directory: "tf-plan-files"