github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/data_source_aws_ecs_task_definition.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/aws/aws-sdk-go/aws"
     7  	"github.com/aws/aws-sdk-go/service/ecs"
     8  	"github.com/hashicorp/terraform/helper/schema"
     9  )
    10  
    11  func dataSourceAwsEcsTaskDefinition() *schema.Resource {
    12  	return &schema.Resource{
    13  		Read: dataSourceAwsEcsTaskDefinitionRead,
    14  
    15  		Schema: map[string]*schema.Schema{
    16  			"task_definition": &schema.Schema{
    17  				Type:     schema.TypeString,
    18  				Required: true,
    19  				ForceNew: true,
    20  			},
    21  			// Computed values.
    22  			"family": &schema.Schema{
    23  				Type:     schema.TypeString,
    24  				Computed: true,
    25  			},
    26  			"network_mode": &schema.Schema{
    27  				Type:     schema.TypeString,
    28  				Computed: true,
    29  			},
    30  			"revision": &schema.Schema{
    31  				Type:     schema.TypeInt,
    32  				Computed: true,
    33  			},
    34  			"status": &schema.Schema{
    35  				Type:     schema.TypeString,
    36  				Computed: true,
    37  			},
    38  			"task_role_arn": &schema.Schema{
    39  				Type:     schema.TypeString,
    40  				Computed: true,
    41  			},
    42  		},
    43  	}
    44  }
    45  
    46  func dataSourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{}) error {
    47  	conn := meta.(*AWSClient).ecsconn
    48  
    49  	desc, err := conn.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
    50  		TaskDefinition: aws.String(d.Get("task_definition").(string)),
    51  	})
    52  
    53  	if err != nil {
    54  		return err
    55  	}
    56  
    57  	taskDefinition := *desc.TaskDefinition
    58  
    59  	d.SetId(aws.StringValue(taskDefinition.TaskDefinitionArn))
    60  	d.Set("family", aws.StringValue(taskDefinition.Family))
    61  	d.Set("network_mode", aws.StringValue(taskDefinition.NetworkMode))
    62  	d.Set("revision", aws.Int64Value(taskDefinition.Revision))
    63  	d.Set("status", aws.StringValue(taskDefinition.Status))
    64  	d.Set("task_role_arn", aws.StringValue(taskDefinition.TaskRoleArn))
    65  
    66  	if d.Id() == "" {
    67  		return fmt.Errorf("task definition %q not found", d.Get("task_definition").(string))
    68  	}
    69  
    70  	return nil
    71  }