Git Product home page Git Product logo

the-aws-terraform-samples / terraform-aws-sample-infra-resources-terraform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/aws-sample-infra-resources-terraform

0.0 0.0 0.0 10 KB

A sample infra resources code in Terraform that goes into a target workload account. This code is pushed into the AWS CodeCommit repo for our sample.

License: MIT No Attribution

Shell 46.11% HCL 53.89%

terraform-aws-sample-infra-resources-terraform's Introduction

aws-sample-infra-resources-terraform

A sample infra resources code in Terraform that goes into a target workload account. This code is pushed into the AWS CodeCommit repo for our sample.

Table of contents

Sample Workload Infra

  • Regional resources: An external facing ALB all the way down to the VPC.
  • Global resources: An IAM role.

Once all resources are deployed (see section on how to deploy resources) then go to EC2 -> Load Balancer (demo*) -> DNS Name -> Copy it and open it in the browser (make sure to use http:// and not https://).

Prerequisites:

To push the infra repo code into AWS CodeCommit in the central tooling account:

To deploy resources into the target workload accounts:

To destroy the resources in the target workload accounts:

  • If not done already, use aws configure with your IAM user credentials for the central tooling account and then assume InfraBuildRole:
# You can use below one liner
# For details, see [this](https://aws.amazon.com/premiumsupport/knowledge-center/iam-assume-role-cli/
OUT=$(aws sts assume-role --role-arn arn:aws:iam::111122223333:role/InfraBuildRole --role-session-name INFRA_BUILD);export AWS_ACCESS_KEY_ID=$(echo $OUT | jq -r '.Credentials''.AccessKeyId');export AWS_SECRET_ACCESS_KEY=$(echo $OUT | jq -r '.Credentials''.SecretAccessKey');export AWS_SESSION_TOKEN=$(echo $OUT | jq -r '.Credentials''.SessionToken');

# Verify you assumed the role
aws sts get-caller-identity
{
    "UserId": "AAA:INFRA_BUILD",
    "Account": "111122223333",
    "Arn": "arn:aws:sts::111122223333:assumed-role/InfraBuildRole/INFRA_BUILD"
}
  • Use the regional resources destroy shell script in this repo to generate the tf plan for the account and region. Inspect the tf plan and then run terraform apply "tfplan"
./scripts/run-tf-regional-destroy.sh -t <tag> -b <tf_backend_config_prefix> -r <tf_state_region> -g <global_resource_deployment_region>
# Ex: ./scripts/run-tf-regional-destroy.sh -t dev_us-east-1/research/1.0 -g eu-central-1 -r eu-central-1 -b org-awesome-tf-state
  • Then, use the global resources destroy shell script in this repo to generate the tf plan for the account. Inspect the tf plan and then run terraform apply "tfplan"
./scripts/run-tf-global-destroy.sh -t <tag> -b <tf_backend_config_prefix> -r <tf_state_region> -g <global_resource_deployment_region>
# Ex: ./scripts/run-tf-global-destroy.sh -t dev_global/research/1.0 -g eu-central-1 -r eu-central-1 -b org-awesome-tf-state

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

Requirements

Name Version
terraform > 0.14
aws ~> 3.74

Providers

Name Version
aws 3.74.2

Modules

Name Source Version
global ./modules/global n/a
regional ./modules/regional n/a

Resources

Name Type
aws_caller_identity.current data source
aws_region.current data source

Inputs

Name Description Type Default Required
account Target AWS account number number n/a yes
env Environment name string n/a yes
number_of_azs Number of azs to deploy to number 2 no
region Target region string n/a yes

Outputs

Name Description
account_id The effective account id in which Terraform is operating
caller_arn The effective user arn that Terraform is running as
caller_user The effective user id that Terraform is running as
region The region in which Terraform is operating

terraform-aws-sample-infra-resources-terraform's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.