Connect with us

Tech

Terraform 1.8 provider features for AWS, Google Cloud, and Kubernetes

Terraform 1.8 provider features for AWS, Google Cloud, and Kubernetes

 


Today, with the release of HashiCorp Terraform 1.8, we are announcing the general availability of provider-defined functions on AWS, Google Cloud, and Kubernetes providers. This release marks another step forward in our unique approach to ecosystem scalability. Provider-defined functions allow anyone in the Terraform community to build custom functions within providers to extend the functionality of Terraform.

Introducing provider-defined functions

Previously, users relied on several built-in functions in the Terraform configuration language to perform various tasks including numerical calculations, string manipulation, collection transformations, validation, and other operations. However, the Terraform community needed more functionality than built-in functions could provide. With the release of Terraform 1.8, a provider can now implement custom functions that can be called from her Terraform configuration. The function schema is defined within the provider's schema using the Terraform provider plugin framework.

To use the function, declare the provider as required_provider in the terraform{} block.

terraform { required_version = “>= 1.8.0” required_providers { time = { source = “bashicorp/local” version = “2.5.1” } }}

Provider-defined functions can perform multiple tasks, including:

Transform existing data Parse combined data into separate referenceable components Build combined data from individual components Simplify validation and assertions

To access provider-defined functions, reference the Provider:: namespace by the Terraform provider's local name. For example, you can use the direxists function by including Provider::local::direxists() in your Terraform configuration.

Below are some examples of new provider-defined functions in officially supported AWS, Google Cloud, and Kubernetes providers.

Terraform AWS provider

The 5.40 release of the Terraform AWS provider includes the first provider-defined functions to parse and construct Amazon Resource Names (ARNs), simplifying Terraform configurations that require working with ARNs. The arn_parse provider-defined function is used to parse an ARN and return objects for the individual visible components, such as region and account ID. For example, to get the AWS account ID from an Amazon Elastic Container Registry (ECR) repository, use the arn_parse function to get the account ID and set it as the output.

# Create an ECR repository resource “aws_ecr_repository” “bashicups” { name = “bashicups” image_scanning_configuration { scan_on_push = true }} # Output the ECR repository account ID output “bashicups_ecr_repository_account_id” { value = Provider::aws::arn_parse( aws_ecr_repository.bashicups .arn).account_id}

Running terraform apply on the above configuration will output the AWS account ID.

Application completed! Resources: 2 added, 0 modified, 0 destroyed. Output: bashicups_ecr_repository_account_id = “751192555662”

If you do not use the arn_parse function, you must define and test a combination of built-in Terraform functions to split the ARN and reference the appropriate index, or define a regular expression to match substrings. This function handles the parsing in a concise way, so you don't have to worry about parsing it yourself.

The AWS provider also includes a new arn_build function that builds an ARN from individual attributes and returns it as a string. This provider-defined function can create an ARN that cannot be referenced by another resource. For example, you may want to allow another account to pull images from her ECR repository. The following arn_build function uses your account ID to build an IAM policy ARN.

# Allow another account to pull from the ECR repository data “aws_iam_policy_document” “cross_account_pull_ecr” { statement { sid = “AllowCrossAccountPull” effect = “Allow” principal { type = “AWS” identifiers = [ provider::aws::arn_build(“aws”, “iam”, “”, var.cross_account_id, “root”), ] } action = [ “ecr:BatchGetImage”, “ecr:GetDownloadUrlForLayer”, ] }}

The arn_build function helps guide and simplify the process of combining substrings to form an ARN, improving readability compared to using string interpolation. Without this, you would have to search the AWS documentation for the exact ARN structure and test it manually.

Terraform Google Cloud provider

The 5.23 release of the Terraform Google Cloud provider adds an easy way to get the region, zone, name, and project from the ID of unmanaged resources in your Terraform configuration. A provider-defined function now helps parse Google IDs when adding his IAM binding to resources managed outside of Terraform.

resource “google_cloud_run_service_iam_member” “example_run_invoker_jane” { member = “user:[email protected]” role = “run.invoker” service = Provider::google::name_from_id(var.example_cloud_run_service_id) location = Provider::google::location_from_id( var.example_cloud_run_service_id) Project = Provider::google::project_from_id(var.example_cloud_run_service_id)}

The Google Cloud provider also includes a new region_from_zone provider-defined function that helps you retrieve the region name from a specific zone (for example, us-west1-a to us-west1). This simple string processing could previously be accomplished in multiple ways using Terraforms built-in functions, but new functions simplify the process.

