awsproviderpatch

package
v0.68.14-beta2024111501 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package awsproviderpatch provides the `aws-provider-patch` command.

The `aws-provider-patch` command finds all Terraform modules nested in the current code (i.e., in the .terraform/modules folder), looks for provider "aws" { ... } blocks in those modules, and overwrites the attributes in those provider blocks with the attributes specified in terragrntOptions.

For example, if were running Terragrunt against code that contained a module:

module "example" {
  source = "<URL>"
}

When you run 'init', Terraform would download the code for that module into .terraform/modules. This function would scan that module code for provider blocks:

provider "aws" {
   region = var.aws_region
}

And if AwsProviderPatchOverrides in opts was set to map[string]string{"region": "us-east-1"}, then this method would update the module code to:

provider "aws" {
   region = "us-east-1"
}

This is a temporary workaround for a Terraform bug (https://github.com/hashicorp/terraform/issues/13018) where any dynamic values in nested provider blocks are not handled correctly when you call 'terraform import', so by temporarily hard-coding them, we can allow 'import' to work.

Index

Constants

View Source
const (
	CommandName = "aws-provider-patch"

	FlagNameTerragruntOverrideAttr = "terragrunt-override-attr"
)

Variables

This section is empty.

Functions

func NewCommand

func NewCommand(opts *options.TerragruntOptions) *cli.Command

func NewFlags

func NewFlags(opts *options.TerragruntOptions) cli.Flags

func PatchAwsProviderInTerraformCode added in v0.66.7

func PatchAwsProviderInTerraformCode(terraformCode string, terraformFilePath string, attributesToOverride map[string]string) (string, bool, error)

PatchAwsProviderInTerraformCode looks for provider "aws" { ... } blocks in the given Terraform code and overwrites the attributes in those provider blocks with the given attributes. It returns the new Terraform code and a boolean true if that code was updated.

For example, if you passed in the following Terraform code:

provider "aws" {
   region = var.aws_region
}

And you set attributesToOverride to map[string]string{"region": "us-east-1"}, then this method will return:

provider "aws" {
   region = "us-east-1"
}

This is a temporary workaround for a Terraform bug (https://github.com/hashicorp/terraform/issues/13018) where any dynamic values in nested provider blocks are not handled correctly when you call 'terraform import', so by temporarily hard-coding them, we can allow 'import' to work.

func Run

Types

type MalformedJSONValError

type MalformedJSONValError struct {
	// contains filtered or unexported fields
}

func (MalformedJSONValError) Error

func (err MalformedJSONValError) Error() string

type MissingOverrideAttrError

type MissingOverrideAttrError string

func (MissingOverrideAttrError) Error

func (flagName MissingOverrideAttrError) Error() string

type TerraformModule

type TerraformModule struct {
	Key    string `json:"Key"`
	Source string `json:"Source"`
	Dir    string `json:"Dir"`
}

type TerraformModulesJSON added in v0.67.7

type TerraformModulesJSON struct {
	Modules []TerraformModule `json:"Modules"`
}

TerraformModulesJSON is the format we expect in the .terraform/modules/modules.json file

type TypeInferenceError

type TypeInferenceError struct {
	// contains filtered or unexported fields
}

func (TypeInferenceError) Error

func (err TypeInferenceError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL