Skip to content
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

Adding VPC config #2

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions aws/resource_aws_sagemaker_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ func resourceAwsSagemakerModel() *schema.Resource {
},
},

"vpc_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"subnets": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"security_group_ids": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},

"execution_role_arn": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -113,6 +134,11 @@ func resourceAwsSagemakerModelCreate(d *schema.ResourceData, meta interface{}) e
createOpts.Tags = tagsFromMapSagemaker(v.(map[string]interface{}))
}

if v, ok := d.GetOk("vpc_config"); ok {
vpcConfig := expandSageMakerVpcConfigRequest(v.([]interface{}))
createOpts.SetVpcConfig(vpcConfig)
}

log.Printf("[DEBUG] Sagemaker model create config: %#v", *createOpts)
modelResponse, err := retryOnAwsCode("ValidationException", func() (interface{}, error) {
return conn.CreateModel(createOpts)
Expand All @@ -131,6 +157,19 @@ func resourceAwsSagemakerModelCreate(d *schema.ResourceData, meta interface{}) e
return resourceAwsSagemakerModelUpdate(d, meta)
}

func expandSageMakerVpcConfigRequest(l []interface{}) *sagemaker.VpcConfig {
if len(l) == 0 {
return nil
}

m := l[0].(map[string]interface{})

return &sagemaker.VpcConfig{
SecurityGroupIds: expandStringSet(m["security_group_ids"].(*schema.Set)),
Subnets: expandStringSet(m["subnets"].(*schema.Set)),
}
}

func resourceAwsSagemakerModelRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sagemakerconn

Expand Down Expand Up @@ -162,6 +201,9 @@ func resourceAwsSagemakerModelRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("creation_time", model.CreationTime.Format(time.RFC3339)); err != nil {
return err
}
if err := d.Set("vpc_config", flattenSageMakerVpcConfigResponse(model.VpcConfig)); err != nil {
return fmt.Errorf("error setting vpc_config: %s", err)
}

tagsOutput, err := conn.ListTags(&sagemaker.ListTagsInput{
ResourceArn: model.ModelArn,
Expand All @@ -171,6 +213,19 @@ func resourceAwsSagemakerModelRead(d *schema.ResourceData, meta interface{}) err
return nil
}

func flattenSageMakerVpcConfigResponse(vpcConfig *sagemaker.VpcConfig) []map[string]interface{} {
if vpcConfig == nil {
return []map[string]interface{}{}
}

m := map[string]interface{}{
"security_group_ids": schema.NewSet(schema.HashString, flattenStringList(vpcConfig.SecurityGroupIds)),
"subnets": schema.NewSet(schema.HashString, flattenStringList(vpcConfig.Subnets)),
}

return []map[string]interface{}{m}
}

func resourceAwsSagemakerModelUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sagemakerconn

Expand Down