locals {zone = us-central1-a # How to derive region us-central1 using built-in functions region_1 = join(“-“, slide(split(“-“, local.zone), 0, 2)) region_2 = substr(local.zone, 0, length(local.zone)-2) # The new region_from_zone function makes this easy. region_3 = Provider::google::region_from_zone(local.zone)}Terraform Kubernetes Provider

The 2.28 release of the Terraform Kubernetes provider includes provider-defined functions for encoding and decoding Kubernetes manifests into Terraform, making it easier for practitioners to work with kubernetes_manifest resources.

Users with a Kubernetes manifest in YAML format can convert it to a Terraform object using the manifest_decode function. The example below shows how to use the manifest_decode function by referring to his YAML-formatted Kubernetes manifest embedded in the Terraform configuration.

local { manifest =

If you want to decode a YAML file instead of using the embedded YAML format, you can use the built-in file and manifest_decode functions to decode it.

$ cat manifest.yaml—Type: NamespaceapiVersion: v1metadata: Name: Test Label: Name: Test Resource “kubernetes_manifest” “example” { manifest = provider::kubernetes::manifest_decode(file(“${path.module}/ manifest) .yaml”))}

If your manifest YAML contains multiple Kubernetes resources, you can use the manifest_decode_multi function to decode them into a list that you can use in the for_each attribute of the kubernetes_manifest resource.

$ cat manifest.yaml—Type: NamespaceapiVersion: v1metadata: Name: test-1 Label: Name: test-1—Type: NamespaceapiVersion: v1metadata: Name: test-2 Label: Name: test-2 Resource “kubernetes_manifest ” ” “example” { for_each = { for m in Provider::kubernetes::manifest_decode_multi(file(“${path.module}/manifest.yaml”))): m.metadata.name => m } manifest = each . value}Start using provider-defined functions

Provider-defined functions allow you to declare performer intent and make Terraform configurations more expressive and readable by reducing complex and repetitive expressions. To learn about all of the new launch date provider-defined functions, check the documentation and changelogs for the aforementioned providers.

For more information about how provider-defined functions work and how to create your own, see the Terraform plugin framework documentation. We would like to thank our partners and community members for their valuable contributions to the HashiCorp Terraform ecosystem.

Sources

1/ https://Google.com/

2/ https://www.hashicorp.com/blog/terraform-1-8-adds-provider-functions-for-aws-google-cloud-and-kubernetes

The mention sources can contact us to remove/changing this article

What Are The Main Benefits Of Comparing Car Insurance Quotes Online

LOS ANGELES, CA / ACCESSWIRE / June 24, 2020, / Compare-autoinsurance.Org has launched a new blog post that presents the main benefits of comparing multiple car insurance quotes. For more info and free online quotes, please visit https://compare-autoinsurance.Org/the-advantages-of-comparing-prices-with-car-insurance-quotes-online/ The modern society has numerous technological advantages. One important advantage is the speed at which information is sent and received. With the help of the internet, the shopping habits of many persons have drastically changed. The car insurance industry hasn't remained untouched by these changes. On the internet, drivers can compare insurance prices and find out which sellers have the best offers. View photos The advantages of comparing online car insurance quotes are the following: Online quotes can be obtained from anywhere and at any time. Unlike physical insurance agencies, websites don't have a specific schedule and they are available at any time. Drivers that have busy working schedules, can compare quotes from anywhere and at any time, even at midnight. Multiple choices. Almost all insurance providers, no matter if they are well-known brands or just local insurers, have an online presence. Online quotes will allow policyholders the chance to discover multiple insurance companies and check their prices. Drivers are no longer required to get quotes from just a few known insurance companies. Also, local and regional insurers can provide lower insurance rates for the same services. Accurate insurance estimates. Online quotes can only be accurate if the customers provide accurate and real info about their car models and driving history. Lying about past driving incidents can make the price estimates to be lower, but when dealing with an insurance company lying to them is useless. Usually, insurance companies will do research about a potential customer before granting him coverage. Online quotes can be sorted easily. Although drivers are recommended to not choose a policy just based on its price, drivers can easily sort quotes by insurance price. Using brokerage websites will allow drivers to get quotes from multiple insurers, thus making the comparison faster and easier. For additional info, money-saving tips, and free car insurance quotes, visit https://compare-autoinsurance.Org/ Compare-autoinsurance.Org is an online provider of life, home, health, and auto insurance quotes. This website is unique because it does not simply stick to one kind of insurance provider, but brings the clients the best deals from many different online insurance carriers. In this way, clients have access to offers from multiple carriers all in one place: this website. On this site, customers have access to quotes for insurance plans from various agencies, such as local or nationwide agencies, brand names insurance companies, etc. "Online quotes can easily help drivers obtain better car insurance deals. All they have to do is to complete an online form with accurate and real info, then compare prices", said Russell Rabichev, Marketing Director of Internet Marketing Company. CONTACT: Company Name: Internet Marketing CompanyPerson for contact Name: Gurgu CPhone Number: (818) 359-3898Email: [email protected]: https://compare-autoinsurance.Org/ SOURCE: Compare-autoinsurance.Org View source version on accesswire.Com:https://www.Accesswire.Com/595055/What-Are-The-Main-Benefits-Of-Comparing-Car-Insurance-Quotes-Online View photos

ExBUlletin

to request, modification Contact us at Here or [email protected]