Skip to content

Commit

Permalink
Go upgrade to 1.20 (#2605)
Browse files Browse the repository at this point in the history
* Upgrade to go 1.20

* Go 1.20 formatting update
  • Loading branch information
denis256 authored Jun 15, 2023
1 parent d59c964 commit 1d18109
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ orbs:

defaults: &defaults
docker:
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.18-tf1.4-tg39.1-pck1.8-ci50.7
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.20-tf1.4-tg39.1-pck1.8-ci50.7

version: 2.1
jobs:
Expand Down
2 changes: 1 addition & 1 deletion _ci/install-golang.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Install golang using Chocolatey
choco install golang --version 1.18.5 -y
choco install golang --version 1.20.0 -y
# Verify installation
Get-Command go
go version
7 changes: 4 additions & 3 deletions aws_helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ func getSTSCredentialsFromIAMRoleOptions(sess *session.Session, iamRoleOptions o
}

// Returns an AWS session object. The session is configured by either:
// - The provided AwsSessionConfig struct, which specifies region (required), profile name (optional), and IAM role to
// assume (optional).
// - The provided TerragruntOptions struct, which specifies any IAM role to assume (optional).
// - The provided AwsSessionConfig struct, which specifies region (required), profile name (optional), and IAM role to
// assume (optional).
// - The provided TerragruntOptions struct, which specifies any IAM role to assume (optional).
//
// Note that if the AwsSessionConfig object is null, this will return default session credentials using the default
// credentials chain of the AWS SDK.
func CreateAwsSession(config *AwsSessionConfig, terragruntOptions *options.TerragruntOptions) (*session.Session, error) {
Expand Down
79 changes: 41 additions & 38 deletions cli/aws_provider_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ const awsProviderPatchHelp = `
//
// For example, if were running Terragrunt against code that contained a module:
//
// module "example" {
// source = "<URL>"
// }
// 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
// }
// provider "aws" {
// region = var.aws_region
// }
//
// And if AwsProviderPatchOverrides in terragruntOptions 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"
// }
// 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
Expand Down Expand Up @@ -158,15 +158,15 @@ func findAllTerraformFilesInModules(terragruntOptions *options.TerragruntOptions
//
// For example, if you passed in the following Terraform code:
//
// provider "aws" {
// region = var.aws_region
// }
// 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"
// }
// 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
Expand Down Expand Up @@ -209,12 +209,12 @@ func patchAwsProviderInTerraformCode(terraformCode string, terraformFilePath str
//
// Assume that block1 is:
//
// provider "aws" {
// region = var.aws_region
// assume_role {
// role_arn = var.role_arn
// }
// }
// provider "aws" {
// region = var.aws_region
// assume_role {
// role_arn = var.role_arn
// }
// }
//
// If you call:
//
Expand All @@ -223,12 +223,12 @@ func patchAwsProviderInTerraformCode(terraformCode string, terraformFilePath str
//
// The result would be:
//
// provider "aws" {
// region = "eu-west-1"
// assume_role {
// role_arn = "foo"
// }
// }
// provider "aws" {
// region = "eu-west-1"
// assume_role {
// role_arn = "foo"
// }
// }
//
// Assume block2 is:
//
Expand All @@ -239,7 +239,6 @@ func patchAwsProviderInTerraformCode(terraformCode string, terraformFilePath str
// overrideAttributeInBlock(block2, "region", "eu-west-1")
// overrideAttributeInBlock(block2, "assume_role.role_arn", "foo")
//
//
// The result would be:
//
// provider "aws" {}
Expand Down Expand Up @@ -285,24 +284,28 @@ func overrideAttributeInBlock(block *hclwrite.Block, key string, value string) (
//
// Assume block is:
//
// provider "aws" {
// region = var.aws_region
// assume_role {
// role_arn = var.role_arn
// }
// }
// provider "aws" {
// region = var.aws_region
// assume_role {
// role_arn = var.role_arn
// }
// }
//
// traverseBlock(block, []string{"region"})
// => returns (<body of the current block>, "region")
//
// => returns (<body of the current block>, "region")
//
// traverseBlock(block, []string{"assume_role", "role_arn"})
// => returns (<body of the nested assume_role block>, "role_arn")
//
// => returns (<body of the nested assume_role block>, "role_arn")
//
// traverseBlock(block, []string{"foo"})
// => returns (nil, "")
//
// => returns (nil, "")
//
// traverseBlock(block, []string{"assume_role", "foo"})
// => returns (nil, "")
//
// => returns (nil, "")
func traverseBlock(block *hclwrite.Block, keyParts []string) (*hclwrite.Body, string) {
if block == nil {
return nil, ""
Expand Down
82 changes: 44 additions & 38 deletions config/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ func handleIncludeForDependency(
// attributes defined in the targetConfig. Note that this will modify the targetConfig.
// NOTE: the following attributes are deliberately omitted from the merge operation, as they are handled differently in
// the parser:
// - locals [These blocks are not merged by design]
// - locals [These blocks are not merged by design]
//
// NOTE: dependencies block is a special case and is merged deeply. This is necessary to ensure the configstack system
// works correctly, as it uses the `Dependencies` list to track the dependencies of modules for graph building purposes.
// This list includes the dependencies added from dependency blocks, which is handled in a different stage.
Expand Down Expand Up @@ -337,19 +338,19 @@ func (targetConfig *TerragruntConfig) Merge(sourceConfig *TerragruntConfig, terr
}

// DeepMerge performs a deep merge of the given sourceConfig into the targetConfig. Deep merge is defined as follows:
// - For simple types, the source overrides the target.
// - For lists, the two attribute lists are combined together in concatenation.
// - For maps, the two maps are combined together recursively. That is, if the map keys overlap, then a deep merge is
// performed on the map value.
// - Note that some structs are not deep mergeable due to an implementation detail. This will change in the future. The
// following structs have this limitation:
// - remote_state
// - generate
// - Note that the following attributes are deliberately omitted from the merge operation, as they are handled
// differently in the parser:
// - dependency blocks (TerragruntDependencies) [These blocks need to retrieve outputs, so we need to merge during
// the parsing step, not after the full config is decoded]
// - locals [These blocks are not merged by design]
// - For simple types, the source overrides the target.
// - For lists, the two attribute lists are combined together in concatenation.
// - For maps, the two maps are combined together recursively. That is, if the map keys overlap, then a deep merge is
// performed on the map value.
// - Note that some structs are not deep mergeable due to an implementation detail. This will change in the future. The
// following structs have this limitation:
// - remote_state
// - generate
// - Note that the following attributes are deliberately omitted from the merge operation, as they are handled
// differently in the parser:
// - dependency blocks (TerragruntDependencies) [These blocks need to retrieve outputs, so we need to merge during
// the parsing step, not after the full config is decoded]
// - locals [These blocks are not merged by design]
func (targetConfig *TerragruntConfig) DeepMerge(sourceConfig *TerragruntConfig, terragruntOptions *options.TerragruntOptions) error {
// Merge simple attributes first
if sourceConfig.DownloadDir != "" {
Expand Down Expand Up @@ -738,37 +739,42 @@ func updateBareIncludeBlock(file *hcl.File, filename string) ([]byte, bool, erro
// block:
//
// Case 1: a single include block as top level:
// {
// "include": {
// "path": "foo"
// }
// }
//
// {
// "include": {
// "path": "foo"
// }
// }
//
// Case 2: a single include block in list:
// {
// "include": [
// {"path": "foo"}
// ]
// }
//
// {
// "include": [
// {"path": "foo"}
// ]
// }
//
// Case 3: mixed bare and labeled include block as list:
// {
// "include": [
// {"path": "foo"},
// {
// "labeled": {"path": "bar"}
// }
// ]
// }
//
// {
// "include": [
// {"path": "foo"},
// {
// "labeled": {"path": "bar"}
// }
// ]
// }
//
// For simplicity of implementation, we focus on handling Case 1 and 2, and ignore Case 3. If we see Case 3, we will
// error out. Instead, the user should handle this case explicitly using the object encoding instead of list encoding:
// {
// "include": {
// "": {"path": "foo"},
// "labeled": {"path": "bar"}
// }
// }
//
// {
// "include": {
// "": {"path": "foo"},
// "labeled": {"path": "bar"}
// }
// }
//
// If the multiple include blocks are encoded in this way in the json configuration, nothing needs to be done by this
// function.
func updateBareIncludeBlockJSON(fileBytes []byte) ([]byte, bool, error) {
Expand Down
7 changes: 4 additions & 3 deletions config/locals.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ type Local struct {

// evaluateLocalsBlock is a routine to evaluate the locals block in a way to allow references to other locals. This
// will:
// - Extract a reference to the locals block from the parsed file
// - Continuously evaluate the block until all references are evaluated, defering evaluation of anything that references
// other locals until those references are evaluated.
// - Extract a reference to the locals block from the parsed file
// - Continuously evaluate the block until all references are evaluated, defering evaluation of anything that references
// other locals until those references are evaluated.
//
// This returns a map of the local names to the evaluated expressions (represented as `cty.Value` objects). This will
// error if there are remaining unevaluated locals after all references that can be evaluated has been evaluated.
func evaluateLocalsBlock(
Expand Down
8 changes: 4 additions & 4 deletions configstack/running_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func toRunningModules(modules []*TerraformModule, dependencyOrder DependencyOrde

// Loop through the map of runningModules and for each module M:
//
// * If dependencyOrder is NormalOrder, plug in all the modules M depends on into the Dependencies field and all the
// modules that depend on M into the NotifyWhenDone field.
// * If dependencyOrder is ReverseOrder, do the reverse.
// * If dependencyOrder is IgnoreOrder, do nothing.
// - If dependencyOrder is NormalOrder, plug in all the modules M depends on into the Dependencies field and all the
// modules that depend on M into the NotifyWhenDone field.
// - If dependencyOrder is ReverseOrder, do the reverse.
// - If dependencyOrder is IgnoreOrder, do nothing.
func crossLinkDependencies(modules map[string]*runningModule, dependencyOrder DependencyOrder) (map[string]*runningModule, error) {
for _, module := range modules {
for _, dependency := range module.Module.Dependencies {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gruntwork-io/terragrunt

go 1.18
go 1.20

require (
cloud.google.com/go/storage v1.27.0
Expand Down
2 changes: 1 addition & 1 deletion remote/remote_state_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func TestGetTerraformInitArgs(t *testing.T) {
}

// Test to validate cases when is not possible to read all S3 configurations
//https://github.com/gruntwork-io/terragrunt/issues/2109
// https://github.com/gruntwork-io/terragrunt/issues/2109
func TestNegativePublicAccessResponse(t *testing.T) {
t.Parallel()
testCases := []struct {
Expand Down
29 changes: 15 additions & 14 deletions util/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ func KindOf(value interface{}) reflect.Kind {
}

// MustWalkTerraformOutput is a helper utility to deeply return a value from a terraform output.
// nil will be returned if the path is invalid
//
// Using an example terraform output:
// a = {
// b = {
// c = "foo"
// }
// "d" = [
// 1,
// 2
// ]
// }
// nil will be returned if the path is invalid
//
// path ["a", "b", "c"] will return "foo"
// path ["a", "d", "1"] will return 2
// path ["a", "foo"] will return nil
// Using an example terraform output:
// a = {
// b = {
// c = "foo"
// }
// "d" = [
// 1,
// 2
// ]
// }
//
// path ["a", "b", "c"] will return "foo"
// path ["a", "d", "1"] will return 2
// path ["a", "foo"] will return nil
func MustWalkTerraformOutput(value interface{}, path ...string) interface{} {
if value == nil {
return nil
Expand Down

0 comments on commit 1d18109

Please sign in to comment.