Skip to content

Commit

Permalink
provider/aws: Remove unsafe ptr dereferencing from ECS/ECR (#8514)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored and stack72 committed Aug 28, 2016
1 parent ee4f96e commit 2223964
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions builtin/providers/aws/resource_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func resourceAwsEcrRepositoryCreate(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] ECR repository created: %q", *repository.RepositoryArn)

d.SetId(*repository.RepositoryName)
d.Set("arn", *repository.RepositoryArn)
d.Set("registry_id", *repository.RegistryId)
d.Set("arn", repository.RepositoryArn)
d.Set("registry_id", repository.RegistryId)

return resourceAwsEcrRepositoryRead(d, meta)
}
Expand All @@ -86,8 +86,8 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] Received repository %s", out)

d.SetId(*repository.RepositoryName)
d.Set("arn", *repository.RepositoryArn)
d.Set("registry_id", *repository.RegistryId)
d.Set("arn", repository.RepositoryArn)
d.Set("registry_id", repository.RegistryId)
d.Set("name", repository.RepositoryName)

repositoryUrl := buildRepositoryUrl(repository, meta.(*AWSClient).region)
Expand Down
6 changes: 3 additions & 3 deletions builtin/providers/aws/resource_aws_ecr_repository_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func resourceAwsEcrRepositoryPolicyCreate(d *schema.ResourceData, meta interface
log.Printf("[DEBUG] ECR repository policy created: %s", *repositoryPolicy.RepositoryName)

d.SetId(*repositoryPolicy.RepositoryName)
d.Set("registry_id", *repositoryPolicy.RegistryId)
d.Set("registry_id", repositoryPolicy.RegistryId)

return resourceAwsEcrRepositoryPolicyRead(d, meta)
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func resourceAwsEcrRepositoryPolicyRead(d *schema.ResourceData, meta interface{}
repositoryPolicy := out

d.SetId(*repositoryPolicy.RepositoryName)
d.Set("registry_id", *repositoryPolicy.RegistryId)
d.Set("registry_id", repositoryPolicy.RegistryId)

return nil
}
Expand All @@ -110,7 +110,7 @@ func resourceAwsEcrRepositoryPolicyUpdate(d *schema.ResourceData, meta interface
repositoryPolicy := *out

d.SetId(*repositoryPolicy.RepositoryName)
d.Set("registry_id", *repositoryPolicy.RegistryId)
d.Set("registry_id", repositoryPolicy.RegistryId)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/aws/resource_aws_ecs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func resourceAwsEcsClusterCreate(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] ECS cluster %s created", *out.Cluster.ClusterArn)

d.SetId(*out.Cluster.ClusterArn)
d.Set("name", *out.Cluster.ClusterName)
d.Set("name", out.Cluster.ClusterName)
return nil
}

Expand Down
14 changes: 7 additions & 7 deletions builtin/providers/aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,21 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Received ECS service %s", service)

d.SetId(*service.ServiceArn)
d.Set("name", *service.ServiceName)
d.Set("name", service.ServiceName)

// Save task definition in the same format
if strings.HasPrefix(d.Get("task_definition").(string), "arn:aws:ecs:") {
d.Set("task_definition", *service.TaskDefinition)
d.Set("task_definition", service.TaskDefinition)
} else {
taskDefinition := buildFamilyAndRevisionFromARN(*service.TaskDefinition)
d.Set("task_definition", taskDefinition)
}

d.Set("desired_count", *service.DesiredCount)
d.Set("desired_count", service.DesiredCount)

// Save cluster in the same format
if strings.HasPrefix(d.Get("cluster").(string), "arn:aws:ecs:") {
d.Set("cluster", *service.ClusterArn)
d.Set("cluster", service.ClusterArn)
} else {
clusterARN := getNameFromARN(*service.ClusterArn)
d.Set("cluster", clusterARN)
Expand All @@ -224,16 +224,16 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error {
// Save IAM role in the same format
if service.RoleArn != nil {
if strings.HasPrefix(d.Get("iam_role").(string), "arn:aws:iam:") {
d.Set("iam_role", *service.RoleArn)
d.Set("iam_role", service.RoleArn)
} else {
roleARN := getNameFromARN(*service.RoleArn)
d.Set("iam_role", roleARN)
}
}

if service.DeploymentConfiguration != nil {
d.Set("deployment_maximum_percent", *service.DeploymentConfiguration.MaximumPercent)
d.Set("deployment_minimum_healthy_percent", *service.DeploymentConfiguration.MinimumHealthyPercent)
d.Set("deployment_maximum_percent", service.DeploymentConfiguration.MaximumPercent)
d.Set("deployment_minimum_healthy_percent", service.DeploymentConfiguration.MinimumHealthyPercent)
}

if service.LoadBalancers != nil {
Expand Down
8 changes: 4 additions & 4 deletions builtin/providers/aws/resource_aws_ecs_task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resourceAwsEcsTaskDefinitionCreate(d *schema.ResourceData, meta interface{}
*taskDefinition.TaskDefinitionArn, *taskDefinition.Revision)

d.SetId(*taskDefinition.Family)
d.Set("arn", *taskDefinition.TaskDefinitionArn)
d.Set("arn", taskDefinition.TaskDefinitionArn)

return resourceAwsEcsTaskDefinitionRead(d, meta)
}
Expand All @@ -160,9 +160,9 @@ func resourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{})
taskDefinition := out.TaskDefinition

d.SetId(*taskDefinition.Family)
d.Set("arn", *taskDefinition.TaskDefinitionArn)
d.Set("family", *taskDefinition.Family)
d.Set("revision", *taskDefinition.Revision)
d.Set("arn", taskDefinition.TaskDefinitionArn)
d.Set("family", taskDefinition.Family)
d.Set("revision", taskDefinition.Revision)
d.Set("container_definitions", taskDefinition.ContainerDefinitions)
d.Set("task_role_arn", taskDefinition.TaskRoleArn)
d.Set("network_mode", taskDefinition.NetworkMode)
Expand Down

0 comments on commit 2223964

Please sign in to comment.