Reputation: 5700
I deployed my Glue Jobs via Console and / or boto3 library until now.
I want to move to Infrastructure as Code using Terraform and manage all the Glue resources with this tool. Now to import already existing resources I'm aware of the command terraform import ADDR ID
but I'm not sure how does that work.
Anyone can explain me how the import works with AWS Glue?
Upvotes: 3
Views: 3508
Reputation: 5700
Referencing https://www.terraform.io/docs/cli/import/usage.html before importing an AWS Glue Job it is necessary to create a .tf
file in the current working directory in your CLI.
So let's create a main.tf
file like this:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
}
provider "aws" {
region = "my-region-1"
assume_role {
role_arn = "arn:aws:iam::012345678901:role/MyRole"
}
}
resource "aws_glue_job" "my_job_resource" {
name = "my-glue-job"
role_arn = "arn:aws:iam::012345678901:role/MyGlueJobRole"
command {
name = "glueetl"
script_location = "s3://my-bucket/my-script.py"
python_version = "3"
}
}
Where:
my-region-1
is the AWS region where operatingarn:aws:iam::012345678901:role/MyRole
is the AWS Role assumed when running Terraform commands (which is what will access / interact with AWS Resources)my-glue-job
is the name of the existing Glue Jobarn:aws:iam::012345678901:role/MyGlueJobRole
is the AWS Role of the existing Glue Jobs3://my-bucket/my-script.py
is the S3 location of the Glue Job scriptThe command
field is specific of the Glue Job import as considered a mandatory field, for other fields references and / or variations: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/glue_job
Once the main.tf
file is ready, run from the CLI in the same folder containing the file the following commands:
terraform init
terraform import aws_glue_job.my_job_resource my-glue-job
terraform show
Few details on these commands:
my_job_resource
is the name of the block that identifies AWS resource while my-glue-job
is the actual Glue Job name (in both cases refer to the main.tf
file)Copy and replace the output generated from the last step into the main.tf
file, replacing the block resource "aws_glue_job" "my_job_resource"
.
It is now imported in a Terraform script.
The same principle can be reused for any other Glue resources, just reference the documentation page https://registry.terraform.io/providers/hashicorp/aws/latest/docs
Upvotes: 2