pbobov / terraform-provider-ssm

Terraform provider for AWS Systems Manager service
https://registry.terraform.io/providers/pbobov/ssm/latest
Apache License 2.0
2 stars 1 forks source link

An AWS region is required #17

Open iadminko opened 2 months ago

iadminko commented 2 months ago

Terraform Version

Affected Resource(s)

Terraform Configuration Files

resource "ssm_command" "greeting" {
  document_name = "AWS-RunShellScript"
  parameters {
    name   = "commands"
    values = ["echo 'Hello World!'"]
  }
  destroy_document_name = "AWS-RunShellScript"
  destroy_parameters {
    name   = "commands"
    values = ["echo 'Goodbye World.'"]
  }
  targets {
    key    = "InstanceIds"
    values = [aws_instance.world.id]
  }
  comment           = "Greetings from SSM!"
  execution_timeout = 600
  output_location {
    s3_bucket_name = aws_s3_bucket.output.bucket
    s3_key_prefix  = "greetings"
  }
}

Debug Output

Error: operation error EC2: DescribeInstances, failed to resolve service endpoint, an AWS region is required, but was not found
│
│   with ssm_command.greeting,
│   on ssm.runcommand.tf line 14, in resource "ssm_command" "greeting":
│   14: resource "ssm_command" "greeting" {

Expected Behavior

What should have happened?

Actual Behavior

Steps to Reproduce

terraform apply

zett93 commented 1 month ago

same problem here :(

pbobov commented 4 weeks ago

It looks like for the provider to work the AWS region must be set in the environment of the Terraform execution by AWS_DEFAULT_REGION environment variable. I'll add "region" provider attribute to support setting region at the provider level.

iadminko commented 4 weeks ago

It looks like for the provider to work the AWS region must be set in the environment of the Terraform execution by AWS_DEFAULT_REGION environment variable. I'll add "region" provider attribute to support setting region at the provider level.

There is a bit deep issue, if i'm not wrong - in case if you use just the single profile configured AWS CLI, the module is working, but as soon as you use a multi profile setup, the region is not pulled in to the module.

zett93 commented 2 weeks ago

In my case it doesn't work through Azure DevOps pipeline (IMO it should use a variable to configure the region), AND another thing, when I added AWS_DEFAULT_REGION to the pipeline, it didn't work either. It says there are no EC2 instances (but there are 100%)

pbobov commented 2 weeks ago

It says there are no EC2 instances (but there are 100%)

Are the EC2 instances "managed by SSM" (have SSM agent installed and the IAM role has permissions required by the SSM agent)?

pbobov commented 2 weeks ago

The AWS client configuration (region and credentials) is loaded here https://github.com/pbobov/terraform-provider-ssm/blob/main/awstools/command.go#L42.

See https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/