Skip to content

Commit 569d2f1

Browse files
committed
ds/sagemaker_prebuilt_image_path: New data source
1 parent 2b6a2b2 commit 569d2f1

1 file changed

Lines changed: 353 additions & 0 deletions

File tree

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,353 @@
1+
package aws
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
8+
)
9+
10+
const (
11+
// Sagemaker Algorithm BlazingText
12+
sageMakerRepositoryBlazingText = "blazingtext"
13+
// Sagemaker Algorithm DeepAR Forecasting
14+
sageMakerRepositoryDeepARForecasting = "forecasting-deepar"
15+
// Sagemaker Algorithm Factorization Machines
16+
sageMakerRepositoryFactorizationMachines = "factorization-machines"
17+
// Sagemaker Algorithm Image Classification
18+
sageMakerRepositoryImageClassification = "image-classification"
19+
// Sagemaker Algorithm IP Insights
20+
sageMakerRepositoryIPInsights = "ipinsights"
21+
// Sagemaker Algorithm k-means
22+
sageMakerRepositoryKMeans = "kmeans"
23+
// Sagemaker Algorithm k-nearest-neighbor
24+
sageMakerRepositoryKNearestNeighbor = "knn"
25+
// Sagemaker Algorithm Latent Dirichlet Allocation
26+
sageMakerRepositoryLDA = "lda"
27+
// Sagemaker Algorithm Linear Learner
28+
sageMakerRepositoryLinearLearner = "linear-learner"
29+
// Sagemaker Algorithm Neural Topic Model
30+
sageMakerRepositoryNeuralTopicModel = "ntm"
31+
// Sagemaker Algorithm Object2Vec
32+
sageMakerRepositoryObject2Vec = "object2vec"
33+
// Sagemaker Algorithm Object Detection
34+
sageMakerRepositoryObjectDetection = "object-detection"
35+
// Sagemaker Algorithm PCA
36+
sageMakerRepositoryPCA = "pca"
37+
// Sagemaker Algorithm Random Cut Forest
38+
sageMakerRepositoryRandomCutForest = "randomcutforest"
39+
// Sagemaker Algorithm Semantic Segmentation
40+
sageMakerRepositorySemanticSegmentation = "semantic-segmentation"
41+
// Sagemaker Algorithm Seq2Seq
42+
sageMakerRepositorySeq2Seq = "seq2seq"
43+
// Sagemaker Algorithm XGBoost
44+
sageMakerRepositoryXGBoost = "sagemaker-xgboost"
45+
// Sagemaker Library scikit-learn
46+
sageMakerRepositoryScikitLearn = "sagemaker-scikit-learn"
47+
// Sagemaker Library Spark ML
48+
sageMakerRepositorySparkML = "sagemaker-sparkml-serving"
49+
// Sagemaker Repo MXNet Inference
50+
sageMakerRepositoryMXNetInference = "mxnet-inference"
51+
// Sagemaker Repo MXNet Inference EIA
52+
sageMakerRepositoryMXNetInferenceEIA = "mxnet-inference-eia"
53+
// Sagemaker Repo MXNet Training
54+
sageMakerRepositoryMXNetTraining = "mxnet-training"
55+
// Sagemaker Repo PyTorch Inference
56+
sageMakerRepositoryPyTorchInference = "pytorch-inference"
57+
// Sagemaker Repo PyTorch Inference EIA
58+
sageMakerRepositoryPyTorchInferenceEIA = "pytorch-inference-eia"
59+
// Sagemaker Repo PyTorch Training
60+
sageMakerRepositoryPyTorchTraining = "pytorch-training"
61+
// Sagemaker Repo TensorFlow Inference
62+
sageMakerRepositoryTensorFlowInference = "tensorflow-inference"
63+
// Sagemaker Repo TensorFlow Inference EIA
64+
sageMakerRepositoryTensorFlowInferenceEIA = "tensorflow-inference-eia"
65+
// Sagemaker Repo TensorFlow Training
66+
sageMakerRepositoryTensorFlowTraining = "tensorflow-training"
67+
)
68+
69+
// https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html
70+
var sageMakerPrebuiltImageIDByRegion_Blazing = map[string]string{
71+
"ap-east-1": "286214385809",
72+
"ap-northeast-1": "501404015308",
73+
"ap-northeast-2": "306986355934",
74+
"ap-south-1": "991648021394",
75+
"ap-southeast-1": "475088953585",
76+
"ap-southeast-2": "544295431143",
77+
"ca-central-1": "469771592824",
78+
"cn-north-1": "390948362332",
79+
"cn-northwest-1": "387376663083",
80+
"eu-central-1": "813361260812",
81+
"eu-north-1": "669576153137",
82+
"eu-west-1": "685385470294",
83+
"eu-west-2": "644912444149",
84+
"eu-west-3": "749696950732",
85+
"me-south-1": "249704162688",
86+
"sa-east-1": "855470959533",
87+
"us-east-1": "811284229777",
88+
"us-east-2": "825641698319",
89+
"us-gov-west-1": "226302683700",
90+
"us-west-1": "632365934929",
91+
"us-west-2": "433757028032",
92+
}
93+
94+
// https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html
95+
var sageMakerPrebuiltImageIDByRegion_DeepAR = map[string]string{
96+
"ap-east-1": "286214385809",
97+
"ap-northeast-1": "633353088612",
98+
"ap-northeast-2": "204372634319",
99+
"ap-south-1": "991648021394",
100+
"ap-southeast-1": "475088953585",
101+
"ap-southeast-2": "514117268639",
102+
"ca-central-1": "469771592824",
103+
"cn-north-1": "390948362332",
104+
"cn-northwest-1": "387376663083",
105+
"eu-central-1": "495149712605",
106+
"eu-north-1": "669576153137",
107+
"eu-west-1": "224300973850",
108+
"eu-west-2": "644912444149",
109+
"eu-west-3": "749696950732",
110+
"me-south-1": "249704162688",
111+
"sa-east-1": "855470959533",
112+
"us-east-1": "522234722520",
113+
"us-east-2": "566113047672",
114+
"us-gov-west-1": "226302683700",
115+
"us-west-1": "632365934929",
116+
"us-west-2": "156387875391",
117+
}
118+
119+
// https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html
120+
var sageMakerPrebuiltImageIDByRegion_FactorMachines = map[string]string{
121+
"ap-east-1": "286214385809",
122+
"ap-northeast-1": "351501993468",
123+
"ap-northeast-2": "835164637446",
124+
"ap-south-1": "991648021394",
125+
"ap-southeast-1": "475088953585",
126+
"ap-southeast-2": "712309505854",
127+
"ca-central-1": "469771592824",
128+
"cn-north-1": "390948362332",
129+
"cn-northwest-1": "387376663083",
130+
"eu-central-1": "664544806723",
131+
"eu-north-1": "669576153137",
132+
"eu-west-1": "438346466558",
133+
"eu-west-2": "644912444149",
134+
"eu-west-3": "749696950732",
135+
"me-south-1": "249704162688",
136+
"sa-east-1": "855470959533",
137+
"us-east-1": "382416733822",
138+
"us-east-2": "404615174143",
139+
"us-gov-west-1": "226302683700",
140+
"us-west-1": "632365934929",
141+
"us-west-2": "174872318107",
142+
}
143+
144+
// https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html
145+
var sageMakerPrebuiltImageIDByRegion_LDA = map[string]string{
146+
"ap-northeast-1": "258307448986",
147+
"ap-northeast-2": "293181348795",
148+
"ap-south-1": "991648021394",
149+
"ap-southeast-1": "475088953585",
150+
"ap-southeast-2": "297031611018",
151+
"ca-central-1": "469771592824",
152+
"eu-central-1": "353608530281",
153+
"eu-west-1": "999678624901",
154+
"eu-west-2": "644912444149",
155+
"us-east-1": "766337827248",
156+
"us-east-2": "999911452149",
157+
"us-gov-west-1": "226302683700",
158+
"us-west-1": "632365934929",
159+
"us-west-2": "266724342769",
160+
}
161+
162+
// https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html
163+
var sageMakerPrebuiltImageIDByRegion_XGBoost = map[string]string{
164+
"ap-east-1": "651117190479",
165+
"ap-northeast-1": "354813040037",
166+
"ap-northeast-2": "366743142698",
167+
"ap-south-1": "720646828776",
168+
"ap-southeast-1": "121021644041",
169+
"ap-southeast-2": "783357654285",
170+
"ca-central-1": "341280168497",
171+
"cn-north-1": "450853457545",
172+
"cn-northwest-1": "451049120500",
173+
"eu-central-1": "492215442770",
174+
"eu-north-1": "662702820516",
175+
"eu-west-1": "141502667606",
176+
"eu-west-2": "764974769150",
177+
"eu-west-3": "659782779980",
178+
"me-south-1": "801668240914",
179+
"sa-east-1": "737474898029",
180+
"us-east-1": "683313688378",
181+
"us-east-2": "257758044811",
182+
"us-gov-west-1": "414596584902",
183+
"us-west-1": "746614075791",
184+
"us-west-2": "246618743249",
185+
}
186+
187+
// https://docs.aws.amazon.com/sagemaker/latest/dg/pre-built-docker-containers-scikit-learn-spark.html
188+
var sageMakerPrebuiltImageIDByRegion_SparkML = map[string]string{
189+
"ap-northeast-1": "354813040037",
190+
"ap-northeast-2": "366743142698",
191+
"ap-south-1": "720646828776",
192+
"ap-southeast-1": "121021644041",
193+
"ap-southeast-2": "783357654285",
194+
"ca-central-1": "341280168497",
195+
"eu-central-1": "492215442770",
196+
"eu-west-1": "141502667606",
197+
"eu-west-2": "764974769150",
198+
"us-east-1": "683313688378",
199+
"us-east-2": "257758044811",
200+
"us-gov-west-1": "414596584902",
201+
"us-west-1": "746614075791",
202+
"us-west-2": "246618743249",
203+
}
204+
205+
// https://github.com/aws/deep-learning-containers/blob/master/available_images.md
206+
var sageMakerPrebuiltImageIDByRegion_DeepLearning = map[string]string{
207+
"ap-east-1": "871362719292",
208+
"ap-northeast-1": "763104351884",
209+
"ap-northeast-2": "763104351884",
210+
"ap-south-1": "763104351884",
211+
"ap-southeast-1": "763104351884",
212+
"ap-southeast-2": "763104351884",
213+
"ca-central-1": "763104351884",
214+
"cn-north-1": "727897471807",
215+
"cn-northwest-1": "727897471807",
216+
"eu-central-1": "763104351884",
217+
"eu-north-1": "763104351884",
218+
"eu-west-1": "763104351884",
219+
"eu-west-2": "763104351884",
220+
"eu-west-3": "763104351884",
221+
"me-south-1": "217643126080",
222+
"sa-east-1": "763104351884",
223+
"us-east-1": "763104351884",
224+
"us-east-2": "763104351884",
225+
"us-west-1": "763104351884",
226+
"us-west-2": "763104351884",
227+
}
228+
229+
func dataSourceAwsSagemakerPrebuiltImagePath() *schema.Resource {
230+
return &schema.Resource{
231+
Read: dataSourceAwsRdsOrderableDbInstanceRead,
232+
Schema: map[string]*schema.Schema{
233+
"repository_name": {
234+
Type: schema.TypeString,
235+
Required: true,
236+
ValidateFunc: validation.StringInSlice([]string{
237+
sageMakerRepositoryBlazingText,
238+
sageMakerRepositoryDeepARForecasting,
239+
sageMakerRepositoryFactorizationMachines,
240+
sageMakerRepositoryImageClassification,
241+
sageMakerRepositoryIPInsights,
242+
sageMakerRepositoryKMeans,
243+
sageMakerRepositoryKNearestNeighbor,
244+
sageMakerRepositoryLDA,
245+
sageMakerRepositoryLinearLearner,
246+
sageMakerRepositoryNeuralTopicModel,
247+
sageMakerRepositoryObject2Vec,
248+
sageMakerRepositoryObjectDetection,
249+
sageMakerRepositoryPCA,
250+
sageMakerRepositoryRandomCutForest,
251+
sageMakerRepositorySemanticSegmentation,
252+
sageMakerRepositorySeq2Seq,
253+
sageMakerRepositoryXGBoost,
254+
sageMakerRepositoryScikitLearn,
255+
sageMakerRepositorySparkML,
256+
sageMakerRepositoryMXNetInference,
257+
sageMakerRepositoryMXNetInferenceEIA,
258+
sageMakerRepositoryMXNetTraining,
259+
sageMakerRepositoryPyTorchInference,
260+
sageMakerRepositoryPyTorchInferenceEIA,
261+
sageMakerRepositoryPyTorchTraining,
262+
sageMakerRepositoryTensorFlowInference,
263+
sageMakerRepositoryTensorFlowInferenceEIA,
264+
sageMakerRepositoryTensorFlowTraining,
265+
}, false),
266+
},
267+
268+
"dns_suffix": {
269+
Type: schema.TypeString,
270+
Optional: true,
271+
},
272+
273+
"image_tag": {
274+
Type: schema.TypeString,
275+
Optional: true,
276+
Default: "1",
277+
},
278+
279+
"region": {
280+
Type: schema.TypeString,
281+
Optional: true,
282+
},
283+
284+
"registry_id": {
285+
Type: schema.TypeString,
286+
Computed: true,
287+
},
288+
289+
"registry_path": {
290+
Type: schema.TypeString,
291+
Computed: true,
292+
},
293+
},
294+
}
295+
}
296+
297+
func dataSourceAwsSagemakerPrebuiltImagePathRead(d *schema.ResourceData, meta interface{}) error {
298+
region := meta.(*AWSClient).region
299+
if v, ok := d.GetOk("region"); ok {
300+
region = v.(string)
301+
}
302+
303+
suffix := meta.(*AWSClient).dnsSuffix
304+
if v, ok := d.GetOk("dns_suffix"); ok {
305+
suffix = v.(string)
306+
}
307+
308+
repo := d.Get("repository_name").(string)
309+
imageTag := d.Get("image_tag").(string)
310+
311+
id := ""
312+
switch repo {
313+
case sageMakerRepositoryBlazingText,
314+
sageMakerRepositoryImageClassification,
315+
sageMakerRepositoryObjectDetection,
316+
sageMakerRepositorySemanticSegmentation,
317+
sageMakerRepositorySeq2Seq:
318+
id = sageMakerPrebuiltImageIDByRegion_Blazing[region]
319+
case sageMakerRepositoryDeepARForecasting:
320+
id = sageMakerPrebuiltImageIDByRegion_DeepAR[region]
321+
case sageMakerRepositoryLDA:
322+
id = sageMakerPrebuiltImageIDByRegion_LDA[region]
323+
case sageMakerRepositoryXGBoost:
324+
id = sageMakerPrebuiltImageIDByRegion_XGBoost[region]
325+
case sageMakerRepositoryScikitLearn, sageMakerRepositorySparkML:
326+
id = sageMakerPrebuiltImageIDByRegion_SparkML[region]
327+
case sageMakerRepositoryMXNetInference,
328+
sageMakerRepositoryMXNetInferenceEIA,
329+
sageMakerRepositoryMXNetTraining,
330+
sageMakerRepositoryPyTorchInference,
331+
sageMakerRepositoryPyTorchInferenceEIA,
332+
sageMakerRepositoryPyTorchTraining,
333+
sageMakerRepositoryTensorFlowInference,
334+
sageMakerRepositoryTensorFlowInferenceEIA,
335+
sageMakerRepositoryTensorFlowTraining:
336+
id = sageMakerPrebuiltImageIDByRegion_DeepLearning[region]
337+
default:
338+
id = sageMakerPrebuiltImageIDByRegion_FactorMachines[region]
339+
}
340+
341+
if id == "" {
342+
return fmt.Errorf("no registry ID available for region (%s) and repository (%s)", region, repo)
343+
}
344+
345+
d.SetId(id)
346+
d.Set("registry_id", id)
347+
d.Set("registry_path", dataSourceAwsSagemakerPrebuiltImageCreatePath(id, region, suffix, repo, imageTag))
348+
return nil
349+
}
350+
351+
func dataSourceAwsSagemakerPrebuiltImageCreatePath(id, region, suffix, repo, imageTag string) string {
352+
return fmt.Sprintf("%s.dkr.ecr.%s.%s/%s:%s", id, region, suffix, repo, imageTag)
353+
}

0 commit comments

Comments
 (0)