-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new data source aws_batch_job_queue #4288
Changes from 2 commits
8fc1a72
6b38310
bb13a65
956d865
5536d8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/batch" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsBatchJobQueue() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsBatchJobQueueRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"status_reason": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"priority": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"compute_environment_order": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"compute_environment": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"order": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsBatchJobQueueRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).batchconn | ||
|
||
params := &batch.DescribeJobQueuesInput{ | ||
JobQueues: []*string{aws.String(d.Get("name").(string))}, | ||
} | ||
log.Printf("[DEBUG] Reading Batch Job Queue: %s", params) | ||
desc, err := conn.DescribeJobQueues(params) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(desc.JobQueues) == 0 { | ||
return fmt.Errorf("no matches found for name: %s", d.Get("name").(string)) | ||
} | ||
|
||
if len(desc.JobQueues) > 1 { | ||
return fmt.Errorf("multiple matches found for name: %s", d.Get("name").(string)) | ||
} | ||
|
||
jobQueue := desc.JobQueues[0] | ||
d.SetId(aws.StringValue(jobQueue.JobQueueArn)) | ||
d.Set("arn", jobQueue.JobQueueArn) | ||
d.Set("name", jobQueue.JobQueueName) | ||
d.Set("status", jobQueue.Status) | ||
d.Set("status_reason", jobQueue.StatusReason) | ||
d.Set("state", jobQueue.State) | ||
d.Set("priority", jobQueue.Priority) | ||
|
||
ceos := make([]map[string]interface{}, 0) | ||
for _, v := range jobQueue.ComputeEnvironmentOrder { | ||
ceo := map[string]interface{}{} | ||
ceo["compute_environment"] = *v.ComputeEnvironment | ||
ceo["order"] = *v.Order | ||
ceos = append(ceos, ceo) | ||
} | ||
d.Set("compute_environment_order", ceos) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When calling if err := d.Set("compute_environment_order", ceos); err != nil {
return fmt.Errorf("error setting compute_environment_order: %s", err)
} I can tell you from looking at the the existing |
||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDataSourceAwsBatchJobQueue(t *testing.T) { | ||
rName := acctest.RandomWithPrefix("tf_acc_test_") | ||
resourceName := "aws_batch_job_queue.test" | ||
datasourceName := "data.aws_batch_job_queue.by_name" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDataSourceAwsBatchJobQueueConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourceAwsBatchJobQueueCheck(datasourceName, resourceName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsBatchJobQueueCheck(datasourceName, resourceName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
ds, ok := s.RootModule().Resources[datasourceName] | ||
if !ok { | ||
return fmt.Errorf("root module has no data source called %s", datasourceName) | ||
} | ||
|
||
jobQueueRs, ok := s.RootModule().Resources[resourceName] | ||
if !ok { | ||
return fmt.Errorf("root module has no resource called %s", resourceName) | ||
} | ||
|
||
attrNames := []string{ | ||
"arn", | ||
"name", | ||
"state", | ||
"priority", | ||
} | ||
|
||
for _, attrName := range attrNames { | ||
if ds.Primary.Attributes[attrName] != jobQueueRs.Primary.Attributes[attrName] { | ||
return fmt.Errorf( | ||
"%s is %s; want %s", | ||
attrName, | ||
ds.Primary.Attributes[attrName], | ||
jobQueueRs.Primary.Attributes[attrName], | ||
) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccDataSourceAwsBatchJobQueueConfig(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_batch_job_queue" "test" { | ||
name = "%[1]s" | ||
state = "ENABLED" | ||
priority = 1 | ||
compute_environments = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A value is required inside this list:
|
||
} | ||
|
||
resource "aws_batch_job_queue" "wrong" { | ||
name = "%[1]s_wrong" | ||
state = "ENABLED" | ||
priority = 2 | ||
compute_environments = [] | ||
} | ||
|
||
data "aws_batch_job_queue" "by_name" { | ||
name = "${aws_batch_job_queue.test.name}" | ||
} | ||
`, rName) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,9 @@ | |
<li<%= sidebar_current("docs-aws-datasource-availability-zones") %>> | ||
<a href="/docs/providers/aws/d/availability_zones.html">aws_availability_zones</a> | ||
</li> | ||
<li<%= sidebar_current("docs-aws-datasource-batch-job-queue") %>> | ||
<a href="/docs/providers/aws/d/batch_job_queue.html">aws_batch_job_queue</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
</li> | ||
<li<%= sidebar_current("docs-aws-datasource-billing-service-account") %>> | ||
<a href="/docs/providers/aws/d/billing_service_account.html">aws_billing_service_account</a> | ||
</li> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_batch_job_queue | ||
sidebar_current: "docs-aws-datasource-batch-job-queue | ||
description: |- | ||
Provides details about a batch job queue | ||
--- | ||
|
||
# Data Source: aws_batch_job_queue | ||
|
||
The Batch Job Queue data source allows access to details of a specific | ||
job queue within AWS Batch. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_batch_job_queue" "test-queue" { | ||
name = "tf-test-batch-job-queue" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the job queue. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `arn` - The ARN of the job queue. | ||
* `status` - The current status of the job queue (for example, `CREATING` or `VALID`). | ||
* `status_reason` - A short, human-readable string to provide additional details about the current status | ||
of the job queue. | ||
* `state` - Describes the ability of the queue to accept new jobs (for example, `ENABLED` or `DISABLED`). | ||
* `priority` - The priority of the job queue. Job queues with a higher priority are evaluated first when | ||
associated with the same compute environment. | ||
* `compute_environment_order` - The compute environments that are attached to the job queue and the order in | ||
which job placement is preferred. Compute environments are selected for job placement in ascending order. | ||
* `compute_environment_order.#.order` - The order of the compute environment. | ||
* `compute_environment_order.#.compute_environment` - The ARN of the compute environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent provider panics, we should opt to safely read these: