From 7330ba0d5dbcc4adb21332710dee605f260f8877 Mon Sep 17 00:00:00 2001 From: tylerthome Date: Wed, 26 Jun 2024 18:18:47 -0700 Subject: [PATCH 1/4] initial tf test with oidc, dns only --- terraform-incubator/home-unite-us/main.tf | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 terraform-incubator/home-unite-us/main.tf diff --git a/terraform-incubator/home-unite-us/main.tf b/terraform-incubator/home-unite-us/main.tf new file mode 100644 index 0000000..7e665d4 --- /dev/null +++ b/terraform-incubator/home-unite-us/main.tf @@ -0,0 +1,11 @@ +resource "aws_route53_zone" "main" { + name = "homeunite.us" +} + +resource "aws_route53_record" "www" { + zone_id = aws_route53_zone.main.zone_id + name = "homeunite.us" + type = "A" + ttl = 300 + records = ["18.223.160.58"] +} \ No newline at end of file From eac5e802d238150e6cb2c2e1b1f53470467bdbe2 Mon Sep 17 00:00:00 2001 From: tylerthome Date: Wed, 26 Jun 2024 19:02:11 -0700 Subject: [PATCH 2/4] add action and oidc integration --- .../workflows/terraform-plan-with-oidc.yaml | 44 +++++++++++++++++++ terraform-incubator/home-unite-us/main.tf | 21 ++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/terraform-plan-with-oidc.yaml diff --git a/.github/workflows/terraform-plan-with-oidc.yaml b/.github/workflows/terraform-plan-with-oidc.yaml new file mode 100644 index 0000000..efe0a14 --- /dev/null +++ b/.github/workflows/terraform-plan-with-oidc.yaml @@ -0,0 +1,44 @@ +name: Terraform deploy with OIDC +on: + workflow_dispatch: + inputs: + target-host-environment: + type: choice + description: The AWS environment to deploy (dev/test/prod) + options: + - dev + - test + - prod + +permissions: + id-token: write + contents: read + +jobs: + + TerraformPlan: + + runs-on: ubuntu-latest + + steps: + - name: Clone repo + uses: actions/checkout@v4 + + - name: configure aws credentials + uses: aws-actions/configure-aws-credentials@v3 + with: + role-to-assume: arn:aws:iam::035866691871:role/gha-incubator + role-session-name: ghaincubatorsession + aws-region: us-west-2 + + - name: + uses: hashicorp/setup-terraform@v3 + + - name: Run terraform + run: | + pushd ./terraform-incubator/home-unite-us + terraform init + + popd + + \ No newline at end of file diff --git a/terraform-incubator/home-unite-us/main.tf b/terraform-incubator/home-unite-us/main.tf index 7e665d4..22a15ff 100644 --- a/terraform-incubator/home-unite-us/main.tf +++ b/terraform-incubator/home-unite-us/main.tf @@ -8,4 +8,23 @@ resource "aws_route53_record" "www" { type = "A" ttl = 300 records = ["18.223.160.58"] -} \ No newline at end of file +} + +terraform { + + required_providers { + aws = { + source = "hashicorp/aws" + } + } + + backend "s3" { + region = "us-west-2" + key = "incubator/home-unite-us/dev.tfstate" + bucket = "hlfa-incubator-terragrunt" + } +} + +provider "aws" { + region = "us-west-2" +} From b4955874501c34368719099f8d17c29e27274dd0 Mon Sep 17 00:00:00 2001 From: tylerthome Date: Wed, 26 Jun 2024 19:06:20 -0700 Subject: [PATCH 3/4] add plan --- .github/workflows/terraform-plan-with-oidc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform-plan-with-oidc.yaml b/.github/workflows/terraform-plan-with-oidc.yaml index efe0a14..0aac1af 100644 --- a/.github/workflows/terraform-plan-with-oidc.yaml +++ b/.github/workflows/terraform-plan-with-oidc.yaml @@ -38,7 +38,7 @@ jobs: run: | pushd ./terraform-incubator/home-unite-us terraform init - + terraform plan popd \ No newline at end of file From 65e08d08a39c8961cb240881f50b386314821857 Mon Sep 17 00:00:00 2001 From: tylerthome Date: Wed, 26 Jun 2024 19:24:36 -0700 Subject: [PATCH 4/4] nest main.tf into subfolder --- .github/workflows/terraform-plan-with-oidc.yaml | 2 +- terraform-incubator/home-unite-us/{ => dev}/main.tf | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename terraform-incubator/home-unite-us/{ => dev}/main.tf (100%) diff --git a/.github/workflows/terraform-plan-with-oidc.yaml b/.github/workflows/terraform-plan-with-oidc.yaml index 0aac1af..cce5f78 100644 --- a/.github/workflows/terraform-plan-with-oidc.yaml +++ b/.github/workflows/terraform-plan-with-oidc.yaml @@ -38,7 +38,7 @@ jobs: run: | pushd ./terraform-incubator/home-unite-us terraform init - terraform plan + terraform plan popd \ No newline at end of file diff --git a/terraform-incubator/home-unite-us/main.tf b/terraform-incubator/home-unite-us/dev/main.tf similarity index 100% rename from terraform-incubator/home-unite-us/main.tf rename to terraform-incubator/home-unite-us/dev/main.tf