I'm very new to golang, so I'm trying to follow: terratest_code-base while buidling my test to read the cw log stream.

terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
            // The path to where our Terraform code is located to give the folder name
            TerraformDir: "../../",

            // Variables to pass to our Terraform code using -var options
            Vars: map[string]interface{}{
                "dynamo_db_table_name": expectedTableName,
                "token": token,
                "aws_region": awsRegion,
                "access_key": accessKey,
                "secret_key": secretKey,
                "environment": environment,
            },

            // Environment variables to set when running Terraform
            EnvVars: map[string]string{
                "AWS_DEFAULT_REGION": awsRegion,
                "AWS_ACCESS_KEY_ID": accessKey,
                "AWS_SECRET_ACCESS_KEY": secretKey,
                "AWS_SESSION_TOKEN": token,
            },
            // Backend config to create state file in S3
            BackendConfig: map[string]interface{}{
                "bucket": bucketName,
                "key":    key,
                "region": awsRegion,
            },
        })
    // At the end of the test, run `terraform destroy` to clean up any resources that were created
    defer terraform.Destroy(t, terraformOptions)

    // This will run `terraform init` and `terraform apply` and fail the test if there are any errors
    terraform.InitAndApply(t, terraformOptions)

client := aws.NewCloudWatchLogsClient(t, awsRegion)
    cw_main_log_group_prefix := terraform.Output(t, terraformOptions, "main_cloudwatch_log_name")

    groups, err := client.DescribeLogGroups(&cloudwatchlogs.DescribeLogGroupsInput{LogGroupNamePrefix: &cw_main_log_group_prefix})
    // cw_prefix_not_exist_msg := fmt.Sprintf("CW Log group %s does not exists", cw_main_log_group_prefix)
    if err != nil {
        assert.Error(t, errors.New("Error in "))
    }

    if len(groups.LogGroups) < 1 {
             assert.Error(t, errors.New(fmt.Sprintf("No log group found for %s", cw_main_log_group_prefix)))
    }

    group := groups.LogGroups[0]
    fmt.Println(group)
    streams, err := client.DescribeLogStreams(&cloudwatchlogs.DescribeLogStreamsInput{
            LogGroupName: group.LogGroupName,
            Descending:   awsSDK.Bool(true),
            OrderBy:      awsSDK.String("LastEventTime"),
    })

    if len(streams.LogStreams) < 1 {
          assert.Error(t, errors.New(fmt.Sprintf("No log streams found for %s", cw_main_log_group_prefix)))
    }

    stream := streams.LogStreams[0]
     message, err := aws.GetCloudWatchLogEntriesE(t, awsRegion, stream.LogStreamName, cw_main_log_group_prefix)

I'm getting below error:

cannot use stream.LogStreamName (variable of type *string) as type string in argument to aws.GetCloudWatchLogEntriesE

as the response from describeLogstream has string attribute called LogStreamName

My question is how to fix this?

can anyone suggest me how to follow carry out the test? only thing it prints is fmt.Println(group)

0

There are 0 best solutions below